diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-03-13 15:17:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 15:17:25 +0100 |
commit | 9c381f29060d697fe2d2c4768cd51b37d98ef3e0 (patch) | |
tree | 08a729476060f61f16ac8e909ed7dfe1cf4b2843 /g4f/providers | |
parent | Merge pull request #1680 from Zero6992/main (diff) | |
parent | Update Bing.py (diff) | |
download | gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar.gz gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar.bz2 gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar.lz gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar.xz gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.tar.zst gpt4free-9c381f29060d697fe2d2c4768cd51b37d98ef3e0.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/providers/create_images.py | 5 | ||||
-rw-r--r-- | g4f/providers/helper.py | 12 |
2 files changed, 11 insertions, 6 deletions
diff --git a/g4f/providers/create_images.py b/g4f/providers/create_images.py index 29a2a041..29db9435 100644 --- a/g4f/providers/create_images.py +++ b/g4f/providers/create_images.py @@ -6,6 +6,7 @@ import asyncio from .. import debug from ..typing import CreateResult, Messages from .types import BaseProvider, ProviderType +from ..image import ImageResponse system_message = """ You can generate images, pictures, photos or img with the DALL-E 3 image generator. @@ -92,7 +93,9 @@ class CreateImagesProvider(BaseProvider): messages.insert(0, {"role": "system", "content": self.system_message}) buffer = "" for chunk in self.provider.create_completion(model, messages, stream, **kwargs): - if isinstance(chunk, str) and buffer or "<" in chunk: + if isinstance(chunk, ImageResponse): + yield chunk + elif isinstance(chunk, str) and buffer or "<" in chunk: buffer += chunk if ">" in buffer: match = re.search(r'<img data-prompt="(.*?)">', buffer) diff --git a/g4f/providers/helper.py b/g4f/providers/helper.py index df6767a4..5f3b4fb6 100644 --- a/g4f/providers/helper.py +++ b/g4f/providers/helper.py @@ -1,7 +1,6 @@ from __future__ import annotations import random -import secrets import string from ..typing import Messages @@ -40,11 +39,14 @@ def get_random_string(length: int = 10) -> str: for _ in range(length) ) -def get_random_hex() -> str: +def get_random_hex(length: int = 32) -> str: """ - Generate a random hexadecimal string of a fixed length. + Generate a random hexadecimal string with n length. Returns: - str: A random hexadecimal string of 32 characters (16 bytes). + str: A random hexadecimal string of n characters. """ - return secrets.token_hex(16).zfill(32)
\ No newline at end of file + return ''.join( + random.choice("abcdef" + string.digits) + for _ in range(length) + )
\ No newline at end of file |