Spaces:
Sleeping
Sleeping
File size: 1,028 Bytes
7a4d005 | 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 31 32 | 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
|