Skip to content

Commit ce09f93

Browse files
committed
typing
1 parent fceaada commit ce09f93

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

unstructured_platform_plugins/etl_uvicorn/api_generator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class InvokeResponse(BaseModel):
111111

112112
logging.getLogger("etl_uvicorn.fastapi")
113113

114-
async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> InvokeResponse:
114+
ResponseType = StreamingResponse if inspect.isasyncgenfunction(func) else InvokeResponse
115+
116+
async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> ResponseType:
115117
usage: list[UsageData] = []
116118
request_dict = kwargs if kwargs else {}
117119
if "usage" in inspect.signature(func).parameters:
@@ -144,7 +146,7 @@ async def _stream_response():
144146
if input_schema_model.model_fields:
145147

146148
@fastapi_app.post("/invoke", response_model=InvokeResponse)
147-
async def run_job(request: input_schema_model) -> InvokeResponse:
149+
async def run_job(request: input_schema_model) -> ResponseType:
148150
log_func_and_body(func=func, body=request.json())
149151
# Create dictionary from pydantic model while preserving underlying types
150152
request_dict = {f: getattr(request, f) for f in request.model_fields}
@@ -156,7 +158,7 @@ async def run_job(request: input_schema_model) -> InvokeResponse:
156158
else:
157159

158160
@fastapi_app.post("/invoke", response_model=InvokeResponse)
159-
async def run_job() -> InvokeResponse:
161+
async def run_job() -> ResponseType:
160162
log_func_and_body(func=func)
161163
return await wrap_fn(
162164
func=func,

0 commit comments

Comments
 (0)