langserve icon indicating copy to clipboard operation
langserve copied to clipboard

modify request body using pydantic BaseModel

Open restuprajna opened this issue 1 year ago • 0 comments
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)

restuprajna avatar May 06 '24 09:05 restuprajna