blade57 commited on
Commit
7775127
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -34,6 +34,39 @@ def get_current_time_in_timezone(timezone: str) -> str:
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:
@@ -55,7 +88,7 @@ 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,
@@ -65,5 +98,4 @@ agent = CodeAgent(
65
  prompt_templates=prompt_templates
66
  )
67
 
68
-
69
  GradioUI(agent).launch()
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ @tool
38
+ def check_is_prime(number_to_check:int)-> str: #it's import to specify the return type
39
+ """A tool that checks if the number is a prime number or not
40
+ Args:
41
+ number_to_check: the number to check
42
+ """
43
+ return_text = ""
44
+ # Negative numbers, 0 and 1 are not primes
45
+ if number_to_check > 1:
46
+
47
+ # Iterate from 2 to n // 2
48
+ for i in range(2, (number_to_check//2)+1):
49
+
50
+ # If num is divisible by any number between
51
+ # 2 and n / 2, it is not prime
52
+ if (number_to_check % i) == 0:
53
+ print(number_to_check, "is not a prime number")
54
+ break
55
+ else:
56
+ return_text = "is a prime number")
57
+ else:
58
+ return_text = "is not a prime number")
59
+ return return_text
60
+
61
+ @tool
62
+ def get_scientific_notation(number_to_convert:int)-> str: #it's import to specify the return type
63
+ """A tool that converts a number to scientific notation
64
+ Args:
65
+ number_to_convert: the first argument
66
+ """
67
+ number = 12345.6789
68
+ return f"{number_to_convert:.2e}"
69
+
70
  final_answer = FinalAnswerTool()
71
 
72
  # 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:
 
88
 
89
  agent = CodeAgent(
90
  model=model,
91
+ tools=[final_answer, check_is_prime, get_scientific_notation], ## add your tools here (don't remove final answer)
92
  max_steps=6,
93
  verbosity_level=1,
94
  grammar=None,
 
98
  prompt_templates=prompt_templates
99
  )
100
 
 
101
  GradioUI(agent).launch()