File size: 992 Bytes
fa64206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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}")