jonnnnnnnyChan commited on
Commit
07ad07e
·
verified ·
1 Parent(s): 325256c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -27
app.py CHANGED
@@ -1,14 +1,11 @@
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
  from huggingface_hub import login
11
-
12
  import os
13
 
14
  # 从环境变量获取 Token
@@ -16,55 +13,47 @@ token = os.getenv("HUGGINGFACE_HUB_TOKEN")
16
  # 输入从 Hugging Face 网站获取的 API Token
17
  login(token)
18
 
19
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
20
  @tool
21
- def call_me_here(arg1:str, arg2:int)-> str: #it's import to specify the return type
22
- #Keep this format for the description / args / args description but feel free to modify the tool
23
- """A tool that does nothing yet
24
  Args:
25
- arg1: the first argument
26
- arg2: the second argument
27
  """
28
- return f"How do you do '{arg1}',you are calling {arg2} now!"
29
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
32
- """A tool that fetches the current local time in a specified timezone.
33
  Args:
34
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
35
  """
36
  try:
37
- # Create timezone object
38
  tz = pytz.timezone(timezone)
39
- # Get current time in that timezone
40
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
41
  return f"The current local time in {timezone} is: {local_time}"
42
  except Exception as e:
43
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
44
 
45
-
46
  final_answer = FinalAnswerTool()
47
 
48
- # 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:
49
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
50
-
51
  model = HfApiModel(
52
- max_tokens=2096,
53
- temperature=0.5,
54
- model_id= 'Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
55
- custom_role_conversions=None,
56
  )
57
 
58
-
59
  # Import tool from Hub
60
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
61
 
62
  with open("prompts.yaml", 'r') as stream:
63
  prompt_templates = yaml.safe_load(stream)
64
-
65
  agent = CodeAgent(
66
  model=model,
67
- tools=[final_answer], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,
@@ -74,5 +63,4 @@ agent = CodeAgent(
74
  prompt_templates=prompt_templates
75
  )
76
 
77
-
78
  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
  from huggingface_hub import login
 
9
  import os
10
 
11
  # 从环境变量获取 Token
 
13
  # 输入从 Hugging Face 网站获取的 API Token
14
  login(token)
15
 
16
+ # 这个工具将根据输入参数返回一条自定义消息
17
  @tool
18
+ def call_me_here(name: str, count: int) -> str:
19
+ """返回一个问候消息。
 
20
  Args:
21
+ name: 被称呼的名字
22
+ count: 一个整数计数
23
  """
24
+ return f"Hello {name}, you are calling me {count} times now!"
25
 
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
28
+ """获取指定时区的当前本地时间。
29
  Args:
30
+ timezone: 字符串,表示有效的时区(例如,'America/New_York')。
31
  """
32
  try:
 
33
  tz = pytz.timezone(timezone)
 
34
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
35
  return f"The current local time in {timezone} is: {local_time}"
36
  except Exception as e:
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
 
 
39
  final_answer = FinalAnswerTool()
40
 
 
 
 
41
  model = HfApiModel(
42
+ max_tokens=2096,
43
+ temperature=0.5,
44
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
45
+ custom_role_conversions=None,
46
  )
47
 
 
48
  # Import tool from Hub
49
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
50
 
51
  with open("prompts.yaml", 'r') as stream:
52
  prompt_templates = yaml.safe_load(stream)
53
+
54
  agent = CodeAgent(
55
  model=model,
56
+ tools=[final_answer, call_me_here, get_current_time_in_timezone], # 添加 call_me_here 工具
57
  max_steps=6,
58
  verbosity_level=1,
59
  grammar=None,
 
63
  prompt_templates=prompt_templates
64
  )
65
 
 
66
  GradioUI(agent).launch()