Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,32 +142,34 @@ class CodeAgent:
|
|
| 142 |
)
|
| 143 |
|
| 144 |
def create_prompt(self, question: str, search_results: Optional[List[Dict[str, str]]] = None) -> str:
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
"
|
| 161 |
-
"
|
| 162 |
-
"2. Example - Question: 'What is the capital of France?' Expected Answer: Paris\n"
|
| 163 |
-
"3. Example - Question: 'How many days are there in a standard week?' Expected Answer: 7\n"
|
| 164 |
-
"4. Example - Question: 'List the first three positive even numbers.' Expected Answer: 2, 4, 6\n"
|
| 165 |
-
"5. If, after carefully checking the search results (if any were provided) and your own knowledge, you absolutely cannot determine a factual answer, or if the question is impossible for you to answer (e.g. requires seeing an image), then respond with the single word: Unknown\n"
|
| 166 |
-
" Do not guess. 'Unknown' is only for when you are certain you don't know.\n"
|
| 167 |
)
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
def __call__(self, question: str) -> str:
|
| 173 |
"""
|
|
|
|
| 142 |
)
|
| 143 |
|
| 144 |
def create_prompt(self, question: str, search_results: Optional[List[Dict[str, str]]] = None) -> str:
|
| 145 |
+
prompt = []
|
| 146 |
+
|
| 147 |
+
if search_results:
|
| 148 |
+
prompt.append("Search Results:\n")
|
| 149 |
+
for i, sr in enumerate(search_results, 1):
|
| 150 |
+
snippet = sr.get("snippet", "")
|
| 151 |
+
title = sr.get("title", "")
|
| 152 |
+
prompt.append(f"[{i}] Title: {title}\nSnippet: {snippet}\n")
|
| 153 |
+
prompt.append("\n")
|
| 154 |
+
|
| 155 |
+
prompt.append(
|
| 156 |
+
"Instructions:\n"
|
| 157 |
+
"- ONLY answer with the exact fact, number, name, or list from above search results. NO explanations, NO restating question.\n"
|
| 158 |
+
"- If several possible answers, pick the most obvious or first. Use comma for lists.\n"
|
| 159 |
+
"- Only use 'Unknown' if absolutely impossible to answer from the search results or common knowledge.\n"
|
| 160 |
+
"- If the answer needs audio/image/code execution, reply: Unknown.\n"
|
| 161 |
+
"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
)
|
| 163 |
+
else:
|
| 164 |
+
prompt.append(
|
| 165 |
+
"No search results. Use your knowledge. If impossible, reply: Unknown\n"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
prompt.append(f"Question: {question}\n")
|
| 169 |
+
prompt.append("Answer: ")
|
| 170 |
+
return "".join(prompt)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
|
| 174 |
def __call__(self, question: str) -> str:
|
| 175 |
"""
|