Skip to content

Commit 3849f9f

Browse files
committed
fix: Force StillMe to report RSS feed errors honestly and directly - Fixed failed_feeds_info extraction with isinstance check - Enhanced RSS feed errors reporting with stronger instructions - Added direct answer requirement for RSS feed errors questions - Added logging for RSS feed errors detection - Strengthened prompt instructions with multiple CRITICAL warnings
1 parent 52182b2 commit 3849f9f

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

backend/api/routers/chat_router.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,25 +2292,55 @@ def truncate_text(text: str, max_tokens: int) -> str:
22922292
failed_feeds_info = rss_info.get("failed_feeds")
22932293
feeds_count = rss_info.get("feeds_count", 0)
22942294
failed_feeds_text = ""
2295-
if failed_feeds_info:
2295+
2296+
# CRITICAL: Always check for failed feeds and report them honestly
2297+
# Check if failed_feeds_info is a dict (not None, not empty list)
2298+
if failed_feeds_info and isinstance(failed_feeds_info, dict):
22962299
failed_count = failed_feeds_info.get("failed_count", 0)
22972300
successful_count = failed_feeds_info.get("successful_count", 0)
22982301
total_count = failed_feeds_info.get("total_count", feeds_count) # Use feeds_count as fallback
22992302
failure_rate = failed_feeds_info.get("failure_rate", 0)
23002303
last_error = failed_feeds_info.get("last_error")
23012304

2305+
# CRITICAL: If there are ANY failed feeds, we MUST report them
23022306
if failed_count > 0:
2307+
logger.info(f"⚠️ RSS feed errors detected: {failed_count}/{total_count} feeds failed ({failure_rate}%)")
2308+
failed_feeds_text = f"""
2309+
2310+
**🚨🚨🚨 RSS FEEDS STATUS - CRITICAL INFORMATION (MUST REPORT IN YOUR ANSWER) 🚨🚨🚨**
2311+
2312+
**YOU MUST ANSWER THE USER'S QUESTION ABOUT RSS FEED ERRORS DIRECTLY AND HONESTLY:**
2313+
2314+
- **Total RSS Feeds**: {total_count} feeds configured
2315+
- **Failed Feeds**: {failed_count}/{total_count} feeds are currently experiencing connection issues ({failure_rate}% failure rate)
2316+
- **Successful Feeds**: {successful_count}/{total_count} feeds are working normally
2317+
- **Last Error**: {last_error[:200] if last_error else 'Unknown error'}
2318+
2319+
**CRITICAL INSTRUCTIONS - YOU MUST FOLLOW THESE EXACTLY:**
2320+
2321+
1. **DO NOT say "không có thông tin cụ thể về bất kỳ nguồn học nào bị lỗi"** - This is FALSE. There ARE {failed_count} RSS feeds that are failing.
2322+
2323+
2. **DO NOT say "all sources are working fine" or "all feeds are active"** - This is FALSE. {failed_count} feeds have failed.
2324+
2325+
3. **YOU MUST say EXACTLY**: "StillMe hiện đang học từ {len(enabled_sources)} nguồn. Đối với RSS feeds cụ thể: có tổng cộng {total_count} RSS feeds, trong đó {failed_count} feeds đang gặp sự cố kết nối (tỷ lệ lỗi: {failure_rate}%), {successful_count} feeds đang hoạt động bình thường."
2326+
2327+
4. **BE DIRECT AND HONEST**: When the user asks "có nguồn nào bị lỗi ko?", you MUST answer "Có, có {failed_count} RSS feeds đang gặp sự cố kết nối."
2328+
2329+
5. **DO NOT be vague or evasive**: Be specific about the numbers and the status.
2330+
2331+
**THIS IS A TEST OF YOUR TRANSPARENCY AND HONESTY - YOU MUST PASS THIS TEST.**
2332+
"""
2333+
else:
2334+
# No failed feeds, but still mention RSS status
23032335
failed_feeds_text = f"""
2304-
**⚠️ RSS FEEDS STATUS (CRITICAL - MUST REPORT EXACT NUMBERS):**
2336+
**📊 RSS FEEDS STATUS:**
23052337
- **Total RSS Feeds**: {total_count} feeds configured
2306-
- **Failed Feeds**: {failed_count}/{total_count} feeds are currently failing ({failure_rate}% failure rate)
2307-
- **Successful Feeds**: {successful_count}/{total_count} feeds are working
2308-
- **Last Error**: {last_error[:150] if last_error else 'Unknown error'}
2309-
- **CRITICAL**: You MUST mention the EXACT numbers: "{total_count} RSS feeds total, {failed_count} feeds are experiencing connection issues, {successful_count} feeds are working". Do NOT say "all sources are working fine" or "all feeds are active" when {failed_count} feeds have failed.
2310-
- **You MUST be honest and specific**: Say something like "StillMe is currently learning from {len(enabled_sources)} sources. For RSS feeds specifically: {total_count} feeds total, {failed_count} feeds are experiencing connection issues (failure rate: {failure_rate}%), {successful_count} feeds are working normally."
2338+
- **Status**: All feeds are working normally
23112339
"""
23122340
elif feeds_count > 0:
23132341
# If no failed_feeds_info but we have feeds_count, still mention it
2342+
# But we should try to get RSS stats from system_monitor as fallback
2343+
logger.warning(f"⚠️ No failed_feeds_info in API response, but feeds_count={feeds_count}. Attempting to get RSS stats from system_monitor.")
23142344
failed_feeds_text = f"""
23152345
**📊 RSS FEEDS STATUS:**
23162346
- **Total RSS Feeds**: {feeds_count} feeds configured
@@ -2343,10 +2373,11 @@ def truncate_text(text: str, max_tokens: int) -> str:
23432373
{failed_feeds_text}
23442374
23452375
**MANDATORY RESPONSE REQUIREMENTS:**
2346-
1. **List ALL current sources** - **CRITICAL**: You MUST list ALL {len(enabled_sources)} enabled sources from the API data above. Do NOT just say "RSS, arXiv, Wikipedia" - you MUST list ALL sources: {', '.join([name.upper() for name in enabled_sources]) if enabled_sources else 'ALL SOURCES FROM API DATA ABOVE'}
2376+
1. **Answer RSS feed errors question DIRECTLY** - **CRITICAL**: If the user asks "có nguồn nào bị lỗi ko?" or "are there any sources with errors?", you MUST check the RSS FEEDS STATUS section above and answer HONESTLY. If there are failed feeds, you MUST mention the exact numbers. DO NOT say "không có thông tin cụ thể" when the information IS available above.
2377+
2. **List ALL current sources** - **CRITICAL**: You MUST list ALL {len(enabled_sources)} enabled sources from the API data above. Do NOT just say "RSS, arXiv, Wikipedia" - you MUST list ALL sources: {', '.join([name.upper() for name in enabled_sources]) if enabled_sources else 'ALL SOURCES FROM API DATA ABOVE'}
23472378
- **You MUST mention each source by name**: {', '.join([name.upper() for name in enabled_sources]) if enabled_sources else 'ALL SOURCES'}
23482379
- **For each source, describe what StillMe learns from it**
2349-
2. **Be specific about topics** - For each source, mention what topics/chủ đề StillMe learns from that source
2380+
3. **Be specific about topics** - For each source, mention what topics/chủ đề StillMe learns from that source
23502381
3. **When proposing new sources** - You MUST:
23512382
- First acknowledge what StillMe ALREADY has (from the list above)
23522383
- Only propose sources that are NOT already enabled

0 commit comments

Comments
 (0)