Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -8,20 +8,6 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
|
11 |
-
@tool
|
12 |
-
{
|
13 |
-
"name": "sum_tool",
|
14 |
-
"type": "Code",
|
15 |
-
"function": "calculate",
|
16 |
-
"input_parameters": {
|
17 |
-
"math_expression": "string"
|
18 |
-
},
|
19 |
-
"output": {
|
20 |
-
"result": "number"
|
21 |
-
},
|
22 |
-
"code": "return eval(math_expression)"
|
23 |
-
}
|
24 |
-
|
25 |
|
26 |
@tool
|
27 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -37,39 +23,13 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
38 |
|
39 |
|
40 |
-
|
41 |
-
model = HfApiModel(
|
42 |
-
max_tokens=2096,
|
43 |
-
temperature=0.5,
|
44 |
-
model_id='Qwen/Qwen2.5-Coder-3B-Instruct',# it is possible that this model may be overloaded
|
45 |
-
custom_role_conversions=None,
|
46 |
-
)
|
47 |
-
|
48 |
-
|
49 |
-
# Import tool from Hub
|
50 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
51 |
-
search_tool = DuckDuckGoSearchTool()
|
52 |
|
53 |
-
with open("prompts.yaml", 'r') as stream:
|
54 |
-
prompt_templates = yaml.safe_load(stream)
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[
|
59 |
-
|
60 |
-
verbosity_level=1,
|
61 |
-
grammar=None,
|
62 |
-
planning_interval=None,
|
63 |
-
name=None,
|
64 |
-
description=None,
|
65 |
-
prompt_templates=prompt_templates
|
66 |
)
|
67 |
|
68 |
-
|
69 |
-
total_input_tokens += agent.model.last_input_token_count
|
70 |
-
else:
|
71 |
-
# Handle the case where last_input_token_count is None
|
72 |
-
# For example, you can set total_input_tokens to a default value
|
73 |
-
total_input_tokens = 0
|
74 |
-
|
75 |
-
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLModel
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@tool
|
13 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
23 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
24 |
|
25 |
|
26 |
+
model = LiteLLModel(model_id = "gpt-4o-mini", api_key="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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
|
|
28 |
|
29 |
agent = CodeAgent(
|
30 |
model=model,
|
31 |
+
tools=[DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
32 |
+
additional_authorized_imports=['math'],
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
+
agent.run( "Calculate how long does it take to drive from Melbourne to Sydney?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|