Skip to content

Commit 5e5bac0

Browse files
author
Bintou DIOP
committed
modification de l'outil search
1 parent 6236462 commit 5e5bac0

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

agent_tools.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# tools.py
21
import os
32
import requests
43
import ast
@@ -11,12 +10,12 @@
1110
from langchain_core.tools import tool
1211
from langchain_tavily import TavilySearch
1312

14-
# --- Configuration et Initialisation ---
13+
# Configuration et Initialisation
1514
load_dotenv()
1615
OPENWEATHER_API_KEY = os.getenv("OPENWEATHER_API_KEY")
1716
CALENDAR_FILE = "./data/calendar.json"
1817

19-
# --- Outil 1 : Calculatrice Sécurisée ---
18+
# Outil 1 : Calculatrice Sécurisée
2019

2120
# Opérateurs autorisés pour l'évaluation sécurisée
2221
ALLOWED_OPERATORS = {
@@ -55,17 +54,22 @@ def calculate_financial_operation(expression: str) -> str:
5554
return safe_eval(expression)
5655

5756

58-
# --- Outil 2 : Recherche Web (Tavily) ---
57+
# Outil 2 : Recherche Web (Tavily)
5958

6059
# TavilySearchResults est déjà une classe Tool/Runnable
61-
web_search_tool = TavilySearch(
62-
name="recherche_web_actualites",
63-
description="Utilisez cet outil pour trouver des informations externes, des actualités financières récentes, ou des définitions qui ne sont pas dans les documents internes.",
64-
max_results=3
65-
)
60+
tavily_search_instance = TavilySearch(max_results=3)
61+
@tool
62+
def recherche_web_actualites(query: str) -> str:
63+
"""
64+
Utilisez cet outil pour trouver des informations externes...
65+
"""
66+
try:
67+
return tavily_search_instance.invoke(query)
68+
except Exception as e:
69+
return f"Erreur lors de la recherche web (Tavily): {e}"
6670

6771

68-
# --- Outil 3 : Météo (OpenWeatherMap) ---
72+
# Outil 3 : Météo (OpenWeatherMap)
6973

7074
@tool
7175
def get_weather_for_city(city: str) -> str:
@@ -92,7 +96,7 @@ def get_weather_for_city(city: str) -> str:
9296
return "Erreur de connexion à l'API météo. Veuillez réessayer."
9397

9498

95-
# --- Outil 4 : Calendrier / Todo List Locale ---
99+
# Outil 4 : Calendrier /
96100

97101
@tool
98102
def read_calendar(query: str) -> str:
@@ -122,12 +126,12 @@ def read_calendar(query: str) -> str:
122126
return f"Erreur lors de la lecture du calendrier: {e}"
123127

124128

125-
# --- Liste des Outils Exportée ---
129+
# Liste des Outils Exportée
126130

127131
# NOTE : La recherche web est ajoutée directement car elle est déjà une classe Tool
128132
EXTERNAL_TOOLS = [
129133
calculate_financial_operation,
130-
web_search_tool,
134+
recherche_web_actualites,
131135
get_weather_for_city,
132136
read_calendar
133137
]

0 commit comments

Comments
 (0)