Skip to content

Commit e0a53c3

Browse files
jrobertboosasimurka
authored andcommitted
fix
1 parent f8adfee commit e0a53c3

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/pydantic_ai_lightspeed/llamastack/_transport.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from llama_stack.core.server.routes import find_matching_route
1919
from llama_stack.core.utils.context import preserve_contexts_async_generator
20+
from starlette.responses import StreamingResponse
2021

2122

2223
class _AsyncByteStream(httpx.AsyncByteStream):
@@ -183,9 +184,16 @@ async def _handle_streaming(
183184
result = await func(**merged_body)
184185

185186
async def gen() -> AsyncGenerator[bytes, None]:
186-
async for chunk in result:
187-
data = json.dumps(convert_pydantic_to_json_value(chunk))
188-
yield f"data: {data}\n\n".encode("utf-8")
187+
if isinstance(result, StreamingResponse):
188+
async for chunk in result.body_iterator:
189+
if isinstance(chunk, str):
190+
yield chunk.encode("utf-8")
191+
else:
192+
yield bytes(chunk)
193+
else:
194+
async for chunk in result:
195+
data = json.dumps(convert_pydantic_to_json_value(chunk))
196+
yield f"data: {data}\n\n".encode("utf-8")
189197

190198
wrapped_gen = preserve_contexts_async_generator(gen(), [PROVIDER_DATA_VAR])
191199

0 commit comments

Comments
 (0)