Youlln commited on
Commit
d238c40
·
verified ·
1 Parent(s): a69a909

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -294,9 +294,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
294
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
295
 
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  final_answer = FinalAnswerTool()
298
- web_search_tool = DuckDuckGoSearchTool(max_results=5) # Vous pouvez ajuster max_results selon vos besoins
299
- visit_webpage_tool = VisitWebpageTool()
300
 
301
  # 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:
302
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -323,8 +346,7 @@ agent = CodeAgent(
323
  timer_tool,
324
  inspiration_generator,
325
  get_current_time_in_timezone,
326
- web_search_tool,
327
- visit_webpage_tool
328
  ], ## add your tools here (don't remove final answer)
329
  max_steps=6,
330
  verbosity_level=1,
 
294
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
295
 
296
 
297
+ # Version simplifiée de l'outil de recherche web
298
+ @tool
299
+ def web_search(query: str) -> str:
300
+ """Effectue une recherche web DuckDuckGo et retourne les meilleurs résultats.
301
+
302
+ Args:
303
+ query: La requête de recherche à effectuer.
304
+ """
305
+ try:
306
+ from duckduckgo_search import DDGS
307
+ ddgs = DDGS()
308
+ results = ddgs.text(query, max_results=5)
309
+
310
+ if len(results) == 0:
311
+ return "Aucun résultat trouvé. Essayez une requête moins restrictive ou plus courte."
312
+
313
+ formatted_results = ["## Résultats de recherche\n"]
314
+ for result in results:
315
+ formatted_results.append(f"[{result['title']}]({result['href']})\n{result['body']}\n")
316
+
317
+ return "\n".join(formatted_results)
318
+ except Exception as e:
319
+ return f"Erreur lors de la recherche: {str(e)}"
320
+
321
  final_answer = FinalAnswerTool()
322
+
 
323
 
324
  # 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:
325
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
346
  timer_tool,
347
  inspiration_generator,
348
  get_current_time_in_timezone,
349
+ web_search
 
350
  ], ## add your tools here (don't remove final answer)
351
  max_steps=6,
352
  verbosity_level=1,