Commit
·
0def8be
1
Parent(s):
ae7a494
update tool
Browse files
app.py
CHANGED
@@ -1,22 +1,39 @@
|
|
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 |
-
#
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -33,8 +50,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
-
|
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'
|
@@ -42,11 +60,10 @@ final_answer = FinalAnswerTool()
|
|
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 |
|
@@ -55,7 +72,14 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
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 tools.visit_webpage import VisitWebpageTool
|
8 |
+
from tools.web_search import DuckDuckGoSearchTool
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
|
12 |
+
# 導入基本工具
|
13 |
@tool
|
14 |
+
def random_number_generator(min_value: int, max_value: int) -> int:
|
15 |
+
"""生成指定範圍內的隨機整數
|
|
|
16 |
Args:
|
17 |
+
min_value: 隨機數的最小值
|
18 |
+
max_value: 隨機數的最大值
|
19 |
"""
|
20 |
+
import random
|
21 |
+
return random.randint(min_value, max_value)
|
22 |
+
|
23 |
+
@tool
|
24 |
+
def calculate_days_between(start_date: str, end_date: str) -> int:
|
25 |
+
"""計算兩個日期之間的天數差異
|
26 |
+
Args:
|
27 |
+
start_date: 開始日期,格式為 YYYY-MM-DD
|
28 |
+
end_date: 結束日期,格式為 YYYY-MM-DD
|
29 |
+
"""
|
30 |
+
try:
|
31 |
+
start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
|
32 |
+
end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
|
33 |
+
delta = end - start
|
34 |
+
return delta.days
|
35 |
+
except Exception as e:
|
36 |
+
return f"錯誤:{str(e)}"
|
37 |
|
38 |
@tool
|
39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
50 |
except Exception as e:
|
51 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
52 |
|
|
|
53 |
final_answer = FinalAnswerTool()
|
54 |
+
web_search = DuckDuckGoSearchTool()
|
55 |
+
visit_webpage = VisitWebpageTool()
|
56 |
|
57 |
# 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:
|
58 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
60 |
model = HfApiModel(
|
61 |
max_tokens=2096,
|
62 |
temperature=0.5,
|
63 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
64 |
custom_role_conversions=None,
|
65 |
)
|
66 |
|
|
|
67 |
# Import tool from Hub
|
68 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
69 |
|
|
|
72 |
|
73 |
agent = CodeAgent(
|
74 |
model=model,
|
75 |
+
tools=[
|
76 |
+
final_answer,
|
77 |
+
get_current_time_in_timezone,
|
78 |
+
random_number_generator,
|
79 |
+
calculate_days_between,
|
80 |
+
web_search,
|
81 |
+
visit_webpage
|
82 |
+
], # 添加您的工具
|
83 |
max_steps=6,
|
84 |
verbosity_level=1,
|
85 |
grammar=None,
|