Spaces:
Sleeping
Sleeping
Download graph/chains/router.py from mikail-bitik/CorrectiveRAGProject: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/chains/router.py
- Command line
-
hf download hf://spaces/mikail-bitik/CorrectiveRAGProject/graph/chains/router.py
-
curl -L -o router.py https://huggingface.co/spaces/mikail-bitik/CorrectiveRAGProject/resolve/main/graph/chains/router.py
1.03 kB
| from langchain_deepseek import ChatDeepSeek | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from pydantic import BaseModel, Field | |
| from typing import Literal | |
| class RouteQuery(BaseModel): | |
| """ | |
| Route a user query to the most relevant datasource | |
| """ | |
| datasource: Literal["vectorstore","websearch"] = Field( | |
| ..., | |
| description="Given a user question choose to route it to websearch or a vectorstore" | |
| ) | |
| llm = ChatDeepSeek(model="deepseek-chat", temperature=0) | |
| structured_llm_router = llm.with_structured_output(RouteQuery) | |
| system_prompt = """ You are an expert at routing a user question to a vectorstore or web search.\n | |
| The vectorstore contains documents related to agents, prompt engineering and adversarial attacks.\ | |
| Use the vectorstore for questions on these topics. For all else, use websearch.""" | |
| route_prompt = ChatPromptTemplate.from_messages( | |
| [ | |
| ("system", system_prompt), | |
| ("human", "{question}") | |
| ] | |
| ) | |
| question_router = route_prompt | structured_llm_router | |