Commit 51c28026 authored by nextime's avatar nextime

Optimize prompt to prevent chatbot explanations and reduce encoding time

- Redesigned prompt to be more direct and system-like
- Added explicit instructions to NOT explain the encoding process
- Removed verbose explanations that were causing chatbots to add commentary
- Streamlined format requirements to prevent 'I'll encode this in JSON' responses
- Made instructions more concise and command-like for faster processing
- Maintained all functionality while reducing response time
parent 10316371
...@@ -370,29 +370,30 @@ async def forward_to_chatbot(chatbot_name, config, prompt): ...@@ -370,29 +370,30 @@ async def forward_to_chatbot(chatbot_name, config, prompt):
# Generate unique ID for this request using UUID for better uniqueness # Generate unique ID for this request using UUID for better uniqueness
request_id = str(uuid.uuid4()).replace('-', '')[:16] # 16-character unique ID request_id = str(uuid.uuid4()).replace('-', '')[:16] # 16-character unique ID
# Create JSON-based prompt with unique ID and base64 encoding # Create JSON-based prompt with unique ID and base64 encoding - optimized to prevent explanations
json_instruction = f'''CRITICAL INSTRUCTIONS - READ CAREFULLY: json_instruction = f'''SYSTEM INSTRUCTION - FOLLOW EXACTLY:
1. You MUST complete your ENTIRE response to the user's question first You must respond ONLY with a JSON object. Do NOT write any explanation, introduction, or commentary.
2. Only AFTER you have finished writing your complete answer, format it as JSON
3. The JSON must contain exactly two keys: "response" and "id"
4. The "response" key must contain your COMPLETE answer encoded in base64
5. The "id" key must contain exactly this value: "{request_id}"
RESPONSE FORMAT REQUIREMENTS: REQUIRED FORMAT (copy this structure exactly):
- Your complete answer must be encoded in base64 and placed in the "response" key {{"response": "BASE64_ENCODED_ANSWER", "id": "{request_id}"}}
- Include ALL content: explanations, code, examples, formatting, everything
- Do NOT truncate, summarize, or omit any part of your response
- Wait until your response is 100% complete before creating the JSON
- The JSON must be valid and parseable
- Nothing should appear outside the JSON object
EXAMPLE FORMAT: PROCESS:
{{"response": "BASE64_ENCODED_COMPLETE_ANSWER_HERE", "id": "{request_id}"}} 1. Generate your complete answer to the user's question
2. Encode that answer in base64
3. Place the base64 string in the "response" field
4. Use the exact ID: {request_id}
5. Output ONLY the JSON - no other text
IMPORTANT: Do not start formatting as JSON until you have completely finished answering the user's question. Your complete response must be base64 encoded in the "response" field. DO NOT:
- Write "I'll encode this in JSON" or similar explanations
- Add any text before or after the JSON
- Explain the encoding process
- Use markdown formatting around the JSON
USER'S ACTUAL QUESTION: RESPOND ONLY WITH THE JSON OBJECT.
USER QUESTION:
''' '''
modified_prompt = f"{json_instruction}\n\n{prompt}" modified_prompt = f"{json_instruction}\n\n{prompt}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment