Spaces:
Sleeping
Sleeping
Update gemini_agent.py
Browse files- 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
|
| 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
|
| 171 |
-
elif '.mp3' in question.lower()
|
| 172 |
-
prompt = f"""This question refers to an attached audio file.
|
| 173 |
else:
|
| 174 |
-
prompt = f"""This question refers to an attached file. Provide the most
|
| 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 = ("
|
| 190 |
-
"
|
| 191 |
-
|
| 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\
|
| 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
|
| 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 |
|