diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-13 13:30:44 +0100 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-13 13:30:44 +0100 |
commit | 17057742ac3729f5a5bd551c84b7a03212c61a40 (patch) | |
tree | c3e28d8a93dd97e1df8cc3c054135633bec891d2 /g4f/client/client.py | |
parent | Update (g4f/Provider/Blackbox.py) (diff) | |
download | gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar.gz gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar.bz2 gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar.lz gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar.xz gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.tar.zst gpt4free-17057742ac3729f5a5bd551c84b7a03212c61a40.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/client/client.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/g4f/client/client.py b/g4f/client/client.py index 63358302..73d8fea3 100644 --- a/g4f/client/client.py +++ b/g4f/client/client.py @@ -144,39 +144,32 @@ class Client(BaseClient): class AsyncClient(Client): """Legacy AsyncClient that redirects to the main Client class. This class exists for backwards compatibility.""" - + def __init__(self, *args, **kwargs): import warnings warnings.warn( - "AsyncClient is deprecated and will be removed in a future version. " + "AsyncClient is deprecated and will be removed in future versions." "Use Client instead, which now supports both sync and async operations.", DeprecationWarning, stacklevel=2 ) super().__init__(*args, **kwargs) - self.chat = Chat(self) - self._images = Images(self) - self.completions = Completions(self) - - @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 async_create(self, *args, **kwargs): + """Asynchronous create method that calls the synchronous method.""" + return await super().async_create(*args, **kwargs) - async def async_generate(self, *args, **kwargs) -> 'ImagesResponse': + async def async_generate(self, *args, **kwargs): + """Asynchronous image generation method.""" 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}") + async def async_images(self) -> Images: + """Asynchronous access to images.""" + return await super().async_images() + + async def async_fetch_image(self, url: str) -> bytes: + """Asynchronous fetching of an image by URL.""" + return await self._fetch_image(url) class Completions: def __init__(self, client: Client, provider: ProviderType = None): |