summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorkqlio67 <kqlio67@users.noreply.github.com>2024-11-12 07:44:48 +0100
committerkqlio67 <kqlio67@users.noreply.github.com>2024-11-12 07:44:48 +0100
commit21a26f68826778afa7ab932ef4cd488b422fdc68 (patch)
treebaac655d7744f9c872a7968ac94583297fa4bc10 /g4f
parentUpdate (g4f/Provider/GizAI.py) (diff)
downloadgpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar.gz
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar.bz2
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar.lz
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar.xz
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.tar.zst
gpt4free-21a26f68826778afa7ab932ef4cd488b422fdc68.zip
Diffstat (limited to 'g4f')
-rw-r--r--g4f/client/client.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/g4f/client/client.py b/g4f/client/client.py
index 8e195213..63358302 100644
--- a/g4f/client/client.py
+++ b/g4f/client/client.py
@@ -154,14 +154,29 @@ class AsyncClient(Client):
stacklevel=2
)
super().__init__(*args, **kwargs)
+ self.chat = Chat(self)
+ self._images = Images(self)
+ self.completions = Completions(self)
- async def chat_complete(self, *args, **kwargs):
- """Legacy method that redirects to async_create"""
- return await self.chat.completions.async_create(*args, **kwargs)
+ @property
+ def images(self) -> 'Images':
+ return self._images
+
+ async def async_create(self, *args, **kwargs) -> Union['ChatCompletion', AsyncIterator['ChatCompletionChunk']]:
+ response = await super().async_create(*args, **kwargs)
+ async for result in response:
+ return result
- async def create_image(self, *args, **kwargs):
- """Legacy method that redirects to async_generate"""
- return await self.images.async_generate(*args, **kwargs)
+ async def async_generate(self, *args, **kwargs) -> 'ImagesResponse':
+ return await super().async_generate(*args, **kwargs)
+
+ async def _fetch_image(self, url: str) -> bytes:
+ async with ClientSession() as session:
+ async with session.get(url) as resp:
+ if resp.status == 200:
+ return await resp.read()
+ else:
+ raise Exception(f"Failed to fetch image from {url}, status code {resp.status}")
class Completions:
def __init__(self, client: Client, provider: ProviderType = None):
@@ -531,4 +546,3 @@ class Images:
async def create_variation(self, image: Union[str, bytes], model: str = None, response_format: str = "url", **kwargs):
# Existing implementation, adjust if you want to support b64_json here as well
pass
-