Spaces:
Sleeping
Sleeping
related check
Browse files- gemini_agent.py +7 -3
gemini_agent.py
CHANGED
|
@@ -214,10 +214,14 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
|
|
| 214 |
else:
|
| 215 |
prompt = f"""Answer this question with only the essential information requested:\n\n{question}\n\nAnswer:"""
|
| 216 |
|
| 217 |
-
# Prepend context to the prompt if available
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
prompt = f"Use the following Wikipedia context to answer the question:\n{wiki_context}\n\n{prompt}"
|
| 220 |
-
elif ddg_context:
|
| 221 |
prompt = f"Use the following web search context to answer the question:\n{ddg_context}\n\n{prompt}"
|
| 222 |
|
| 223 |
# Use the constructed prompt for all cases
|
|
|
|
| 214 |
else:
|
| 215 |
prompt = f"""Answer this question with only the essential information requested:\n\n{question}\n\nAnswer:"""
|
| 216 |
|
| 217 |
+
# Prepend context to the prompt if available and likely relevant
|
| 218 |
+
def is_relevant_context(context, question):
|
| 219 |
+
# Only use context if it contains a main keyword from the question and is not a generic error
|
| 220 |
+
keywords = [w.lower().strip(',.?') for w in question.split() if len(w) > 3]
|
| 221 |
+
return context and not any(x in context.lower() for x in ["not found", "no results", "does not contain information"]) and any(kw in context.lower() for kw in keywords)
|
| 222 |
+
if wiki_context and is_relevant_context(wiki_context, question):
|
| 223 |
prompt = f"Use the following Wikipedia context to answer the question:\n{wiki_context}\n\n{prompt}"
|
| 224 |
+
elif ddg_context and is_relevant_context(ddg_context, question):
|
| 225 |
prompt = f"Use the following web search context to answer the question:\n{ddg_context}\n\n{prompt}"
|
| 226 |
|
| 227 |
# Use the constructed prompt for all cases
|