Spaces:
Running
Running
fix: structured output prompt with example + DDG timeout 4s
Browse filesrag_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
- .env +1 -1
- 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=
|
| 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 (
|
| 869 |
{source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
|
| 870 |
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
|
|
|
| 876 |
|
| 877 |
-
OUTPUT FORMAT
|
| 878 |
|
| 879 |
-
## [
|
| 880 |
|
| 881 |
-
**[
|
| 882 |
-
-
|
| 883 |
-
-
|
| 884 |
|
| 885 |
-
**[
|
| 886 |
-
-
|
| 887 |
|
| 888 |
-
> π‘
|
| 889 |
|
| 890 |
-
|
|
|
|
|
|
|
| 891 |
|
| 892 |
-
|
| 893 |
-
-
|
| 894 |
-
-
|
| 895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 (
|
| 996 |
{source_index_lines if source_index_lines else "NO SOURCES RETRIEVED."}
|
| 997 |
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1003 |
|
| 1004 |
-
|
|
|
|
| 1005 |
|
| 1006 |
-
|
| 1007 |
|
| 1008 |
-
|
| 1009 |
-
-
|
| 1010 |
-
|
| 1011 |
|
| 1012 |
-
**
|
| 1013 |
-
-
|
|
|
|
| 1014 |
|
| 1015 |
-
|
|
|
|
| 1016 |
|
| 1017 |
-
|
|
|
|
| 1018 |
|
| 1019 |
-
|
| 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."}
|