Commit ca9b223c authored by nextime's avatar nextime

Add response ID tracking to debug logs

- Log which response ID was matched for each reply
- Track exact matches vs fallback responses
- Include response ID in prompts.log for correlation
- Enhanced debugging visibility for response detection
- Console logging for JavaScript fallback cases
parent 2a54a34e
...@@ -774,6 +774,14 @@ def decode_chatbot_response(response_text, chatbot_name, request_id): ...@@ -774,6 +774,14 @@ def decode_chatbot_response(response_text, chatbot_name, request_id):
extracted_content = match.group(1).strip() extracted_content = match.group(1).strip()
logging.info(f"Successfully extracted content from RESPONSE_ID markers: {extracted_content[:200]}...") logging.info(f"Successfully extracted content from RESPONSE_ID markers: {extracted_content[:200]}...")
# Log the response ID that was matched
if DEBUG_ENABLED:
try:
with open(PROMPTS_LOG_PATH, 'a', encoding='utf-8') as f:
f.write(f"[{datetime.datetime.now().isoformat()}] RESPONSE_ID_MATCHED: {request_id} (exact match)\n")
except Exception as e:
logging.error(f"Failed to log response ID match: {e}")
# Save HTML page content if debug is enabled # Save HTML page content if debug is enabled
if DEBUG_ENABLED: if DEBUG_ENABLED:
try: try:
...@@ -805,6 +813,15 @@ def decode_chatbot_response(response_text, chatbot_name, request_id): ...@@ -805,6 +813,15 @@ def decode_chatbot_response(response_text, chatbot_name, request_id):
# Use the last non-setup response (most recent) # Use the last non-setup response (most recent)
block_id, extracted_content = filtered_blocks[-1] block_id, extracted_content = filtered_blocks[-1]
logging.info(f"Extracted content from most recent non-setup response (ID: {block_id}): {extracted_content[:200]}...") logging.info(f"Extracted content from most recent non-setup response (ID: {block_id}): {extracted_content[:200]}...")
# Log the fallback response ID that was used
if DEBUG_ENABLED:
try:
with open(PROMPTS_LOG_PATH, 'a', encoding='utf-8') as f:
f.write(f"[{datetime.datetime.now().isoformat()}] RESPONSE_ID_MATCHED: {block_id} (fallback - most recent non-setup)\n")
except Exception as e:
logging.error(f"Failed to log fallback response ID: {e}")
return extracted_content return extracted_content
# Final fallback: return the original text # Final fallback: return the original text
...@@ -1376,6 +1393,11 @@ async def detect_progressive_response(page, container_selector, prompt, modified ...@@ -1376,6 +1393,11 @@ async def detect_progressive_response(page, container_selector, prompt, modified
const content = lastBlock.text.substring(startContentIndex + 7, endContentIndex).trim(); const content = lastBlock.text.substring(startContentIndex + 7, endContentIndex).trim();
if (content && content.length > 10) { if (content && content.length > 10) {
console.log('Using final fallback response'); console.log('Using final fallback response');
// Extract the ID from the last block for logging
const idMatch = lastBlock.text.match(/RESPONSE_ID_([^_]+)_START:/);
if (idMatch) {
console.log(`Final fallback response ID: ${idMatch[1]}`);
}
return content; return content;
} }
} }
......
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