Spaces:
Sleeping
Sleeping
Download graph/chains/hallucination_grader.py from mikail-bitik/CorrectiveRAGProject: direct link, hf CLI and curl.
- Browser
- Download file 993 Bytes
-
https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/chains/hallucination_grader.py
- Command line
-
hf download hf://spaces/mikail-bitik/CorrectiveRAGProject/graph/chains/hallucination_grader.py
-
curl -L -o hallucination_grader.py https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/chains/hallucination_grader.py
993 Bytes
| from langchain_deepseek import ChatDeepSeek | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from pydantic import BaseModel, Field | |
| llm = ChatDeepSeek(model="deepseek-chat", temperature=0) | |
| class GradeHallucinations(BaseModel): | |
| """Binary score for hallucination present in generated answer.""" | |
| binary_score: bool = Field( | |
| description="Answer is grounded in the facts, 'yes' or 'no'", | |
| ) | |
| structured_llm_grader = llm.with_structured_output(GradeHallucinations) | |
| system_prompt = """ | |
| You are a grader assessing whether an LLM generation is grounded in / supported by a set of retrieved facts. \n | |
| Give a binary score 'yes' or 'no'. 'Yes' means that the answer is grounded in / supported by the set of facts | |
| """ | |
| hallucination_prompt = ChatPromptTemplate.from_messages( | |
| [ | |
| ("system", system_prompt), | |
| ("human", "Set of facts: \n\n {documents} \n\n LLM generation: {generation}") | |
| ] | |
| ) | |
| hallucination_grader = hallucination_prompt | structured_llm_grader |