Kackle commited on
Commit
04afd3e
·
verified ·
1 Parent(s): e2d15d4

Update gemini_agent.py

Browse files
Files changed (1) hide show
  1. gemini_agent.py +12 -2
gemini_agent.py CHANGED
@@ -183,11 +183,18 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
183
  if is_explicit_retrieval_question(question):
184
  try:
185
  wiki_context = self.wiki_tool.run(question)
 
186
  except Exception as e:
187
  print(f"Wikipedia tool failed: {e}")
188
- if "duckduckgo" in question.lower() or "web search" in question.lower():
 
 
 
 
 
189
  try:
190
  ddg_context = self.ddg_tool.run(question)
 
191
  except Exception as e:
192
  print(f"DuckDuckGo tool failed: {e}")
193
  # Handle attached file questions with enhanced prompts
@@ -231,7 +238,10 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
231
  def is_good_context(context):
232
  return context and not any(x in context.lower() for x in ["not found", "no results", "does not contain information"])
233
  if wiki_context and is_good_context(wiki_context):
234
- prompt = f"Use the following Wikipedia context to answer the question:\n{wiki_context}\n\n{prompt}"
 
 
 
235
  elif ddg_context and is_good_context(ddg_context):
236
  prompt = f"Use the following web search context to answer the question:\n{ddg_context}\n\n{prompt}"
237
 
 
183
  if is_explicit_retrieval_question(question):
184
  try:
185
  wiki_context = self.wiki_tool.run(question)
186
+ print(f"Wiki context: {wiki_context[:200]}...") # Debug
187
  except Exception as e:
188
  print(f"Wikipedia tool failed: {e}")
189
+
190
+ # Use DuckDuckGo as fallback if Wikipedia context is poor or for web search requests
191
+ def is_poor_context(context):
192
+ return not context or any(x in context.lower() for x in ["not found", "no results", "does not contain", "disambiguation"])
193
+
194
+ if "duckduckgo" in question.lower() or "web search" in question.lower() or is_poor_context(wiki_context):
195
  try:
196
  ddg_context = self.ddg_tool.run(question)
197
+ print(f"DDG context: {ddg_context[:200]}...") # Debug
198
  except Exception as e:
199
  print(f"DuckDuckGo tool failed: {e}")
200
  # Handle attached file questions with enhanced prompts
 
238
  def is_good_context(context):
239
  return context and not any(x in context.lower() for x in ["not found", "no results", "does not contain information"])
240
  if wiki_context and is_good_context(wiki_context):
241
+ if "first name" in question.lower():
242
+ prompt = f"Based on this Wikipedia information, find the actor who played Ray/Roman and identify what character they played in Magda M., then give only their first name:\n{wiki_context}\n\n{question}\n\nAnswer:"
243
+ else:
244
+ prompt = f"Use the following Wikipedia context to answer the question:\n{wiki_context}\n\n{prompt}"
245
  elif ddg_context and is_good_context(ddg_context):
246
  prompt = f"Use the following web search context to answer the question:\n{ddg_context}\n\n{prompt}"
247