Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -258,41 +258,41 @@ class BasicAgent:
|
|
| 258 |
|
| 259 |
def _formulate_direct_answer(self, relevant_info, question):
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
if self.model.startswith('gemini'):
|
| 265 |
-
try:
|
| 266 |
-
|
| 267 |
-
if not hasattr(self, 'gemini_model') or self.gemini_model is None:
|
| 268 |
-
self._init_gemini_model()
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
prompt = f"""
|
| 272 |
-
Question: {question}
|
| 273 |
-
|
| 274 |
-
Relevant information: {relevant_info}
|
| 275 |
-
|
| 276 |
-
Instructions:
|
| 277 |
-
1. Provide a concise answer based only on the given information
|
| 278 |
-
2. If the information doesn't contain the answer, say so honestly
|
| 279 |
-
3. Use only facts from the provided information
|
| 280 |
-
4. Format your response as a direct answer to the user
|
| 281 |
-
"""
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
return f"Based on the information: {relevant_info[:200]}..."
|
| 289 |
|
| 290 |
-
except Exception as e:
|
| 291 |
-
print(f"Error using Gemini model: {e}")
|
| 292 |
-
traceback.print_exc()
|
| 293 |
-
return f"Based on the search: {relevant_info[:200]}..."
|
| 294 |
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
|
| 298 |
|
|
|
|
| 258 |
|
| 259 |
def _formulate_direct_answer(self, relevant_info, question):
|
| 260 |
|
| 261 |
+
if not self.model:
|
| 262 |
+
return f"Based on available information: {relevant_info}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
if self.model.startswith('gemini'):
|
| 265 |
+
try:
|
| 266 |
+
|
| 267 |
+
if not hasattr(self, 'gemini_model') or self.gemini_model is None:
|
| 268 |
+
self._init_gemini_model()
|
|
|
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
+
prompt = f"""
|
| 272 |
+
Question: {question}
|
| 273 |
+
|
| 274 |
+
Relevant information: {relevant_info}
|
| 275 |
+
|
| 276 |
+
Instructions:
|
| 277 |
+
1. Provide a concise answer based only on the given information
|
| 278 |
+
2. If the information doesn't contain the answer, say so honestly
|
| 279 |
+
3. Use only facts from the provided information
|
| 280 |
+
4. Format your response as a direct answer to the user
|
| 281 |
+
"""
|
| 282 |
+
|
| 283 |
+
response = self.gemini_model.generate_content(prompt)
|
| 284 |
+
if response and hasattr(response, 'text'):
|
| 285 |
+
return response.text
|
| 286 |
+
else:
|
| 287 |
+
print("Gemini response was empty or invalid")
|
| 288 |
+
return f"Based on the information: {relevant_info[:200]}..."
|
| 289 |
+
|
| 290 |
+
except Exception as e:
|
| 291 |
+
print(f"Error using Gemini model: {e}")
|
| 292 |
+
traceback.print_exc()
|
| 293 |
+
return f"Based on the search: {relevant_info[:200]}..."
|
| 294 |
+
|
| 295 |
+
return f"Based on the information: {relevant_info[:200]}..."
|
| 296 |
|
| 297 |
|
| 298 |
|