rom langchain.chains import RAGChain from langchain.llms import HuggingFace from langchain.retrievers import BM25Retriever from langchain.prompts import PromptTemplate import yaml # Charger la configuration with open('config/config.yaml', 'r') as f: config = yaml.safe_load(f) # Configuration du modèle llm = HuggingFace("distilbert-base-uncased") # Configuration du retriever retriever = BM25Retriever.from_documents(["This is a great movie.", "I love this film."]) # Création du template de prompt template = PromptTemplate("Classify the sentiment of the following text: {text}") # Création de la chaîne RAG rag_chain = RAGChain(llm=llm, retriever=retriever, prompt_template=template) # Exemples de textes à classifier texts = ["This is a fantastic movie.", "I enjoy this movie."] # Utiliser RAG pour obtenir des classifications avec contexte for text in texts: result = rag_chain.run({"text": text}) print(f"Text: {text}, Result: {result}")