-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicAgent.py
More file actions
48 lines (38 loc) · 1.69 KB
/
BasicAgent.py
File metadata and controls
48 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import gradio as gr
import time
from typing import Optional
from agent import workflow
from api_GAIA import ApiClienteGAIA
class BasicAgent:
def __init__(self):
print("BasicAgent initialized.")
self.agent = workflow
async def __call__(self, question: str, task_file_path: Optional[str] = None) -> str:
print(f"Agent received question (first 50 chars): {question[:50]}...")
try:
if task_file_path:
try:
with open(task_file_path, 'r') as f:
file_content = f.read()
# Determine file type from extension
file_ext = os.path.splitext(task_file_path)[1].lower()
context = f"""
Question: {question}
This question has an associated file. Here is the file content:
```{file_ext}
{file_content}
```
Analyze the file content above to answer the question.
"""
question = context
except Exception as e:
print(f"Error {e}")
answer = await self.agent.run(question)
fixed_answer = str(answer).removeprefix("FINAL ANSWER:").removeprefix("FINAL ANSWER :").strip()
print(f"Agent returning fixed answer: {str(fixed_answer)}")
time.sleep(35)
return fixed_answer
except Exception as e:
print(f"Error in agent execution: {str(e)}")
return f"Error: {str(e)}"