Coool2 commited on
Commit
3c271e0
·
verified ·
1 Parent(s): 2112ee7

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +39 -14
agent.py CHANGED
@@ -462,21 +462,46 @@ class EnhancedGAIAAgent:
462
  task_id = question_data.get("task_id", "")
463
 
464
  context_prompt = f"""
465
- GAIA Task ID: {task_id}
466
- Question: {question}
467
-
468
- {f"Associated files: {question_data.get('file_name', '')}" if 'file_name' in question_data else 'No files provided'}
469
-
470
- Instructions:
471
- 1. Analyze this GAIA question using ReAct reasoning
472
- 2. Use specialist agents ONLY when their specific expertise is needed
473
- 3. Provide a precise, exact answer in GAIA format
474
-
475
- Begin your reasoning process:
476
- """
477
-
478
  try:
479
- response = self.coordinator.chat(context_prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  return str(response)
 
481
  except Exception as e:
482
  return f"Error processing question: {str(e)}"
 
462
  task_id = question_data.get("task_id", "")
463
 
464
  context_prompt = f"""
465
+ GAIA Task ID: {task_id}
466
+ Question: {question}
467
+ {f"Associated files: {question_data.get('file_name', '')}" if 'file_name' in question_data else 'No files provided'}
468
+
469
+ Instructions:
470
+ 1. Analyze this GAIA question using ReAct reasoning
471
+ 2. Use specialist agents ONLY when their specific expertise is needed
472
+ 3. Provide a precise, exact answer in GAIA format
473
+
474
+ Begin your reasoning process:
475
+ """
476
+
 
477
  try:
478
+ # Utiliser la méthode correcte pour ReActAgent
479
+ import asyncio
480
+
481
+ # Créer un contexte pour le workflow
482
+ from llama_index.core.workflow import Context
483
+ ctx = Context(self.coordinator)
484
+
485
+ # Exécuter le workflow de manière asynchrone
486
+ async def run_agent():
487
+ response = await self.coordinator.run(ctx=ctx, input=context_prompt)
488
+ return response
489
+
490
+ # Exécuter dans une boucle d'événements
491
+ try:
492
+ loop = asyncio.get_event_loop()
493
+ if loop.is_running():
494
+ # Si on est déjà dans une boucle async (comme dans Gradio)
495
+ import nest_asyncio
496
+ nest_asyncio.apply()
497
+ response = loop.run_until_complete(run_agent())
498
+ else:
499
+ response = asyncio.run(run_agent())
500
+ except RuntimeError:
501
+ # Fallback pour les environnements où asyncio pose problème
502
+ response = asyncio.run(run_agent())
503
+
504
  return str(response)
505
+
506
  except Exception as e:
507
  return f"Error processing question: {str(e)}"