ldidone commited on
Commit
d927d8b
·
1 Parent(s): 860b0fc

Added who_am_i tool to get the user's fullname via HF API.

Browse files
Files changed (2) hide show
  1. app.py +22 -3
  2. prompts.yaml +17 -0
app.py CHANGED
@@ -20,6 +20,19 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
20
  """
21
  return "What magic will you build ?"
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  @tool
24
  def get_current_time_in_timezone(timezone: str) -> str:
25
  """A tool that fetches the current local time in a specified timezone.
@@ -46,8 +59,7 @@ visit_webpage = VisitWebpageTool()
46
  model = HfApiModel(
47
  max_tokens=2096,
48
  temperature=0.5,
49
- # model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
50
- model_id='Qwen/QwQ-32B',
51
  custom_role_conversions=None,
52
  )
53
 
@@ -60,7 +72,14 @@ with open("prompts.yaml", 'r') as stream:
60
 
61
  agent = CodeAgent(
62
  model=model,
63
- tools=[get_current_time_in_timezone, web_search, visit_webpage, final_answer], ## add your tools here (don't remove final answer)
 
 
 
 
 
 
 
64
  max_steps=6,
65
  verbosity_level=1,
66
  grammar=None,
 
20
  """
21
  return "What magic will you build ?"
22
 
23
+ @tool
24
+ def who_am_i()-> str:
25
+ """A tool that return the full name of the user given by Hugging Face API
26
+
27
+ Returns:
28
+ str: The user's full name
29
+ """
30
+ response = requests.get("https://huggingface.co/api/whoami-v2")
31
+ if response.status_code == 200:
32
+ return response.json().get("fullname", "Error fetching user's full name")
33
+ else:
34
+ return "Error fetching user's full name"
35
+
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
38
  """A tool that fetches the current local time in a specified timezone.
 
59
  model = HfApiModel(
60
  max_tokens=2096,
61
  temperature=0.5,
62
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
 
63
  custom_role_conversions=None,
64
  )
65
 
 
72
 
73
  agent = CodeAgent(
74
  model=model,
75
+ tools=[
76
+ get_current_time_in_timezone,
77
+ web_search,
78
+ visit_webpage,
79
+ image_generation_tool,
80
+ who_am_i,
81
+ final_answer
82
+ ], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
prompts.yaml CHANGED
@@ -28,6 +28,23 @@
28
  final_answer(image)
29
  ```<end_code>
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ---
32
  Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
33
 
 
28
  final_answer(image)
29
  ```<end_code>
30
 
31
+ ---
32
+ Task: "Get the full name of the user that asks."
33
+
34
+ Thought: I will proceed step by step and use the following tools: `who_am_i` to find the full name of the user.
35
+ Code:
36
+ ```py
37
+ full_name = who_am_i()
38
+ print(full_name)
39
+ ```<end_code>
40
+ Observation: "Lucas Didone"
41
+
42
+ Thought: I will show the user's name.
43
+ Code:
44
+ ```py
45
+ final_answer(full_name)
46
+ ```<end_code>
47
+
48
  ---
49
  Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
50