diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-21 07:22:59 +0200 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-04-21 07:22:59 +0200 |
commit | db2d6cffd9268e8842f0c2aa8e062c0e19d88d28 (patch) | |
tree | 2b44e3ec6e21a8c1270f3d84a4a1f0efb360d37b /g4f/gui | |
parent | Disable Bing integration test (diff) | |
download | gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.gz gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.bz2 gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.lz gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.xz gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.zst gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.zip |
Diffstat (limited to 'g4f/gui')
-rw-r--r-- | g4f/gui/client/static/js/chat.v1.js | 8 | ||||
-rw-r--r-- | g4f/gui/server/api.py | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index a043cb25..8b00eed2 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -41,7 +41,9 @@ appStorage = window.localStorage || { length: 0 } -const markdown = window.markdownit(); +const markdown = window.markdownit({ + html: true, +}); const markdown_render = (content) => { return markdown.render(content .replaceAll(/<!-- generated images start -->|<!-- generated images end -->/gm, "") @@ -312,6 +314,8 @@ async function add_message_chunk(message) { window.error = message.error console.error(message.error); content_inner.innerHTML += `<p><strong>An error occured:</strong> ${message.error}</p>`; + } else if (message.type == "preview") { + content_inner.innerHTML = markdown_render(message.preview); } else if (message.type == "content") { window.text += message.content; html = markdown_render(window.text); @@ -545,7 +549,7 @@ const load_conversation = async (conversation_id, scroll=true) => { last_model = item.provider?.model; let next_i = parseInt(i) + 1; let next_provider = item.provider ? item.provider : (messages.length > next_i ? messages[next_i].provider : null); - let provider_label = item.provider?.label ? item.provider?.label : item.provider?.name; + let provider_label = item.provider?.label ? item.provider.label : item.provider?.name; let provider_link = item.provider?.name ? `<a href="${item.provider.url}" target="_blank">${provider_label}</a>` : ""; let provider = provider_link ? ` <div class="provider"> diff --git a/g4f/gui/server/api.py b/g4f/gui/server/api.py index 211d40c6..47c25eb7 100644 --- a/g4f/gui/server/api.py +++ b/g4f/gui/server/api.py @@ -7,6 +7,7 @@ from typing import Iterator from g4f import version, models from g4f import get_last_provider, ChatCompletion from g4f.errors import VersionNotFoundError +from g4f.image import ImagePreview from g4f.Provider import ProviderType, __providers__, __map__ from g4f.providers.base_provider import ProviderModelMixin, FinishReason from g4f.providers.conversation import BaseConversation @@ -146,6 +147,8 @@ class Api(): elif isinstance(chunk, Exception): logging.exception(chunk) yield self._format_json("message", get_error_message(chunk)) + elif isinstance(chunk, ImagePreview): + yield self._format_json("preview", chunk.to_string()) elif not isinstance(chunk, FinishReason): yield self._format_json("content", str(chunk)) except Exception as e: |