vinimoreira commited on
Commit
bd4d787
·
verified ·
1 Parent(s): bcbc37c

update rag_chain

Browse files
Files changed (1) hide show
  1. api/rag_chain.py +2 -19
api/rag_chain.py CHANGED
@@ -5,13 +5,13 @@ from pathlib import Path
5
  from dotenv import load_dotenv
6
  from operator import itemgetter
7
  from typing import List, Dict
8
-
9
  from langchain_core.runnables import RunnableParallel, RunnablePassthrough, RunnableLambda
10
  from langchain_core.prompts import PromptTemplate
11
  from langchain_community.vectorstores import FAISS
12
  from langchain_huggingface import HuggingFaceEmbeddings
13
  from huggingface_hub import InferenceClient
14
  from src.retrieval.reranker import HybridReranker
 
15
 
16
  load_dotenv()
17
 
@@ -25,25 +25,8 @@ if not HF_TOKEN:
25
  raise ValueError("token api not found")
26
 
27
  client = InferenceClient(model=LLM_REPO_ID, token=HF_TOKEN)
28
- prompt_template = PromptTemplate.from_template("""[INST]
29
- Sua tarefa é agir como um assistente de helpdesk de TI objetivo e técnico. Você deve responder à pergunta do usuário usando estritamente as informações contidas na seção <CONTEXTO>.
30
-
31
- **REGRAS ABSOLUTAS:**
32
- 1. Responda SEMPRE em Português do Brasil.
33
- 2. NUNCA mencione a palavra "contexto" ou "fonte" na sua resposta. Apenas use a informação.
34
- 3. NUNCA repita a pergunta do usuário. Gere apenas a resposta direta para a pergunta.
35
- 4. Se a informação não estiver no contexto, responda EXATAMENTE com a frase: "Não encontrei informações sobre isso na minha base de dados."
36
- 5. Baseie-se 100% no texto dentro de <CONTEXTO>. Não adicione nenhuma informação externa.
37
-
38
- <CONTEXTO>
39
- {context}
40
- </CONTEXTO>
41
 
42
- <PERGUNTA>
43
- {query}
44
- </PERGUNTA>
45
- [/INST]
46
- """)
47
 
48
  def format_docs(docs: List[Dict]) -> str:
49
  return "\n\n".join(doc.page_content for doc in docs)
 
5
  from dotenv import load_dotenv
6
  from operator import itemgetter
7
  from typing import List, Dict
 
8
  from langchain_core.runnables import RunnableParallel, RunnablePassthrough, RunnableLambda
9
  from langchain_core.prompts import PromptTemplate
10
  from langchain_community.vectorstores import FAISS
11
  from langchain_huggingface import HuggingFaceEmbeddings
12
  from huggingface_hub import InferenceClient
13
  from src.retrieval.reranker import HybridReranker
14
+ from src.generation.prompt_templates import RAG_PROMPT_TEMPLATE
15
 
16
  load_dotenv()
17
 
 
25
  raise ValueError("token api not found")
26
 
27
  client = InferenceClient(model=LLM_REPO_ID, token=HF_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ prompt_template = PromptTemplate.from_template(RAG_PROMPT_TEMPLATE)
 
 
 
 
30
 
31
  def format_docs(docs: List[Dict]) -> str:
32
  return "\n\n".join(doc.page_content for doc in docs)