__event_emitter__ does not allow to create an artifact #3390

Closed
opened 2025-11-11 15:30:47 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @fovendor on GitHub (Jan 23, 2025).

Bug Report

Installation Method

Miniconda-v3

Environment

  • Open WebUI Version: v0.5.6
  • Operating System: Ubuntu 24.04.1 LTS
  • Browser: Firefox 134.0.2 (64-bit) flatpak

Expected Behavior:

  1. By calling the Action button, I expect that the code will return to the chat, which will be picked up by the artifact to work with my pre-prepared web page.

  2. When I call the artifact with the "Artifact" button, I expect to see an artifact with my web page.

  3. This behavior should work in any dialog, starting with any message.

Actual Behavior:

  1. I save the function code and when I go back to chat, write promt, get a reply and clicking the Action button I do see an unformatted sheet of my web page in chat, I then open the artifact and it works as it should.

  2. I open another dialog and repeat the same thing, but nothing happens: the web page code is not displayed in the chat, the artifact is not created.

  3. I refresh the page, start a new dialog, refresh the page again, but it doesn't work.

  4. I go to the edit function code page and, without changing anything, click save. The code is saved without any changes.

  5. I go back to the chat room and re-click on the Action button and it works as it should.

  6. I try going to another dialog and creating a new artifact, but it fails again and the cycle has to be repeated again.

  7. WTF? :)

Reproduction Details:

You need to take my code, create a function and repeat my steps from the section above. I'm also attaching a video:

https://github.com/user-attachments/assets/ca4ed53f-8b26-44e2-9597-a94555970444

Example Code:

from pydantic import BaseModel
from typing import Optional


class Action:
    class Valves(BaseModel):
        pass

    def __init__(self):
        self.valves = self.Valves()
        self.is_executed = False

    async def action(
        self,
        body: dict,
        __user__=None,
        __event_emitter__=None,
        __event_call__=None,
    ) -> Optional[dict]:
        if self.is_executed:
            return None
        self.is_executed = True

        html_content = """
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inpainting Helper</title></head><body><h1>Inpainting Helper</h1><div class="input-group"><label for="fileInput">Выберите изображение:</label><input id="fileInput" type="file" accept="image/*"></div></body></html>
        """

        # Отправка статусов
        if __event_emitter__:
            await __event_emitter__(
                {
                    "type": "status",
                    "data": {"description": "Генерация интерфейса...", "done": False},
                }
            )

            # Основная отправка HTML
            await __event_emitter__(
                {
                    "type": "message",
                    "data": {
                        "role": "assistant",
                        "content_type": "html",
                        "content": html_content,
                    },
                }
            )

            await __event_emitter__(
                {
                    "type": "status",
                    "data": {"description": "Интерфейс готов", "done": True},
                }
            )
            return None

        # Fallback для старых версий
        # return {"role": "assistant", "content_type": "html", "content": html_content}
        return None

Wish:

I originally wanted to know if it was possible to trigger artifact creation without returning any code to the user chat, but I ran into the problem described. Please explain to me:

  1. Is there any way to output a small web page with scripts and styles directly in the Action button dialog with the user without resorting to artifacts?
  2. If not, is it possible to send the web page code directly to the artifact on the Action button, without printing the web page code in the dialog?
  3. If not, I'd be glad to get an explanation on how to fix artifact creation with code output in the dialog, but make it reliable and work without weird tambourine dancing.

Thank you very much in advance!

Originally created by @fovendor on GitHub (Jan 23, 2025). # Bug Report ## Installation Method Miniconda-v3 ## Environment - **Open WebUI Version:** v0.5.6 - **Operating System:** Ubuntu 24.04.1 LTS - **Browser:** Firefox 134.0.2 (64-bit) flatpak ## Expected Behavior: 1. By calling the Action button, I expect that the code will return to the chat, which will be picked up by the artifact to work with my pre-prepared web page. 2. When I call the artifact with the "Artifact" button, I expect to see an artifact with my web page. 3. This behavior should work in any dialog, starting with any message. ## Actual Behavior: 1. I save the function code and when I go back to chat, write promt, get a reply and clicking the Action button I do see an unformatted sheet of my web page in chat, I then open the artifact and it works as it should. 2. I open another dialog and repeat the same thing, but nothing happens: the web page code is not displayed in the chat, the artifact is not created. 3. I refresh the page, start a new dialog, refresh the page again, but it doesn't work. 4. I go to the edit function code page and, without changing anything, click save. The code is saved without any changes. 5. I go back to the chat room and re-click on the Action button and it works as it should. 6. I try going to another dialog and creating a new artifact, but it fails again and the cycle has to be repeated again. 7. WTF? :) ## Reproduction Details: You need to take my code, create a function and repeat my steps from the section above. I'm also attaching a video: https://github.com/user-attachments/assets/ca4ed53f-8b26-44e2-9597-a94555970444 ## Example Code: ```python from pydantic import BaseModel from typing import Optional class Action: class Valves(BaseModel): pass def __init__(self): self.valves = self.Valves() self.is_executed = False async def action( self, body: dict, __user__=None, __event_emitter__=None, __event_call__=None, ) -> Optional[dict]: if self.is_executed: return None self.is_executed = True html_content = """ <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inpainting Helper</title></head><body><h1>Inpainting Helper</h1><div class="input-group"><label for="fileInput">Выберите изображение:</label><input id="fileInput" type="file" accept="image/*"></div></body></html> """ # Отправка статусов if __event_emitter__: await __event_emitter__( { "type": "status", "data": {"description": "Генерация интерфейса...", "done": False}, } ) # Основная отправка HTML await __event_emitter__( { "type": "message", "data": { "role": "assistant", "content_type": "html", "content": html_content, }, } ) await __event_emitter__( { "type": "status", "data": {"description": "Интерфейс готов", "done": True}, } ) return None # Fallback для старых версий # return {"role": "assistant", "content_type": "html", "content": html_content} return None ``` ## Wish: I originally wanted to know if it was possible to trigger artifact creation without returning any code to the user chat, but I ran into the problem described. Please explain to me: 1. Is there any way to output a small web page with scripts and styles directly in the Action button dialog with the user without resorting to artifacts? 2. If not, is it possible to send the web page code directly to the artifact on the Action button, without printing the web page code in the dialog? 3. If not, I'd be glad to get an explanation on how to fix artifact creation with code output in the dialog, but make it reliable and work without weird tambourine dancing. Thank you very much in advance!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#3390