jaothan's picture
Upload 24 files
fa64206 verified
raw
history blame
992 Bytes
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}")