Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
from smolagents import
|
| 2 |
-
from tools import DuckDuckGoSearchTool
|
| 3 |
import os
|
| 4 |
|
| 5 |
class BasicAgent:
|
|
@@ -10,15 +10,15 @@ class BasicAgent:
|
|
| 10 |
print(f"Agent received question (first 50 chars): {question[:50]} ...")
|
| 11 |
|
| 12 |
# Using Qwen
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
)
|
| 18 |
-
|
| 19 |
agent = CodeAgent(
|
| 20 |
model=model,
|
| 21 |
-
tools=[DuckDuckGoSearchTool()]
|
| 22 |
)
|
| 23 |
prompt = f"""You are a general AI assistant. I will ask you a question. Report your thoughts, and
|
| 24 |
finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should
|
|
@@ -29,7 +29,11 @@ write the digits in plain text unless specified otherwise. If you are asked for
|
|
| 29 |
the above rules depending of whether the element to be put in the list is a number or a string.
|
| 30 |
{question}
|
| 31 |
"""
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
print(f"Agent returning answer: {answer}")
|
| 35 |
return answer
|
|
|
|
| 1 |
+
from smolagents import HfApiModel, ToolCallingAgent, CodeAgent
|
| 2 |
+
from tools import DuckDuckGoSearchTool, get_current_time_in_timezone
|
| 3 |
import os
|
| 4 |
|
| 5 |
class BasicAgent:
|
|
|
|
| 10 |
print(f"Agent received question (first 50 chars): {question[:50]} ...")
|
| 11 |
|
| 12 |
# Using Qwen
|
| 13 |
+
model = HfApiModel(
|
| 14 |
+
max_tokens=2096,
|
| 15 |
+
temperature=0.5,
|
| 16 |
+
model_id = os.getenv("QWEN_MODEL"),# it is possible that this model may be overloaded
|
| 17 |
+
custom_role_conversions=None,
|
| 18 |
)
|
|
|
|
| 19 |
agent = CodeAgent(
|
| 20 |
model=model,
|
| 21 |
+
tools=[DuckDuckGoSearchTool(),get_current_time_in_timezone]
|
| 22 |
)
|
| 23 |
prompt = f"""You are a general AI assistant. I will ask you a question. Report your thoughts, and
|
| 24 |
finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should
|
|
|
|
| 29 |
the above rules depending of whether the element to be put in the list is a number or a string.
|
| 30 |
{question}
|
| 31 |
"""
|
| 32 |
+
try:
|
| 33 |
+
answer = agent.run(prompt)
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Agent failed: {e}")
|
| 36 |
+
answer = "Error: Agent could not complete the request."
|
| 37 |
|
| 38 |
print(f"Agent returning answer: {answer}")
|
| 39 |
return answer
|