Spaces:
Sleeping
Sleeping
Download evaluations/rag.py from jaothan/GenAI_project: direct link, hf CLI and curl.
- Browser
- Download file 992 Bytes
-
https://huggingface.co/spaces/jaothan/GenAI_project/resolve/main/evaluations/rag.py
- Command line
-
hf download hf://spaces/jaothan/GenAI_project/evaluations/rag.py
-
curl -L -o rag.py https://huggingface.co/spaces/jaothan/GenAI_project/resolve/main/evaluations/rag.py
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}") | |