-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use body for streaming instead of params #6098
Merged
Merged
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
94348f6
fix: add post endpoint for streaming
NarekA b645afb
test: stream complex docs
NarekA 72037b5
docs: include docstring for issue test
NarekA 99cdd7d
Merge branch 'master' into fix-streaming-6091
NarekA cc315c9
Merge branch 'master' into fix-streaming-6091
NarekA 8bc5124
fix: use random port
NarekA 804b665
fix: remove import
NarekA 3ce6e1e
fix: simplify client code
NarekA a5376af
fix: use json field
NarekA 025413f
fix: use to_dict for docarray v1
NarekA 60c9b5e
docs: add docs about http get
NarekA 03cc4c4
fix: typo in deployment
NarekA b89c01a
fix: don't use body.data
NarekA cf2f145
fix: do unpack body
NarekA fd30b0e
fix: docarray v2 cast model
NarekA f1f9a88
fix: change start time delay
NarekA 3aa6534
Revert "fix: change start time delay"
NarekA 57af50a
fix: use get only
NarekA 5f27f0a
Merge remote-tracking branch 'origin/master' into fix-streaming-2-6091
NarekA a72a797
fix: delay test
NarekA ee77d13
fix: fix get and post endpoints
NarekA 524aba4
fix: remove post
NarekA 5cfb423
fix: remove endpoint tags
NarekA 3d1b07f
Merge branch 'master' into fix-streaming-2-6091
NarekA ca3a707
test: use get with url params
NarekA 92405db
docs: fix docs on streaming endpoints
NarekA 2c626bf
test: increase tolerance
NarekA 38a577b
fix: iteration over chunks
NarekA c4afd99
fix: gateway forwarding
NarekA c654c14
fix: pre-commit changes
NarekA bb90d14
fix: don't check for docarray_v2
NarekA 08bfd6b
fix: remove type-hint
NarekA 3eff072
fix: update test output
NarekA 46af5fa
fix: adding payload
NarekA bf3cbe2
fix: use json payload
NarekA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import inspect | ||
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union | ||
|
||
from jina import DocumentArray, Document | ||
from jina import Document, DocumentArray | ||
from jina._docarray import docarray_v2 | ||
from jina.importer import ImportExtensions | ||
from jina.serve.networking.sse import EventSourceResponse | ||
|
@@ -11,15 +11,15 @@ | |
from jina.logging.logger import JinaLogger | ||
|
||
if docarray_v2: | ||
from docarray import DocList, BaseDoc | ||
from docarray import BaseDoc, DocList | ||
|
||
|
||
def get_fastapi_app( | ||
request_models_map: Dict, | ||
caller: Callable, | ||
logger: 'JinaLogger', | ||
cors: bool = False, | ||
**kwargs, | ||
request_models_map: Dict, | ||
caller: Callable, | ||
logger: 'JinaLogger', | ||
cors: bool = False, | ||
**kwargs, | ||
): | ||
""" | ||
Get the app from FastAPI as the REST interface. | ||
|
@@ -35,15 +35,18 @@ | |
from fastapi import FastAPI, Response, HTTPException | ||
import pydantic | ||
from fastapi.middleware.cors import CORSMiddleware | ||
import os | ||
|
||
from pydantic import BaseModel, Field | ||
from pydantic.config import BaseConfig, inherit_config | ||
|
||
from jina.proto import jina_pb2 | ||
from jina.serve.runtimes.gateway.models import _to_camel_case | ||
import os | ||
|
||
class Header(BaseModel): | ||
request_id: Optional[str] = Field(description='Request ID', example=os.urandom(16).hex()) | ||
request_id: Optional[str] = Field( | ||
description='Request ID', example=os.urandom(16).hex() | ||
) | ||
|
||
class Config(BaseConfig): | ||
alias_generator = _to_camel_case | ||
|
@@ -66,11 +69,11 @@ | |
logger.warning('CORS is enabled. This service is accessible from any website!') | ||
|
||
def add_post_route( | ||
endpoint_path, | ||
input_model, | ||
output_model, | ||
input_doc_list_model=None, | ||
output_doc_list_model=None, | ||
endpoint_path, | ||
input_model, | ||
output_model, | ||
input_doc_list_model=None, | ||
output_doc_list_model=None, | ||
): | ||
app_kwargs = dict( | ||
path=f'/{endpoint_path.strip("/")}', | ||
|
@@ -123,8 +126,8 @@ | |
return ret | ||
|
||
def add_streaming_routes( | ||
endpoint_path, | ||
input_doc_model=None, | ||
endpoint_path, | ||
input_doc_model=None, | ||
): | ||
from fastapi import Request | ||
|
||
|
@@ -133,26 +136,14 @@ | |
methods=['GET'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following code works, but I did not allow get since it doesn't work with gateway deployments. methods=['GET', 'POST'], |
||
summary=f'Streaming Endpoint {endpoint_path}', | ||
) | ||
async def streaming_get(request: Request): | ||
query_params = dict(request.query_params) | ||
req = DataRequest() | ||
req.header.exec_endpoint = endpoint_path | ||
if not docarray_v2: | ||
req.data.docs = DocumentArray([Document.from_dict(query_params)]) | ||
else: | ||
req.document_array_cls = DocList[input_doc_model] | ||
req.data.docs = DocList[input_doc_model]( | ||
[input_doc_model(**query_params)] | ||
async def streaming_get(request: Request, body: input_doc_model = None): | ||
if not body: | ||
query_params = dict(request.query_params) | ||
body = ( | ||
input_doc_model.parse_obj(query_params) | ||
if docarray_v2 | ||
else Document.from_dict(query_params) | ||
) | ||
event_generator = _gen_dict_documents(await caller(req)) | ||
return EventSourceResponse(event_generator) | ||
|
||
@app.api_route( | ||
path=f'/{endpoint_path.strip("/")}', | ||
methods=['POST'], | ||
summary=f'Streaming Endpoint {endpoint_path}', | ||
) | ||
async def streaming_post(body: input_doc_model, request: Request): | ||
req = DataRequest() | ||
req.header.exec_endpoint = endpoint_path | ||
if not docarray_v2: | ||
|
@@ -169,7 +160,9 @@ | |
output_doc_model = input_output_map['output']['model'] | ||
is_generator = input_output_map['is_generator'] | ||
parameters_model = input_output_map['parameters']['model'] or Optional[Dict] | ||
default_parameters = ... if input_output_map['parameters']['model'] else None | ||
default_parameters = ( | ||
... if input_output_map['parameters']['model'] else None | ||
) | ||
|
||
if docarray_v2: | ||
_config = inherit_config(InnerConfig, BaseDoc.__config__) | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can
and request.method == 'GET'
to the condition here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may not need
POST
at all then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the current state of this PR, and it fixes everything. Can't tell if tests need to be re-run or if they're actually failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can see a test failing here https://github.com/jina-ai/jina/actions/runs/6647328275/job/18084538375?pr=6098
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed that issue, I think the current failures just need re-runs, can you take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, found one that's not flakyness