lethaq commited on
Commit
35961c7
·
verified ·
1 Parent(s): 888f832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
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
- """Create a prompt for the model with optional search results - Simplified Version"""
146
- prompt_parts = []
147
-
148
- if search_results:
149
- prompt_parts.append(self.format_search_results(search_results))
150
- prompt_parts.append(
151
- "Instruction: Use the Search Results provided above to answer the Question. "
152
- "Focus on extracting the specific fact, number, or list requested. "
153
- "If the search results are clearly irrelevant or do not contain the answer, then try to use your general knowledge.\n\n"
154
- )
155
- else:
156
- prompt_parts.append("Instruction: No search results were provided. Answer the Question using your general knowledge.\n\n")
157
-
158
- prompt_parts.append(f"Question: {question}\n")
159
- prompt_parts.append(
160
- "\nAnswer Guidelines (Strictly Follow):\n"
161
- "1. Your answer MUST be ONLY the specific fact, number(s), or comma-separated list requested by the question. NO extra words, explanations, or conversational filler like 'The answer is...'.\n"
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
- prompt_parts.append("\nAnswer: ")
169
-
170
- return "".join(prompt_parts)
 
 
 
 
 
 
 
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
  """