mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-23 19:11:48 +03:00
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))
This commit is contained in:
parent
f38428ab23
commit
5ec0302e19
11
g4f/image.py
11
g4f/image.py
@ -23,6 +23,11 @@ EXTENSIONS_MAP: dict[str, str] = {
|
||||
"image/webp": "webp",
|
||||
}
|
||||
|
||||
def fix_url(url:str) -> str:
|
||||
""" replace ' ' by '+' (to be markdown compliant)"""
|
||||
return url.replace(" ","+")
|
||||
|
||||
|
||||
def to_image(image: ImageType, is_svg: bool = False) -> Image:
|
||||
"""
|
||||
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
|
||||
str: The formatted markdown string.
|
||||
"""
|
||||
if isinstance(images, str):
|
||||
result = f"[![{alt}]({preview.replace('{image}', images) if preview else images})]({images})"
|
||||
result = f"[![{alt}]({fix_url(preview.replace('{image}', images) if preview else images)})]({fix_url(images)})"
|
||||
else:
|
||||
if not isinstance(preview, list):
|
||||
preview = [preview.replace('{image}', image) if preview else image for image in images]
|
||||
result = "\n".join(
|
||||
f"[![#{idx+1} {alt}]({preview[idx]})]({image})"
|
||||
f"[![#{idx+1} {alt}]({fix_url(preview[idx])})]({fix_url(image)})"
|
||||
#f'[<img src="{preview[idx]}" width="200" alt="#{idx+1} {alt}">]({image})'
|
||||
for idx, image in enumerate(images)
|
||||
)
|
||||
@ -302,4 +307,4 @@ class ImageRequest:
|
||||
self.options = options
|
||||
|
||||
def get(self, key: str):
|
||||
return self.options.get(key)
|
||||
return self.options.get(key)
|
||||
|
@ -248,7 +248,7 @@ class AsyncGeneratorProvider(AsyncProvider):
|
||||
str: The created result as a string.
|
||||
"""
|
||||
return "".join([
|
||||
chunk async for chunk in cls.create_async_generator(model, messages, stream=False, **kwargs)
|
||||
str(chunk) async for chunk in cls.create_async_generator(model, messages, stream=False, **kwargs)
|
||||
if not isinstance(chunk, (Exception, FinishReason))
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user