manzoor1234 commited on
Commit
610adfd
·
verified ·
1 Parent(s): 8c5c24b

Create appy.py

Browse files
Files changed (1) hide show
  1. appy.py +53 -0
appy.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, InferenceClientModel, load_tool, tool
2
+ import datetime
3
+ import requests
4
+ import pytz
5
+ import yaml
6
+ @tool
7
+ def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
8
+ # Keep this format for the tool description / args description but feel free to modify the tool
9
+ """A tool that does nothing yet
10
+ Args:
11
+ arg1: the first argument
12
+ arg2: the second argument
13
+ """
14
+ return "What magic will you build ?"
15
+
16
+ @tool
17
+ def get_current_time_in_timezone(timezone: str) -> str:
18
+ """A tool that fetches the current local time in a specified timezone.
19
+ Args:
20
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
21
+ """
22
+ try:
23
+ # Create timezone object
24
+ tz = pytz.timezone(timezone)
25
+ # Get current time in that timezone
26
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
27
+ return f"The current local time in {timezone} is: {local_time}"
28
+ except Exception as e:
29
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"final_answer = FinalAnswerTool()
30
+ model = InferenceClientModel(
31
+ max_tokens=2096,
32
+ temperature=0.5,
33
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
34
+ custom_role_conversions=None,
35
+ )
36
+
37
+ with open("prompts.yaml", 'r') as stream:
38
+ prompt_templates = yaml.safe_load(stream)
39
+
40
+ # We're creating our CodeAgent
41
+ agent = CodeAgent(
42
+ model=model,
43
+ tools=[final_answer], # add your tools here (don't remove final_answer)
44
+ max_steps=6,
45
+ verbosity_level=1,
46
+ grammar=None,
47
+ planning_interval=None,
48
+ name=None,
49
+ description=None,
50
+ prompt_templates=prompt_templates
51
+ )
52
+
53
+ GradioUI(agent).launch()