Programmes commited on
Commit
ba275b2
·
verified ·
1 Parent(s): 226ba19

Update rag_utils.py

Browse files
Files changed (1) hide show
  1. rag_utils.py +8 -3
rag_utils.py CHANGED
@@ -3,6 +3,7 @@ import pickle
3
  import numpy as np
4
  import re
5
  from sentence_transformers import SentenceTransformer
 
6
  from llama_cpp import Llama
7
 
8
  def load_faiss_index(index_path="faiss_index/faiss_index.faiss", doc_path="faiss_index/documents.pkl"):
@@ -25,14 +26,19 @@ def nettoyer_context(context):
25
  return context
26
 
27
  def generate_answer(question, context):
 
 
 
 
 
28
  llm = Llama(
29
- model_path="./mistral-7b-instruct-v0.1.Q4_K_M.gguf",
30
  n_ctx=2048,
31
  n_threads=6,
32
  verbose=False
33
  )
34
 
35
- prompt = f""":
36
 
37
  {context}
38
 
@@ -43,4 +49,3 @@ Réponse :
43
 
44
  output = llm(prompt, max_tokens=256, stop=["</s>"])
45
  return output["choices"][0]["text"].strip()
46
-
 
3
  import numpy as np
4
  import re
5
  from sentence_transformers import SentenceTransformer
6
+ from huggingface_hub import hf_hub_download
7
  from llama_cpp import Llama
8
 
9
  def load_faiss_index(index_path="faiss_index/faiss_index.faiss", doc_path="faiss_index/documents.pkl"):
 
26
  return context
27
 
28
  def generate_answer(question, context):
29
+ model_file = hf_hub_download(
30
+ repo_id="TheBloke/Mistral-7B-Instruct-v0.1-GGUF",
31
+ filename="mistral-7b-instruct-v0.1.Q4_K_M.gguf"
32
+ )
33
+
34
  llm = Llama(
35
+ model_path=model_file,
36
  n_ctx=2048,
37
  n_threads=6,
38
  verbose=False
39
  )
40
 
41
+ prompt = f"""Voici des informations sur des établissements et formations :
42
 
43
  {context}
44
 
 
49
 
50
  output = llm(prompt, max_tokens=256, stop=["</s>"])
51
  return output["choices"][0]["text"].strip()