summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-10 20:09:46 +0100
committerGitHub <noreply@github.com>2024-01-10 20:09:46 +0100
commit517895845e3dba453130da800ec02a5170a2fc66 (patch)
tree48cf7bb921e4de5f4c7359b76e19d38d04e33e05 /g4f
parent~ | gf4 `v-0.2.0.0` (diff)
parentFix create_async in CreateImagesProvider (diff)
downloadgpt4free-0.1.9.11.tar
gpt4free-0.1.9.11.tar.gz
gpt4free-0.1.9.11.tar.bz2
gpt4free-0.1.9.11.tar.lz
gpt4free-0.1.9.11.tar.xz
gpt4free-0.1.9.11.tar.zst
gpt4free-0.1.9.11.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Bing.py2
-rw-r--r--g4f/Provider/create_images.py13
2 files changed, 9 insertions, 6 deletions
diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py
index 10a88ffb..18a6040b 100644
--- a/g4f/Provider/Bing.py
+++ b/g4f/Provider/Bing.py
@@ -249,7 +249,7 @@ async def stream_generate(
cookies: dict = None,
web_search: bool = False,
gpt4_turbo: bool = False,
- timeout = int = 900
+ timeout: int = 900
):
headers = Defaults.headers
if cookies:
diff --git a/g4f/Provider/create_images.py b/g4f/Provider/create_images.py
index 9c76a742..29f88a80 100644
--- a/g4f/Provider/create_images.py
+++ b/g4f/Provider/create_images.py
@@ -71,14 +71,17 @@ class CreateImagesProvider(BaseProvider):
) -> str:
messages.insert(0, {"role": "system", "content": self.system_message})
response = await self.provider.create_async(model, messages, **kwargs)
- matches = re.findall(r'(<img data-prompt="(.*?)">)', result)
+ matches = re.findall(r'(<img data-prompt="(.*?)">)', response)
results = []
- for _, prompt in matches:
- results.append(self.create_images_async(prompt))
+ placeholders = []
+ for placeholder, prompt in matches:
+ if placeholder not in placeholders:
+ results.append(self.create_images_async(prompt))
+ placeholders.append(placeholder)
results = await asyncio.gather(*results)
for idx, result in enumerate(results):
- placeholder = matches[idx][0]
+ placeholder = placeholder[idx]
if self.include_placeholder:
result = placeholder + result
response = response.replace(placeholder, result)
- return result \ No newline at end of file
+ return response \ No newline at end of file