Prechádzať zdrojové kódy

assistant ai version 1

Nadine Elleuch 1 rok pred
rodič
commit
3e9163e2f9
1 zmenil súbory, kde vykonal 4 pridanie a 3 odobranie
  1. 4 3
      app.py

+ 4 - 3
app.py

@@ -7,7 +7,7 @@ from sentence_transformers import CrossEncoder, SentenceTransformer
 from langchain_ollama import OllamaLLM
 from agent_ai.auth import login_to_wiki
 from agent_ai.scraping import fetch_all_pages_content
-from agent_ai.chunking import semantic_chunking, model, chunk_text, chunk_text_generic
+from agent_ai.chunking import semantic_chunking, model
 from agent_ai.embedding_index import build_faiss_index, search_faiss
 from agent_ai.qa_chain import get_qa_chain
 from tabulate import tabulate
@@ -208,9 +208,10 @@ def qa_chain_route():
     question = data.get("question", "")
 
     top_chunks = [
-        f"[Source: {state['chunk_urls'][i] if i < len(state['chunk_urls']) else 'URL inconnue'}]\n{state['all_chunks'][i]}"
+        # Pour chaque indice 'i' dans la liste 'last_indices' (indices des meilleurs chunks)
+        f"[Source: {state['chunk_urls'][i] if i < len(state['chunk_urls']) else 'URL inconnue'}]\n{state['all_chunks'][i]}" # On récupère l'URL correspondante à cet indice si elle existe, sinon on met 'URL inconnue' Puis on ajoute le texte complet du chunk correspondant
         for i in state.get("last_indices", [])
-        if i < len(state["all_chunks"])
+        if i < len(state["all_chunks"]) # On s'assure que l'indice est valide pour éviter les erreurs d'index hors limites
     ]
     top_context = "\n\n".join(top_chunks)