M2LabOrg commited on
Commit
ac30d64
·
verified ·
1 Parent(s): f0fcaa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -8
app.py CHANGED
@@ -46,15 +46,39 @@ def generate_image(prompt:str) -> list:
46
  return image_generation_tool(prompt)
47
 
48
  @tool
49
- def duckduckgo_search(query: str, max_results: int=5) -> str:
50
- """Search DuckDuckGo for a query and return the top results.
 
 
 
 
 
 
 
 
 
51
  Args:
52
- query: the search terms
53
- max_results: how many results to fetch
 
 
54
  """
55
- searcher = DuckDuckGoSearchTool()
56
- results = searcher(query, max_results=max_results)
57
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
 
@@ -78,7 +102,8 @@ with open("prompts.yaml", 'r') as stream:
78
 
79
  agent = CodeAgent(
80
  model=model,
81
- tools=[final_answer, duckduckgo_search, get_current_time_in_timezone, my_custom_tool, generate_image], ## add your tools here (don't remove final answer)
 
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,
 
46
  return image_generation_tool(prompt)
47
 
48
  @tool
49
+ def duckduckgo_search(query: str, max_results: int = 5) -> str:
50
+ """Search DuckDuckGo for a query and return the top N results."""
51
+ searcher = DuckDuckGoSearchTool(max_results=max_results)
52
+ return searcher(query)
53
+
54
+
55
+ @tool
56
+ def is_prime(number: int) -> bool:
57
+ """
58
+ Check if a number is prime using an optimized 6k±1 algorithm.
59
+
60
  Args:
61
+ number: The integer to check for primality.
62
+
63
+ Returns:
64
+ True if `number` is prime, False otherwise.
65
  """
66
+ # Numbers less than 2 are not prime
67
+ if number <= 1:
68
+ return False
69
+ # 2 and 3 are prime
70
+ if number <= 3:
71
+ return True
72
+ # Eliminate multiples of 2 and 3
73
+ if number % 2 == 0 or number % 3 == 0:
74
+ return False
75
+ # Test 6k ± 1 factors up to sqrt(number)
76
+ i = 5
77
+ while i * i <= number:
78
+ if number % i == 0 or number % (i + 2) == 0:
79
+ return False
80
+ i += 6
81
+ return True
82
 
83
 
84
 
 
102
 
103
  agent = CodeAgent(
104
  model=model,
105
+ tools=[final_answer, duckduckgo_search, get_current_time_in_timezone, my_custom_tool, generate_image,
106
+ is_prime], ## add your tools here (don't remove final answer)
107
  max_steps=6,
108
  verbosity_level=1,
109
  grammar=None,