diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-12 12:08:08 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-12 12:08:08 +0100 |
commit | 151f8b8b0e409b112c806927250d5f578f0f6805 (patch) | |
tree | eb9576c91c9494722716a8d20b9f5e436547f7ab | |
parent | Add new Client API with Docs (diff) | |
download | gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar.gz gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar.bz2 gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar.lz gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar.xz gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.tar.zst gpt4free-151f8b8b0e409b112c806927250d5f578f0f6805.zip |
Diffstat (limited to '')
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | docs/cat.webp | bin | 0 -> 5876 bytes | |||
-rw-r--r-- | docs/client.md | 6 | ||||
-rw-r--r-- | g4f/client.py | 16 |
4 files changed, 20 insertions, 5 deletions
@@ -227,6 +227,9 @@ docker-compose down ## 💡 Usage ### New Client with Image Generation + +#### not jet released + ```python from g4f.client import Client diff --git a/docs/cat.webp b/docs/cat.webp Binary files differnew file mode 100644 index 00000000..29c13f59 --- /dev/null +++ b/docs/cat.webp diff --git a/docs/client.md b/docs/client.md index 1201a83d..deb5b0ba 100644 --- a/docs/client.md +++ b/docs/client.md @@ -68,4 +68,10 @@ response = client.images.create_variation( image_url = response.data[0].url ``` +Orginal: +[![Image with cat](/docs/cat.jpeg)](/docs/client.md) + +Variant: +[![Image with cat](/docs/cat.webp)](/docs/client.md) + [to Home](/docs/client.md) diff --git a/g4f/client.py b/g4f/client.py index 117db375..03b0eda3 100644 --- a/g4f/client.py +++ b/g4f/client.py @@ -241,7 +241,8 @@ class Images(): "", [{"role": "user", "content": prompt}], True, - proxy=self.client.get_proxy() + proxy=self.client.get_proxy(), + **kwargs ) else: response = provider.create(prompt) @@ -253,15 +254,20 @@ class Images(): def create_variation(self, image: ImageType, model: str = None, **kwargs): provider = self.models.get(model) if model else self.provider - if isinstance(provider, BaseProvider): + result = None + if isinstance(provider, type) and issubclass(provider, BaseProvider): response = provider.create_completion( "", [{"role": "user", "content": "create a image like this"}], True, image=image, - proxy=self.client.get_proxy() + proxy=self.client.get_proxy(), + **kwargs ) for chunk in response: if isinstance(chunk, ImageProviderResponse): - return ImagesResponse([Image(image)for image in list(chunk.images)]) - raise NoImageResponseError()
\ No newline at end of file + result = ([chunk.images] if isinstance(chunk.images, str) else chunk.images) + result = ImagesResponse([Image(image)for image in result]) + if result is None: + raise NoImageResponseError() + return result
\ No newline at end of file |