docs: fastapi integration section#1326
Merged
jupyterjazz merged 6 commits intofeat-rewrite-v2from Apr 12, 2023
Merged
Conversation
Signed-off-by: jupyterjazz <[email protected]>
Member
|
lets just do FastAPI in a first time, we can do the other one in other PR |
Signed-off-by: jupyterjazz <[email protected]>
samsja
reviewed
Apr 3, 2023
docs/integrations/fastapi.md
Outdated
| @@ -0,0 +1,125 @@ | |||
| # Use Docarray with FastAPI | |||
|
|
|||
| You might already know that `DocArray` documents are Pydantic Models (with a twist) [Reference relevant part], and as such they are fully compatible with `FastAPI`: | |||
Member
There was a problem hiding this comment.
I think we need more introduction to what is FastAPI etccc
samsja
reviewed
Apr 3, 2023
docs/integrations/fastapi.md
Outdated
Comment on lines
+5
to
+43
| ```python | ||
| import numpy as np | ||
| from fastapi import FastAPI | ||
| from httpx import AsyncClient | ||
|
|
||
| from docarray import BaseDoc | ||
| from docarray.documents import ImageDoc | ||
| from docarray.typing import NdArray | ||
| from docarray.base_doc import DocumentResponse | ||
|
|
||
|
|
||
| class InputDoc(BaseDoc): | ||
| img: ImageDoc | ||
|
|
||
|
|
||
| class OutputDoc(BaseDoc): | ||
| embedding_clip: NdArray | ||
| embedding_bert: NdArray | ||
|
|
||
|
|
||
| input_doc = InputDoc(img=ImageDoc(tensor=np.zeros((3, 224, 224)))) | ||
|
|
||
| app = FastAPI() | ||
|
|
||
|
|
||
| @app.post("/doc/", response_model=OutputDoc, response_class=DocumentResponse) | ||
| async def create_item(doc: InputDoc) -> OutputDoc: | ||
| ## call my fancy model to generate the embeddings | ||
| doc = OutputDoc( | ||
| embedding_clip=np.zeros((100, 1)), embedding_bert=np.zeros((100, 1)) | ||
| ) | ||
| return doc | ||
|
|
||
|
|
||
| async with AsyncClient(app=app, base_url="http://test") as ac: | ||
| response = await ac.post("/doc/", data=input_doc.json()) | ||
|
|
||
| doc = OutputDoc.parse_raw(response.content.decode()) | ||
| ``` |
Member
There was a problem hiding this comment.
we need to break down this part in two. First schema creation then FastAPI app instatiation
samsja
reviewed
Apr 3, 2023
docs/integrations/fastapi.md
Outdated
Comment on lines
+82
to
+85
| > **Note** | ||
| > Currently, `FastAPI` receives `DocArray` objects as lists, so you have to construct a DocArray inside the function. | ||
| > Also, if you want to return a `DocArray` object, first you have to convert it to a list. | ||
| > (Shown in the example below) |
Member
There was a problem hiding this comment.
you can check the install documentaiton but to do note you need to do
!! note
smth
Signed-off-by: jupyterjazz <[email protected]>
Signed-off-by: jupyterjazz <[email protected]>
Signed-off-by: Saba Sturua <[email protected]>
|
📝 Docs are deployed on https://ft-docs-fastapi-integration--jina-docs.netlify.app 🎉 |
samsja
approved these changes
Apr 12, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Define an "Integrations" section describing Docarray integration with FastAPI
https://ft-docs-fastapi-integration--jina-docs.netlify.app/