Spaces:
Sleeping
Sleeping
Update gemini_agent.py
Browse files- gemini_agent.py +19 -11
gemini_agent.py
CHANGED
|
@@ -62,7 +62,14 @@ class GeminiAgent:
|
|
| 62 |
|
| 63 |
{question}
|
| 64 |
|
| 65 |
-
Provide only the direct answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
try:
|
| 68 |
await self._rate_limit()
|
|
@@ -160,11 +167,11 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
|
|
| 160 |
# Handle attached file questions with enhanced prompts
|
| 161 |
if 'attached' in question.lower():
|
| 162 |
if 'python code' in question.lower():
|
| 163 |
-
prompt = f"""This question
|
| 164 |
-
elif '.mp3' in question.lower():
|
| 165 |
-
prompt = f"""This question refers to an attached audio file.
|
| 166 |
else:
|
| 167 |
-
prompt = f"""This question refers to an attached file. Provide the most
|
| 168 |
# Handle chess position question
|
| 169 |
elif 'chess position' in question.lower() and 'image' in question.lower():
|
| 170 |
prompt = f"""This is a chess question with an attached image. Provide the best chess move in algebraic notation:\n\n{question}\n\nAnswer:"""
|
|
@@ -179,11 +186,12 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
|
|
| 179 |
):
|
| 180 |
# Add domain definition for botanical vegetables
|
| 181 |
if 'vegetable' in question.lower() and ('botany' in question.lower() or 'botanical' in question.lower()):
|
| 182 |
-
definition = ("
|
| 183 |
-
"
|
| 184 |
-
|
|
|
|
| 185 |
else:
|
| 186 |
-
prompt = f"{question}\n\
|
| 187 |
# Create enhanced prompt based on question type
|
| 188 |
elif 'how many' in question.lower() or 'what is the' in question.lower():
|
| 189 |
prompt = f"""Provide only the exact answer to this question. No explanations, just the specific number, name, or fact requested:\n\n{question}\n\nAnswer:"""
|
|
@@ -224,10 +232,10 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
|
|
| 224 |
|
| 225 |
# If the question expects a single value, extract it
|
| 226 |
if any(kw in question.lower() for kw in ["how many", "what is the", "who", "where", "give only", "provide only"]):
|
| 227 |
-
# Extract the first
|
| 228 |
match = re.search(r'^[A-Za-z0-9 ,+-]+', answer)
|
| 229 |
if match:
|
| 230 |
-
answer = match.group(
|
| 231 |
|
| 232 |
return answer
|
| 233 |
|
|
|
|
| 62 |
|
| 63 |
{question}
|
| 64 |
|
| 65 |
+
Provide only the direct answer requested. Be extremely precise:
|
| 66 |
+
- For quotes: give exact words without quotation marks
|
| 67 |
+
- For numbers: give only the number
|
| 68 |
+
- For names: give only the name requested
|
| 69 |
+
- For bird species counts: count all visible species simultaneously on screen
|
| 70 |
+
- For dialogue responses: give the exact spoken words
|
| 71 |
+
|
| 72 |
+
Answer:"""
|
| 73 |
|
| 74 |
try:
|
| 75 |
await self._rate_limit()
|
|
|
|
| 167 |
# Handle attached file questions with enhanced prompts
|
| 168 |
if 'attached' in question.lower():
|
| 169 |
if 'python code' in question.lower():
|
| 170 |
+
prompt = f"""This question asks for the final numeric output from attached Python code. Trace through the code execution step by step and provide only the final number that would be printed or returned:\n\n{question}\n\nFinal numeric output:"""
|
| 171 |
+
elif '.mp3' in question.lower() and ('ingredients' in question.lower() or 'page numbers' in question.lower()):
|
| 172 |
+
prompt = f"""This question refers to an attached audio file. Based on the context provided, extract the requested information and format it exactly as specified:\n\n{question}\n\nAnswer (formatted as requested):"""
|
| 173 |
else:
|
| 174 |
+
prompt = f"""This question refers to an attached file. Provide the most accurate answer based on the context:\n\n{question}\n\nAnswer:"""
|
| 175 |
# Handle chess position question
|
| 176 |
elif 'chess position' in question.lower() and 'image' in question.lower():
|
| 177 |
prompt = f"""This is a chess question with an attached image. Provide the best chess move in algebraic notation:\n\n{question}\n\nAnswer:"""
|
|
|
|
| 186 |
):
|
| 187 |
# Add domain definition for botanical vegetables
|
| 188 |
if 'vegetable' in question.lower() and ('botany' in question.lower() or 'botanical' in question.lower()):
|
| 189 |
+
definition = ("IMPORTANT: Use strict botanical definitions. A vegetable is any edible plant part that is NOT a botanical fruit. "
|
| 190 |
+
"Botanical fruits develop from flowers and contain seeds (tomatoes, peppers, beans, corn, peas, zucchini, etc. are fruits). "
|
| 191 |
+
"True vegetables include roots, stems, leaves, and other plant parts.")
|
| 192 |
+
prompt = f"{definition}\n\n{question}\n\nProvide ONLY the botanical vegetables from the list, alphabetized, comma separated. No fruits, no explanations."
|
| 193 |
else:
|
| 194 |
+
prompt = f"{question}\n\nProvide exactly what is requested: alphabetized, comma separated list with no extra text or explanations."
|
| 195 |
# Create enhanced prompt based on question type
|
| 196 |
elif 'how many' in question.lower() or 'what is the' in question.lower():
|
| 197 |
prompt = f"""Provide only the exact answer to this question. No explanations, just the specific number, name, or fact requested:\n\n{question}\n\nAnswer:"""
|
|
|
|
| 232 |
|
| 233 |
# If the question expects a single value, extract it
|
| 234 |
if any(kw in question.lower() for kw in ["how many", "what is the", "who", "where", "give only", "provide only"]):
|
| 235 |
+
# Extract the first meaningful part of the answer
|
| 236 |
match = re.search(r'^[A-Za-z0-9 ,+-]+', answer)
|
| 237 |
if match:
|
| 238 |
+
answer = match.group().strip()
|
| 239 |
|
| 240 |
return answer
|
| 241 |
|