Spaces:
Sleeping
Sleeping
fix: agent flow
Browse files- services/model_handler.py +40 -1
services/model_handler.py
CHANGED
@@ -232,12 +232,14 @@ Output:"""
|
|
232 |
|
233 |
def generate_answer(self, query: str) -> str:
|
234 |
try:
|
|
|
235 |
# Format translation prompt
|
236 |
translation_prompt = self._format_prompt(
|
237 |
role="Translate the following text to English",
|
238 |
instructions="Provide a direct English translation of the input text.",
|
239 |
query=query
|
240 |
)
|
|
|
241 |
|
242 |
# Get English translation
|
243 |
translation = self.translator.run(prompt=translation_prompt, stream=False)
|
@@ -245,12 +247,15 @@ Output:"""
|
|
245 |
logging.error("Translation failed")
|
246 |
return "Error: Unable to translate the query"
|
247 |
|
|
|
|
|
248 |
# Format research prompt
|
249 |
research_prompt = self._format_prompt(
|
250 |
role="Research Assistant",
|
251 |
instructions="Provide a clear and concise answer based on scientific sources.",
|
252 |
query=translation
|
253 |
)
|
|
|
254 |
|
255 |
# Get research results
|
256 |
research_results = self.researcher.run(prompt=research_prompt, stream=False)
|
@@ -258,7 +263,41 @@ Output:"""
|
|
258 |
logging.error("Research failed")
|
259 |
return "Error: Unable to perform research"
|
260 |
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
except Exception as e:
|
263 |
logging.error(f"Error generating answer: {str(e)}")
|
264 |
return f"Error: {str(e)}"
|
|
|
232 |
|
233 |
def generate_answer(self, query: str) -> str:
|
234 |
try:
|
235 |
+
logging.info(f"Generating answer for query: {query}")
|
236 |
# Format translation prompt
|
237 |
translation_prompt = self._format_prompt(
|
238 |
role="Translate the following text to English",
|
239 |
instructions="Provide a direct English translation of the input text.",
|
240 |
query=query
|
241 |
)
|
242 |
+
logging.info(f"Translation prompt: {translation_prompt}")
|
243 |
|
244 |
# Get English translation
|
245 |
translation = self.translator.run(prompt=translation_prompt, stream=False)
|
|
|
247 |
logging.error("Translation failed")
|
248 |
return "Error: Unable to translate the query"
|
249 |
|
250 |
+
logging.info(f"Translation: {translation}")
|
251 |
+
|
252 |
# Format research prompt
|
253 |
research_prompt = self._format_prompt(
|
254 |
role="Research Assistant",
|
255 |
instructions="Provide a clear and concise answer based on scientific sources.",
|
256 |
query=translation
|
257 |
)
|
258 |
+
logging.info(f"Research prompt: {research_prompt}")
|
259 |
|
260 |
# Get research results
|
261 |
research_results = self.researcher.run(prompt=research_prompt, stream=False)
|
|
|
263 |
logging.error("Research failed")
|
264 |
return "Error: Unable to perform research"
|
265 |
|
266 |
+
logging.info(f"Research results: {research_results}")
|
267 |
+
|
268 |
+
# Format summary prompt
|
269 |
+
summary_prompt = self._format_prompt(
|
270 |
+
role="Summary Assistant",
|
271 |
+
instructions="Provide a clear and concise summary of the research results.",
|
272 |
+
query=research_results
|
273 |
+
)
|
274 |
+
logging.info(f"Summary prompt: {summary_prompt}")
|
275 |
+
|
276 |
+
# Get summary
|
277 |
+
summary = self.summarizer.run(prompt=summary_prompt, stream=False)
|
278 |
+
if not summary:
|
279 |
+
logging.error("Summary failed")
|
280 |
+
return "Error: Unable to generate summary"
|
281 |
+
|
282 |
+
logging.info(f"Summary: {summary}")
|
283 |
+
|
284 |
+
# Format presentation prompt
|
285 |
+
presentation_prompt = self._format_prompt(
|
286 |
+
role="Presentation Assistant",
|
287 |
+
instructions="Provide a clear and concise presentation of the research results.",
|
288 |
+
query=summary
|
289 |
+
)
|
290 |
+
logging.info(f"Presentation prompt: {presentation_prompt}")
|
291 |
+
|
292 |
+
# Get presentation
|
293 |
+
presentation = self.presenter.run(prompt=presentation_prompt, stream=False)
|
294 |
+
if not presentation:
|
295 |
+
logging.error("Presentation failed")
|
296 |
+
return "Error: Unable to generate presentation"
|
297 |
+
|
298 |
+
logging.info(f"Presentation: {presentation}")
|
299 |
+
|
300 |
+
return presentation
|
301 |
except Exception as e:
|
302 |
logging.error(f"Error generating answer: {str(e)}")
|
303 |
return f"Error: {str(e)}"
|