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
For a typical Streaming example, if the LitAPI.encode_response yields a dictionary or any non primitive dtype then server might run into error since FastAPI StreamingResponse doesn't accept dictionary.
Proposal: LitServe automatically detects and dumps a dictionary or Pydantic object into a JSON string value of the same so that FastAPI doesn't run into the following error.
During handling of the above exception, another exception occurred:
+ Exception Group Traceback (most recent call last):
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
| result = await app( # type: ignore[func-returns-value]
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
| return await self.app(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
| await super().__call__(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
| await self.middleware_stack(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
| raise exc
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
| await self.app(scope, receive, _send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
| await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
| raise exc
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
| await app(scope, receive, sender)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 756, in __call__
| await self.middleware_stack(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
| await route.handle(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
| await self.app(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
| await wrap_app_handling_exceptions(app, request)(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
| raise exc
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
| await app(scope, receive, sender)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/routing.py", line 75, in app
| await response(scope, receive, send)
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/responses.py", line 258, in __call__
| async with anyio.create_task_group() as task_group:
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__
| raise BaseExceptionGroup(
| exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/responses.py", line 261, in wrap
| await func()
| File "/home/zeus/miniconda3/envs/cloudspace/lib/python3.10/site-packages/starlette/responses.py", line 252, in stream_response
| chunk = chunk.encode(self.charset)
| AttributeError: 'dict' object has no attribute 'encode'
aniketmaurya
changed the title
automatically dump dictionary to json
automatically dump dictionary to json in encode_response while Streaming
May 11, 2024
For a typical Streaming example, if the
LitAPI.encode_response
yields a dictionary or any non primitive dtype then server might run into error since FastAPIStreamingResponse
doesn't accept dictionary.Proposal: LitServe automatically detects and dumps a dictionary or Pydantic object into a JSON string value of the same so that FastAPI doesn't run into the following error.
cc: @lantiga
The text was updated successfully, but these errors were encountered: