mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-22 15:05:57 +03:00
Add variant example
This commit is contained in:
parent
aba4b96f23
commit
151f8b8b0e
@ -227,6 +227,9 @@ docker-compose down
|
||||
## 💡 Usage
|
||||
|
||||
### New Client with Image Generation
|
||||
|
||||
#### not jet released
|
||||
|
||||
```python
|
||||
from g4f.client import Client
|
||||
|
||||
|
BIN
docs/cat.webp
Normal file
BIN
docs/cat.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
@ -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)
|
||||
|
@ -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()
|
||||
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
|
Loading…
Reference in New Issue
Block a user