updated app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,49 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
-
|
8 |
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
-
def
|
13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
18 |
"""
|
19 |
-
return
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -37,33 +64,31 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
42 |
model = HfApiModel(
|
43 |
-
max_tokens=2096,
|
44 |
-
temperature=0.5,
|
45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
46 |
-
custom_role_conversions=None,
|
47 |
)
|
48 |
|
49 |
-
|
50 |
# Import tool from Hub
|
51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
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 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
62 |
planning_interval=None,
|
63 |
name=None,
|
64 |
-
description=
|
65 |
prompt_templates=prompt_templates
|
66 |
)
|
67 |
|
68 |
-
|
69 |
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
from Gradio_UI import GradioUI
|
8 |
+
import openai
|
9 |
+
system_prompt ="""
|
10 |
+
Your are a helpful math assistant
|
11 |
+
Your task resides on helping me with math problems,in specific problems related to right triangles
|
12 |
+
Whenever I ask you to find a hypotenuse you will use the tool find_hypotenuse
|
13 |
+
The way you use the tools is by specifying a json blob.
|
14 |
+
Specifically, this json should have an `action` key (with the name of the tool to use) and an
|
15 |
+
`action_input` key (with the input to the tool going here).
|
16 |
+
|
17 |
+
The only values that should be in the "action" field are:
|
18 |
+
find_hypotenuse: Get the hypotenuse from the given cathetus, args: {"cathetus1": {"type": "int"},"cathetus2": {"type": "int"}}}
|
19 |
+
example use :
|
20 |
+
{{
|
21 |
+
"action": "find_hypotenuse",
|
22 |
+
cathetus1s: {1},
|
23 |
+
cathetus2: {2},
|
24 |
+
}}
|
25 |
+
Once you solve the problem and you have the answer this will be your following answer:
|
26 |
+
example: The hypotenuse of the right triangle is x
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
|
32 |
+
|
33 |
+
|
34 |
+
"""
|
35 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
36 |
@tool
|
37 |
+
def find_hypotenuse(cathetus1: int, cathetus2: int) -> int: # it's import to specify the return type
|
38 |
+
# Keep this format for the description / args / args description but feel free to modify the tool
|
39 |
+
"""A tool that does nothing yet
|
40 |
Args:
|
41 |
+
cathetus1
|
42 |
+
cathetus2
|
43 |
+
hypotenuse = (cathetus1**2 + cathetus2**2)**(1/2)
|
44 |
"""
|
45 |
+
return hypotenuse
|
46 |
+
|
47 |
|
48 |
@tool
|
49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
64 |
final_answer = FinalAnswerTool()
|
65 |
|
66 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
67 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
68 |
|
69 |
model = HfApiModel(
|
70 |
+
max_tokens=2096,
|
71 |
+
temperature=0.5,
|
72 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
73 |
+
custom_role_conversions=None,
|
74 |
)
|
75 |
|
|
|
76 |
# Import tool from Hub
|
77 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
78 |
|
79 |
with open("prompts.yaml", 'r') as stream:
|
80 |
prompt_templates = yaml.safe_load(stream)
|
81 |
+
|
82 |
agent = CodeAgent(
|
83 |
model=model,
|
84 |
+
tools=[find_hypotenuse], ## add your tools here (don't remove final answer)
|
85 |
max_steps=6,
|
86 |
verbosity_level=1,
|
87 |
grammar=None,
|
88 |
planning_interval=None,
|
89 |
name=None,
|
90 |
+
description=system_prompt,
|
91 |
prompt_templates=prompt_templates
|
92 |
)
|
93 |
|
|
|
94 |
GradioUI(agent).launch()
|