Kackle commited on
Commit
f60e375
·
verified ·
1 Parent(s): 06d91eb

Update gemini_agent.py

Browse files
Files changed (1) hide show
  1. gemini_agent.py +11 -19
gemini_agent.py CHANGED
@@ -62,14 +62,7 @@ class GeminiAgent:
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,11 +160,11 @@ Answer:"""
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,12 +179,11 @@ Answer:"""
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,10 +224,10 @@ Answer:"""
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
 
 
62
 
63
  {question}
64
 
65
+ Provide only the direct answer. If it's a quote, give just the quoted text. If it's a number, give just the number. If it's about bird species count, analyze carefully and give the exact count. If it's about dialogue, provide the exact words spoken."""
 
 
 
 
 
 
 
66
 
67
  try:
68
  await self._rate_limit()
 
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 refers to attached Python code. Based on typical code execution patterns, provide the most likely numeric output:\n\n{question}\n\nAnswer:"""
164
+ elif '.mp3' in question.lower():
165
+ prompt = f"""This question refers to an attached audio file. Provide the most likely answer based on the context:\n\n{question}\n\nAnswer:"""
166
  else:
167
+ prompt = f"""This question refers to an attached file. Provide the most likely answer:\n\n{question}\n\nAnswer:"""
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
  ):
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 = ("In botany, a vegetable is any edible part of a plant that is not a fruit or seed. "
183
+ "Fruits contain seeds and develop from the ovary of a flower. Use this definition.")
184
+ prompt = f"{definition}\n\n{question}\n\nList only the requested items, alphabetized, comma separated, and do not include any explanations or extra words."
 
185
  else:
186
+ prompt = f"{question}\n\nList only the requested items, alphabetized, comma separated, and do not include any explanations or extra words."
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
 
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 number, word, or phrase (tweak regex as needed)
228
  match = re.search(r'^[A-Za-z0-9 ,+-]+', answer)
229
  if match:
230
+ answer = match.group(0).strip()
231
 
232
  return answer
233