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
{{ message }}
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
As of today to use FastAPI with DocList we need to cast the DocList into a python list manually like this
fromtypingimportListimportnumpyasnpfromfastapiimportFastAPIfromhttpximportAsyncClientfromdocarrayimportDocListfromdocarray.base_docimportDocArrayResponsefromdocarray.documentsimportTextDoc# Create a docarraydocs=DocList[TextDoc]([TextDoc(text='first'), TextDoc(text='second')])
app=FastAPI()
# Always use our custom response class (needed to dump tensors)@app.post("/doc/", response_class=DocArrayResponse)asyncdefcreate_embeddings(docs: List[TextDoc]) ->List[TextDoc]:
# The docs FastAPI will receive will be treated as List[TextDoc]# so you need to cast it to DocListdocs=DocList[TextDoc].construct(docs)
# Embed docsfordocindocs:
doc.embedding=np.zeros((3, 224, 224))
# Return your DocList as a listreturnlist(docs)
Objective
The objective is to be able to directly use DocList in the type hint
Activity
[-]Make DocList a real List[/-][+]FastAPI integration with DocList[/+]JoanFM commentedon Apr 27, 2023
@jupyterjazz I think we can already test that after merging #1457
JohannesMessner commentedon May 9, 2023
I looked into this, sending a taking a DocList as input works, returning one as an output does not. I am working on this now.
Update: Actually both sending and returning work, only the OpenAPI schema is messed up, see #1521
I would consider this issue to be resolved once:
JoanFM commentedon May 17, 2023
I will close this issue as duplicated of #1521