Skip to content

Commit 872ca8a

Browse files
fix(image-gen): wrap image response in SSE so OWU can display generated image
1 parent 851dc03 commit 872ca8a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

backend/privacy_proxy/app/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,12 @@ async def proxy(request: Request, path: str):
708708
headers=forward_headers,
709709
timeout=300.0
710710
)
711-
return Response(
712-
content=response.content,
713-
status_code=response.status_code,
714-
media_type="application/json"
715-
)
711+
if response.status_code != 200:
712+
return Response(content=response.content, status_code=response.status_code, media_type="application/json")
713+
img_url = response.json()["data"][0].get("url", "")
714+
content = f"![image]({img_url})"
715+
sse = f'data: {{"choices":[{{"delta":{{"role":"assistant","content":{json.dumps(content)}}},"index":0}}]}}\n\ndata: [DONE]\n\n'
716+
return StreamingResponse(iter([sse.encode()]), media_type="text/event-stream")
716717

717718
if is_chat and body and not is_openai:
718719
async with httpx.AsyncClient() as client:

0 commit comments

Comments
 (0)