From 151f8b8b0e409b112c806927250d5f578f0f6805 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 12 Feb 2024 12:08:08 +0100 Subject: Add variant example --- g4f/client.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'g4f') 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 -- cgit v1.2.3