qa_chain.py 691 B

1234567891011121314151617181920212223242526272829303132
  1. from langchain_ollama import OllamaLLM
  2. from langchain.prompts import PromptTemplate
  3. from langchain.chains import LLMChain
  4. prompt_template = PromptTemplate(
  5. input_variables=["context", "question"],
  6. template="""
  7. Tu es un assistant francophone très rigoureux. Tu ne dois **répondre qu’à partir du contexte fourni** ci-dessous.
  8. Contexte :
  9. {context}
  10. Question :
  11. {question}
  12. Si la réponse ne peut pas être déduite **mot pour mot** du contexte, dis : "Je ne sais pas."
  13. Réponse :
  14. """
  15. )
  16. def get_qa_chain():
  17. llm = OllamaLLM(
  18. model="llama3",
  19. temperature=0.7,
  20. top_p=0.9,
  21. max_tokens=256
  22. )
  23. return LLMChain(llm=llm, prompt=prompt_template)