Closed yousefmrashad closed 4 months ago
Solution:
@app.get("/stream_response_and_sources")
async def stream_response_and_sources(user_prompt: str,
chat_summary: str,
chat: str,
book_ids: Annotated[list[str] | None, Query()],
enable_web_retrieval:bool = True):
# Initialize RAG pipeline
Source: https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#__tabbed_15_1
I am encountering an issue with FastAPI where I receive a 422 Unprocessable Entity error when passing a list parameter (
book_ids
) to an endpoint function. Despite correctly typing the parameter asList[str]
in the function signature, and ensuring that it does not accept a default value ofNone
, the error persists when I provide a list of values.Steps to Reproduce:
book_ids: List[str]
).None
.Expected Behavior: The FastAPI endpoint should be able to parse and handle list parameters without encountering a 422 error, as long as the parameter is correctly typed.
Endpoint
Test