返回提交历史
Modified
g4f/image.py
+8
-3
Modified
g4f/providers/base_provider.py
+1
-1
XFEstudio/gpt4free
FIX: fix the url in the markdown output (md compliance), and the chunk/ImageResponse to str ! (#2353)
add fix_url ( replace ' ' by '+' (to be markdown compliant))
5ec0302e
代码差异
2 个文件
+9
-4
@@ -23,6 +23,11 @@ EXTENSIONS_MAP: dict[str, str] = {
23
23
"image/webp": "webp",
24
24
}
25
25
26
def fix_url(url:str) -> str:
27
""" replace ' ' by '+' (to be markdown compliant)"""
28
return url.replace(" ","+")
29
30
26
31
def to_image(image: ImageType, is_svg: bool = False) -> Image:
27
32
"""
28
33
Converts the input image to a PIL Image object.
@@ -212,12 +217,12 @@ def format_images_markdown(images: Union[str, list], alt: str, preview: Union[st
212
217
str: The formatted markdown string.
213
218
"""
214
219
if isinstance(images, str):
215
result = f"[ if preview else images})]({images})"
220
result = f"[ if preview else images)})]({fix_url(images)})"
216
221
else:
217
222
if not isinstance(preview, list):
218
223
preview = [preview.replace('{image}', image) if preview else image for image in images]
219
224
result = "\n".join(
220
f"[]({image})"
225
f"[})]({fix_url(image)})"
221
226
#f'[<img src="{preview[idx]}" width="200" alt="#{idx+1} {alt}">]({image})'
222
227
for idx, image in enumerate(images)
223
228
)
@@ -302,4 +307,4 @@ class ImageRequest:
302
307
self.options = options
303
308
304
309
def get(self, key: str):
305
return self.options.get(key)
310
return self.options.get(key)
@@ -248,7 +248,7 @@ class AsyncGeneratorProvider(AsyncProvider):
248
248
str: The created result as a string.
249
249
"""
250
250
return "".join([
251
chunk async for chunk in cls.create_async_generator(model, messages, stream=False, **kwargs)
251
str(chunk) async for chunk in cls.create_async_generator(model, messages, stream=False, **kwargs)
252
252
if not isinstance(chunk, (Exception, FinishReason))
253
253
])
254
254