Spaces:
Restarting
Restarting
Update agent.py
Browse files
agent.py
CHANGED
@@ -3,8 +3,8 @@ import asyncio
|
|
3 |
|
4 |
class MagAgent:
|
5 |
def __init__(self):
|
6 |
-
"""Initialize the
|
7 |
-
print("Initializing
|
8 |
self.agent = CodeAgent(
|
9 |
model=OpenAIServerModel(model_name="gpt-4o-mini"), # Use a lightweight model
|
10 |
tools=[
|
@@ -12,18 +12,18 @@ class MagAgent:
|
|
12 |
WikipediaSearchTool()
|
13 |
]
|
14 |
)
|
15 |
-
print("
|
16 |
|
17 |
async def __call__(self, question: str) -> str:
|
18 |
-
"""Process a question asynchronously using the
|
19 |
-
print(f"
|
20 |
try:
|
21 |
# Run the agent asynchronously
|
22 |
response = await asyncio.to_thread(
|
23 |
self.agent.run,
|
24 |
prompt=f"Answer the following question accurately and concisely: {question}"
|
25 |
)
|
26 |
-
print(f"
|
27 |
return response
|
28 |
except Exception as e:
|
29 |
error_msg = f"Error processing question: {e}"
|
|
|
3 |
|
4 |
class MagAgent:
|
5 |
def __init__(self):
|
6 |
+
"""Initialize the MagAgent with search tools."""
|
7 |
+
print("Initializing MagAgent with search tools...")
|
8 |
self.agent = CodeAgent(
|
9 |
model=OpenAIServerModel(model_name="gpt-4o-mini"), # Use a lightweight model
|
10 |
tools=[
|
|
|
12 |
WikipediaSearchTool()
|
13 |
]
|
14 |
)
|
15 |
+
print("MagAgent initialized.")
|
16 |
|
17 |
async def __call__(self, question: str) -> str:
|
18 |
+
"""Process a question asynchronously using the MagAgent."""
|
19 |
+
print(f"MagAgent received question (first 50 chars): {question[:50]}...")
|
20 |
try:
|
21 |
# Run the agent asynchronously
|
22 |
response = await asyncio.to_thread(
|
23 |
self.agent.run,
|
24 |
prompt=f"Answer the following question accurately and concisely: {question}"
|
25 |
)
|
26 |
+
print(f"MagAgent response: {response[:50]}...")
|
27 |
return response
|
28 |
except Exception as e:
|
29 |
error_msg = f"Error processing question: {e}"
|