Spaces:
Sleeping
Sleeping
Update rag_utils.py
Browse files- rag_utils.py +8 -5
rag_utils.py
CHANGED
@@ -1,9 +1,9 @@
|
|
|
|
1 |
import faiss
|
2 |
import pickle
|
3 |
import numpy as np
|
4 |
import re
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
-
from huggingface_hub import hf_hub_download
|
7 |
|
8 |
def load_faiss_index(index_path="faiss_index/faiss_index.faiss", doc_path="faiss_index/documents.pkl"):
|
9 |
index = faiss.read_index(index_path)
|
@@ -24,8 +24,6 @@ def nettoyer_context(context):
|
|
24 |
context = context.replace("None", "")
|
25 |
return context
|
26 |
|
27 |
-
|
28 |
-
|
29 |
import os
|
30 |
from huggingface_hub import InferenceClient
|
31 |
|
@@ -41,5 +39,10 @@ Formule ta réponse comme un conseiller d’orientation bienveillant, de manièr
|
|
41 |
Question : {question}
|
42 |
Réponse :"""
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
import faiss
|
3 |
import pickle
|
4 |
import numpy as np
|
5 |
import re
|
6 |
from sentence_transformers import SentenceTransformer
|
|
|
7 |
|
8 |
def load_faiss_index(index_path="faiss_index/faiss_index.faiss", doc_path="faiss_index/documents.pkl"):
|
9 |
index = faiss.read_index(index_path)
|
|
|
24 |
context = context.replace("None", "")
|
25 |
return context
|
26 |
|
|
|
|
|
27 |
import os
|
28 |
from huggingface_hub import InferenceClient
|
29 |
|
|
|
39 |
Question : {question}
|
40 |
Réponse :"""
|
41 |
|
42 |
+
try:
|
43 |
+
response = client.text_generation(prompt, max_new_tokens=300, timeout=30)
|
44 |
+
return response
|
45 |
+
except Exception as e:
|
46 |
+
print("Erreur Hugging Face API :", e)
|
47 |
+
return "😓 Le conseiller IA est temporairement indisponible. Merci de réessayer plus tard."
|
48 |
+
|