niahovcx commited on
Commit
0610923
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -3,35 +3,45 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
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
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
- def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
26
  """
27
- try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
33
- except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
35
 
36
 
37
  final_answer = FinalAnswerTool()
@@ -46,6 +56,7 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
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)
@@ -55,7 +66,10 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import re
7
  from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def summriaze_url(url:str, max_chars:int=4000)-> str: #it's import to specify the return type
14
  #Keep this format for the description / args / args description but feel free to modify the tool
15
+ """抓取网页文本,让智能体后续对其进行总结。
16
  Args:
17
+ url: 要抓取的网页地址(例如 'https://arxiv.org/abs/2501.13958')。
18
+ max_chars: 返回的最大字符数,用于截断过长的网页内容。
19
  """
20
+ try:
21
+ resp = requests.get(url, timeout=10)
22
+ resp.raise_for_status()
23
+ text = resp.text
24
+ # 粗暴一点,把多余空白压缩掉,让 LLM 更好读
25
+ text = re.sub(r"\s+", " ", text)
26
+ return text[:max_chars]
27
+ except Exception as e:
28
+ return f"Error fetching URL '{url}': {str(e)}"
29
 
30
  @tool
31
+ def research_brainstorm_topic(topic: str) -> str:
32
+ """一个辅助工具,用来把研究主题拆分成几个具体的方向。
33
  Args:
34
+ topic: 你的兴趣方向的简短描述(例如:“大语言模型幻觉评估”)。
35
  """
36
+ # 这里让 LLM 后续来扩展,这个工具只返回一个提示壳
37
+ return (
38
+ f"用户想要围绕「{topic}」这个方向的研究/项目灵感。"
39
+ "请将该主题拆解为以下部分:"
40
+ "(1)问题背景和问题定义;"
41
+ "(2)2~3 个可以实际落地的实验设计;"
42
+ "(3)可能使用的数据集或基准(benchmark);"
43
+ "(4)可以对比的简单基线方法。"
44
+ )
45
 
46
 
47
  final_answer = FinalAnswerTool()
 
56
  custom_role_conversions=None,
57
  )
58
 
59
+ search_tool = DuckDuckGoSearchTool()
60
 
61
  # Import tool from Hub
62
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
66
 
67
  agent = CodeAgent(
68
  model=model,
69
+ tools=[final_answer,
70
+ search_tool,
71
+ summriaze_url,
72
+ research_brainstorm_topic,], ## add your tools here (don't remove final answer)
73
  max_steps=6,
74
  verbosity_level=1,
75
  grammar=None,