summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/create_images.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-10 20:08:06 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-10 20:08:06 +0100
commit4343082d37d9fedda6e51bd034657a52c5c1aa2b (patch)
treef2c786df1d7759b212fce4e697c8dd23b649398a /g4f/Provider/create_images.py
parentFix bing stream func (diff)
downloadgpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar.gz
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar.bz2
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar.lz
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar.xz
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.tar.zst
gpt4free-4343082d37d9fedda6e51bd034657a52c5c1aa2b.zip
Diffstat (limited to 'g4f/Provider/create_images.py')
-rw-r--r--g4f/Provider/create_images.py13
1 files changed, 8 insertions, 5 deletions
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