Commit 2cf42f1e authored by nextime's avatar nextime

Improve prompt to ensure complete response capture in base64 encoding

- Add explicit step-by-step instructions for chatbot to follow
- Emphasize waiting for COMPLETE response before JSON formatting
- Use numbered list format for clarity and better compliance
- Add example JSON format to reduce ambiguity
- Separate user question clearly from formatting instructions
- Address issue where chatbot was truncating responses before base64 encoding

This should resolve the problem where the chatbot wasn't including
the whole reply correctly in the base64 encoded response key.
parent 0e320d63
...@@ -371,7 +371,29 @@ async def forward_to_chatbot(chatbot_name, config, prompt): ...@@ -371,7 +371,29 @@ async def forward_to_chatbot(chatbot_name, config, prompt):
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
json_instruction = f'Format the response of this prompt as a raw JSON object with a "response" key containing the answer encoded in base64 format, and a second "id" key containing the unique id "{request_id}". The response should contain the complete answer exactly as it would appear unfiltered from an API, including all content (code, explanations, instructions, formatting, XML, markup language, etc.). Encode the entire response content in base64 before placing it in the "response" key. Nothing should be outside of the JSON object. Wait to have the whole reply before to write the json, and be sure to encode in base64 the whole "response" key. Any other formatting instruction is to be considered for the content to insert in the response key, before base64 encoding. \n\n' json_instruction = f'''CRITICAL INSTRUCTIONS - READ CAREFULLY:
1. You MUST complete your ENTIRE response to the user's question first
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:
- Your complete answer must be encoded in base64 and placed in the "response" key
- 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:
{{"response": "BASE64_ENCODED_COMPLETE_ANSWER_HERE", "id": "{request_id}"}}
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.
USER'S ACTUAL QUESTION:
'''
modified_prompt = f"{json_instruction}\n\n{prompt}" modified_prompt = f"{json_instruction}\n\n{prompt}"
logging.info(f"Request ID: {request_id}, Modified prompt: {modified_prompt}") logging.info(f"Request ID: {request_id}, Modified prompt: {modified_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