You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the way we send/receive DocArray objects with FastAPI.
Context
Currently, DocArray objects are received as lists, so we have to construct an actual DocArray inside the function, and in case of returning, we have to convert it into a list ourselves (done in #1320)
@app.post("/doc/", response_class=DocArrayResponse)asyncdeffunc(fastapi_docs: List[ImageDoc]) ->List[ImageDoc]:
# The docs FastAPI will receive will be treated as List[ImageDoc]# so you need to cast it to DocArraydocarray_docs=DocArray[ImageDoc].construct(fastapi_docs)
...
# In case you want to return a DocArray, return it as a listreturnlist(docarray_docs)
What we want
The goal is to receive/return DocArray objects without any additional operations from the developer side.
Improve the way we send/receive DocArray objects with FastAPI.
Context
Currently, DocArray objects are received as lists, so we have to construct an actual DocArray inside the function, and in case of returning, we have to convert it into a list ourselves (done in #1320)
What we want
The goal is to receive/return DocArray objects without any additional operations from the developer side.
Ways to do it
I've investigated couple of approaches, and here are the most plausible ones and the main problem I had with them:
FastAPI still received DocArray as a List. If we fix that, this is the best way to go
GenericModel does type-checking during runtime which introduces lots of circular imports
BaseModel introduced couple of functions that were in conflict with our existing ones
In general, extending pydantic's classes was a bit of a headache, the first option is much cleaner.