Peterase commited on
Commit
87a832d
Β·
1 Parent(s): 0b5eb95

fix: structured output prompt with example + DDG timeout 4s

Browse files

rag_chat_use_case.py:
- Add concrete EXAMPLE block to both prompts so LLM sees exactly what format to produce
- Shorter, cleaner rules section
- Both execute_chat and execute_stream use identical prompt

.env:
- LIVE_SEARCH_TIMEOUT: 2.0 β†’ 4.0s (HF Space has slower network than local)
DDG was timing out at 1.5s causing 0 live results

Files changed (2) hide show
  1. .env +1 -1
  2. src/core/use_cases/rag_chat_use_case.py +58 -38
.env CHANGED
@@ -79,7 +79,7 @@ ACCESS_TOKEN_EXPIRE_MINUTES=60
79
 
80
  # --- Hybrid Search Settings ---
81
  ENABLE_HYBRID_SEARCH=true
82
- LIVE_SEARCH_TIMEOUT=2.0
83
  LIVE_SEARCH_MAX_RESULTS=5
84
  LIVE_SEARCH_WEIGHT=0.5
85
  DB_SEARCH_WEIGHT=0.5
 
79
 
80
  # --- Hybrid Search Settings ---
81
  ENABLE_HYBRID_SEARCH=true
82
+ LIVE_SEARCH_TIMEOUT=4.0
83
  LIVE_SEARCH_MAX_RESULTS=5
84
  LIVE_SEARCH_WEIGHT=0.5
85
  DB_SEARCH_WEIGHT=0.5
src/core/use_cases/rag_chat_use_case.py CHANGED
@@ -865,34 +865,44 @@ JSON:"""
865
 
866
  prompt = f"""You are ARKI AI, a real-time Ethiopia & Africa news assistant. Today: {datetime.utcnow().strftime("%B %d, %Y")}.
867
 
868
- SOURCE INDEX (cite by number β€” these are the ONLY sources you may use):
869
  {source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
870
 
871
- STRICT RULES:
872
- - Use ONLY facts from the News Context below. NEVER use training data.
873
- - Cite every fact: [1], [2], etc. Only use numbers that exist in the Source Index above.
874
- - Non-English articles: translate to English in your answer.
875
- - Always respond in English.
 
876
 
877
- OUTPUT FORMAT β€” use this exact structure:
878
 
879
- ## [Short headline summarizing the main news]
880
 
881
- **[Topic 1]**
882
- - Key fact from source [N]
883
- - Key fact from source [N]
884
 
885
- **[Topic 2]** (if applicable)
886
- - Key fact from source [N]
887
 
888
- > πŸ’‘ *[One sentence summary of the overall situation]*
889
 
890
- FOLLOW_UP: question1 | question2 | question3
 
 
891
 
892
- EVALUATION GUIDE:
893
- - If sources directly answer the question β†’ use the format above
894
- - If sources are related but not exact β†’ start with "I found related news:" then use the format
895
- - If no relevant sources β†’ say "I couldn't find relevant news on that topic in today's feed." and STOP
 
 
 
 
 
 
 
896
 
897
  News Context:
898
  {context_text if context_text else "NO CONTEXT RETRIEVED."}
@@ -992,34 +1002,44 @@ Answer:"""
992
 
993
  prompt_stream = f"""You are ARKI AI, a real-time Ethiopia & Africa news assistant. Today: {datetime.utcnow().strftime("%B %d, %Y")}.
994
 
995
- SOURCE INDEX (cite by number β€” these are the ONLY sources you may use):
996
  {source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
997
 
998
- STRICT RULES:
999
- - Use ONLY facts from the News Context below. NEVER use training data.
1000
- - Cite every fact: [1], [2], etc. Only use numbers that exist in the Source Index above.
1001
- - Non-English articles: translate to English in your answer.
1002
- - Always respond in English.
 
 
 
 
 
 
 
 
 
1003
 
1004
- OUTPUT FORMAT β€” use this exact structure:
 
1005
 
1006
- ## [Short headline summarizing the main news]
1007
 
1008
- **[Topic 1]**
1009
- - Key fact from source [N]
1010
- - Key fact from source [N]
1011
 
1012
- **[Topic 2]** (if applicable)
1013
- - Key fact from source [N]
 
1014
 
1015
- > πŸ’‘ *[One sentence summary of the overall situation]*
 
1016
 
1017
- FOLLOW_UP: question1 | question2 | question3
 
1018
 
1019
- EVALUATION GUIDE:
1020
- - If sources directly answer the question β†’ use the format above
1021
- - If sources are related but not exact β†’ start with "I found related news:" then use the format
1022
- - If no relevant sources β†’ say "I couldn't find relevant news on that topic in today's feed." and STOP
1023
 
1024
  News Context:
1025
  {context_text if context_text else "NO CONTEXT RETRIEVED."}
 
865
 
866
  prompt = f"""You are ARKI AI, a real-time Ethiopia & Africa news assistant. Today: {datetime.utcnow().strftime("%B %d, %Y")}.
867
 
868
+ SOURCE INDEX (the ONLY sources you may cite):
869
  {source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
870
 
871
+ RULES:
872
+ 1. Use ONLY facts from the News Context. Never use training data.
873
+ 2. Cite every fact inline: [1], [2], etc.
874
+ 3. Translate non-English articles to English.
875
+ 4. Respond in English only.
876
+ 5. End with: FOLLOW_UP: q1 | q2 | q3
877
 
878
+ REQUIRED OUTPUT FORMAT (follow exactly):
879
 
880
+ ## [One-line headline]
881
 
882
+ **[Category name]**
883
+ - [Fact]. [1]
884
+ - [Fact]. [2]
885
 
886
+ **[Another category]** *(if applicable)*
887
+ - [Fact]. [N]
888
 
889
+ > πŸ’‘ [One sentence overall summary]
890
 
891
+ EXAMPLE of correct format:
892
+ ---
893
+ ## Ethiopia: Conflict & Economy Updates
894
 
895
+ **Ethiopia-Sudan Tensions**
896
+ - Sudan recalled its ambassador after accusing Ethiopia of drone strikes on Khartoum airport. [2]
897
+ - Ethiopia rejected the accusations as "baseless" and blamed external parties. [3]
898
+
899
+ **Economic Developments**
900
+ - Ethiopia's GERD dam was inaugurated, doubling the country's electricity capacity. [1]
901
+
902
+ > πŸ’‘ Ethiopia faces simultaneous diplomatic pressure from Sudan and internal political tensions.
903
+ ---
904
+
905
+ If no relevant sources: write "I couldn't find relevant news on that topic in today's feed." and stop.
906
 
907
  News Context:
908
  {context_text if context_text else "NO CONTEXT RETRIEVED."}
 
1002
 
1003
  prompt_stream = f"""You are ARKI AI, a real-time Ethiopia & Africa news assistant. Today: {datetime.utcnow().strftime("%B %d, %Y")}.
1004
 
1005
+ SOURCE INDEX (the ONLY sources you may cite):
1006
  {source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
1007
 
1008
+ RULES:
1009
+ 1. Use ONLY facts from the News Context. Never use training data.
1010
+ 2. Cite every fact inline: [1], [2], etc.
1011
+ 3. Translate non-English articles to English.
1012
+ 4. Respond in English only.
1013
+ 5. End with: FOLLOW_UP: q1 | q2 | q3
1014
+
1015
+ REQUIRED OUTPUT FORMAT (follow exactly):
1016
+
1017
+ ## [One-line headline]
1018
+
1019
+ **[Category name]**
1020
+ - [Fact]. [1]
1021
+ - [Fact]. [2]
1022
 
1023
+ **[Another category]** *(if applicable)*
1024
+ - [Fact]. [N]
1025
 
1026
+ > πŸ’‘ [One sentence overall summary]
1027
 
1028
+ EXAMPLE of correct format:
1029
+ ---
1030
+ ## Ethiopia: Conflict & Economy Updates
1031
 
1032
+ **Ethiopia-Sudan Tensions**
1033
+ - Sudan recalled its ambassador after accusing Ethiopia of drone strikes on Khartoum airport. [2]
1034
+ - Ethiopia rejected the accusations as "baseless" and blamed external parties. [3]
1035
 
1036
+ **Economic Developments**
1037
+ - Ethiopia's GERD dam was inaugurated, doubling the country's electricity capacity. [1]
1038
 
1039
+ > πŸ’‘ Ethiopia faces simultaneous diplomatic pressure from Sudan and internal political tensions.
1040
+ ---
1041
 
1042
+ If no relevant sources: write "I couldn't find relevant news on that topic in today's feed." and stop.
 
 
 
1043
 
1044
  News Context:
1045
  {context_text if context_text else "NO CONTEXT RETRIEVED."}