From ee77d13df3dad56c4cb4d0425114187a6bfe9a5c Mon Sep 17 00:00:00 2001 From: nareka Date: Wed, 25 Oct 2023 10:05:32 -0700 Subject: [PATCH] fix: fix get and post endpoints --- jina/clients/base/helper.py | 2 +- .../gateway/http_fastapi_app_docarrayv2.py | 14 ++++---------- jina/serve/runtimes/worker/http_fastapi_app.py | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/jina/clients/base/helper.py b/jina/clients/base/helper.py index d3b76dc014e72..e6ba065544227 100644 --- a/jina/clients/base/helper.py +++ b/jina/clients/base/helper.py @@ -203,7 +203,7 @@ async def send_streaming_message(self, doc: 'Document', on: str): 'json': doc.dict() if docarray_v2 else doc.to_dict(), } - async with self.session.post(**request_kwargs) as response: + async with self.session.get(**request_kwargs) as response: async for chunk in response.content.iter_any(): events = chunk.split(b'event: ')[1:] for event in events: diff --git a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py index 817a20b1fff9a..3835918f3fedb 100644 --- a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py +++ b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py @@ -181,7 +181,7 @@ def add_post_route( ): app_kwargs = dict( path=f'/{endpoint_path.strip("/")}', - methods=['GET'], + methods=['POST'], summary=f'Endpoint {endpoint_path}', response_model=output_model, ) @@ -249,7 +249,7 @@ def add_streaming_routes( @app.api_route( path=f'/{endpoint_path.strip("/")}', - methods=['POST'], + methods=['GET', 'POST'], summary=f'Streaming Endpoint {endpoint_path}', tags=["streaming"], ) @@ -264,13 +264,8 @@ async def event_generator(): ): if error: raise HTTPException(status_code=499, detail=str(error)) - yield { - 'event': 'update', - 'data': doc.dict() - } - yield { - 'event': 'end' - } + yield {'event': 'update', 'data': doc.dict()} + yield {'event': 'end'} return EventSourceResponse(event_generator()) @@ -280,7 +275,6 @@ async def event_generator(): summary=f'Streaming Endpoint {endpoint_path}', ) async def streaming_post(body: dict): - async def event_generator(): async for doc, error in streamer.stream_doc( doc=input_doc_model.parse_obj(body), exec_endpoint=endpoint_path diff --git a/jina/serve/runtimes/worker/http_fastapi_app.py b/jina/serve/runtimes/worker/http_fastapi_app.py index f692add6a0070..3e2bd3b5a74b8 100644 --- a/jina/serve/runtimes/worker/http_fastapi_app.py +++ b/jina/serve/runtimes/worker/http_fastapi_app.py @@ -133,7 +133,7 @@ def add_streaming_routes( @app.api_route( path=f'/{endpoint_path.strip("/")}', - methods=['GET'], + methods=['GET', 'POST'], summary=f'Streaming Endpoint {endpoint_path}', tags=["streaming"], )