summaryrefslogtreecommitdiffstats
path: root/g4f/api/__init__.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2024-11-15 11:18:56 +0100
committerGitHub <noreply@github.com>2024-11-15 11:18:56 +0100
commitf65ebd98518bc42bd83a9205f3eab9cb06de566a (patch)
tree82ceabb9503acd0e1301b6eb7e20493cc18f3672 /g4f/api/__init__.py
parentFIX: fix the url in the markdown output (md compliance), and the chunk/ImageResponse to str ! (#2353) (diff)
parentquick fix for Conflicts (diff)
downloadgpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar.gz
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar.bz2
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar.lz
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar.xz
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.tar.zst
gpt4free-f65ebd98518bc42bd83a9205f3eab9cb06de566a.zip
Diffstat (limited to 'g4f/api/__init__.py')
-rw-r--r--g4f/api/__init__.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py
index 3e29c5f8..e7f87260 100644
--- a/g4f/api/__init__.py
+++ b/g4f/api/__init__.py
@@ -195,9 +195,13 @@ class Api:
return JSONResponse(response_list[0].to_json())
# Streaming response
+ async def async_generator(sync_gen):
+ for item in sync_gen:
+ yield item
+
async def streaming():
try:
- async for chunk in response:
+ async for chunk in async_generator(response):
yield f"data: {json.dumps(chunk.to_json())}\n\n"
except GeneratorExit:
pass
@@ -221,7 +225,7 @@ class Api:
response_format=config.response_format
)
# Convert Image objects to dictionaries
- response_data = [image.to_dict() for image in response.data]
+ response_data = [{"url": image.url, "b64_json": image.b64_json} for image in response.data]
return JSONResponse({"data": response_data})
except Exception as e:
logger.exception(e)