langserve
langserve copied to clipboard
modify request body using pydantic BaseModel
trafficstars
I want to modify request body to send to the model, is there a way to use pydantic to modify input_type
for example this is the default req body:
{
"inputs": [
"string"
],
"config": {},
"kwargs": {}
}
i want to change like this:
{
"inputs": [
"string"
],
"config": {},
"kwargs": {},
"metadata":["string"]
}
because i want to get the value inside the metadata for filtering rag document.
here are my chain
chain = (
{"context": retriever | RunnablePassthrough(), "task": RunnablePassthrough()}
| pipeline_prompt
| llm
| parser
)
class InputPrompt(BaseModel):
__root__: str
chain = chain.with_types(input_type=InputPrompt)
and I'm using APIHandler to make batch and invoke method:
async def batch_api(api_chain, path: str, request: Request) -> Response:
"""
Handle a request for the specified API.
"""
api_handler = APIHandler(api_chain, path=path)
return await api_handler.batch(request, server_config=langfuse_config)