Produit Minimal Viable #1
@@ -2,7 +2,7 @@ from langchain.tools import tool
|
||||
from langgraph.prebuilt import InjectedState
|
||||
from tavily import TavilyClient
|
||||
from pathlib import Path
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Annotated
|
||||
import sys
|
||||
from .StateElements.TodoElement import TodoElement
|
||||
|
||||
@@ -36,7 +36,7 @@ def write_file(file_path:str, content: str, append:bool=True) -> str:
|
||||
"""
|
||||
try:
|
||||
base_dir:str = Path(sys.argv[0]).resolve().parent.as_posix() # Récupérer le chemin vers le point d'entrée du programme
|
||||
file_path:str = base_dir + (file_path if file_path.startswith('/') else f'/{file_path}') # Puis générer le chemin vers le fichier
|
||||
full_path:str = base_dir + (file_path if file_path.startswith('/') else f'/{file_path}') # Puis générer le chemin vers le fichier
|
||||
|
||||
mode = "a" if append else "w" # Mode d'écriture
|
||||
with open(full_path, mode, encoding="utf-8") as f: # Puis j'écris
|
||||
@@ -90,6 +90,7 @@ def addTodo(name:str, description:str, state: Annotated[dict, InjectedState])->b
|
||||
if state["todo"] is None: state["todo"] = []
|
||||
|
||||
state["todo"].append(TodoElement(name, description))
|
||||
return True
|
||||
|
||||
@tool
|
||||
def removeTodo(index:int, state: Annotated[dict, InjectedState])->bool:
|
||||
@@ -122,9 +123,9 @@ def read_file(file_path: str) -> str:
|
||||
"""
|
||||
try:
|
||||
base_dir:str = Path(sys.argv[0]).resolve().parent.as_posix() # Récupérer le chemin vers le point d'entrée du programme
|
||||
file_path:str = base_dir + (file_path if file_path.startswith('/') else f'/{file_path}') # Puis générer le chemin vers le fichier
|
||||
full_path:str = base_dir + (file_path if file_path.startswith('/') else f'/{file_path}') # Puis générer le chemin vers le fichier
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
with open(full_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
return content
|
||||
@@ -156,7 +157,7 @@ def ask_human(request:str)->str:
|
||||
return user_response
|
||||
|
||||
@tool
|
||||
def search_in_files(query:str, state: Annotated[dict, InjectedState])->List[str]:
|
||||
def search_in_files(query:str, state: Annotated[dict, InjectedState])->str:
|
||||
"""
|
||||
Rechercher quelque chose dans les documents enregistrés localement.
|
||||
Dans le cas actuel, ces documents sont des rapports hebdomadaires de stage.
|
||||
@@ -165,11 +166,11 @@ def search_in_files(query:str, state: Annotated[dict, InjectedState])->List[str]
|
||||
query (str): La requête recherchée.
|
||||
|
||||
Returns:
|
||||
List[str]: Échantillons de documents correspondants.
|
||||
str: Échantillons de documents correspondants, concaténés en une seule chaîne de caractères.
|
||||
"""
|
||||
bdd = VectorDatabase() # Récupère l'unique instance de cette BDD, c'est un SIngleton
|
||||
|
||||
retrieved_docs = bdd.getChroma().similarity_search(prompt, k=5) # 5 documents
|
||||
retrieved_docs = bdd.getChroma().similarity_search(query, k=5) # 5 documents
|
||||
|
||||
# Conversion des documents en texte
|
||||
docs_content = "\n".join(
|
||||
@@ -178,7 +179,7 @@ def search_in_files(query:str, state: Annotated[dict, InjectedState])->List[str]
|
||||
|
||||
# Sauvegarde des données dans le State
|
||||
state["ragQuery"] = query
|
||||
state["ragDocuments"] = docs_content
|
||||
state["ragDocuments"] = retrieved_docs
|
||||
|
||||
return docs_content # Retourne la liste de documents trouvés
|
||||
|
||||
|
||||
Reference in New Issue
Block a user