[GH-ISSUE #8292] Issue with __event_emitter__ for Action functions #15071

Closed
opened 2026-04-19 21:21:55 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @deseven on GitHub (Jan 3, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/8292

Originally assigned to: @tjbck on GitHub.


Installation Method

Docker

Environment

  • Open WebUI Version: 0.5.3
  • Operating System: Linux

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

__event_emitter__ should work.

Actual Behavior:

__event_emitter__ doesn't work, producing an exception.

Description

Bug Summary:

Seems to be similar to #8168 but this time for Action functions.

Reproduction Details

Use the following test function (created by Albert Wesker on Discord):

"""
title: TEST SAMPLE
version: 0.1
description: TEST SAMPLE
"""

from typing import Optional, Dict, Any
from pydantic import BaseModel
from typing import Optional
import asyncio


class Action:
    class Valves(BaseModel):
        pass

    class UserValves(BaseModel):
        pass

    def __init__(self):
        self.valves = self.Valves()
        pass

    async def action(
        self,
        body: dict,
        __user__=None,
        __event_emitter__=None,
        __event_call__=None,
    ) -> Optional[dict]:
        print(f"action: {__name__}")
        print(f"body: {body}")
        print(f"has event emitter: {__event_emitter__}")
        if __event_emitter__:
            try:
                await __event_emitter__(
                    {
                        "type": "status",
                        "data": {"description": "processing", "done": False},
                    }
                )
                await asyncio.sleep(5)
                await __event_emitter__(
                    {"type": "message", "data": {"content": " **message 1**"}}
                )
                await asyncio.sleep(5)
                await __event_emitter__(
                    {
                        "type": "status",
                        "data": {"description": "process done !", "done": True},
                    }
                )
            except Exception as e:
                print("error: ", e)

        print("finished!")

        return body

When executing it nothing happens on the frontend, here's output from the action:

action: function_example_action
body: {'model': 'image-prompt', 'messages': [{'id': '0144f8cd-74e8-4882-bd3b-185267396838', 'role': 'user', 'content': 'test', 'timestamp': 1735865897}, {'id': 'a7768214-e658-44b7-a442-cbb0ff17c83a', 'role': 'assistant', 'content': 'test', 'timestamp': 1735865984}], 'chat_id': 'b21e93f1-9ad5-473d-901e-c525db2dce24', 'session_id': '1xhzjz3nm1T1T63nAABd', 'id': 'a7768214-e658-44b7-a442-cbb0ff17c83a'}
has event emitter: <function get_event_emitter.<locals>.__event_emitter__ at 0xffff93d96200>
error:  'user_id'
finished!
Originally created by @deseven on GitHub (Jan 3, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/8292 Originally assigned to: @tjbck on GitHub. --- ## Installation Method Docker ## Environment - **Open WebUI Version:** 0.5.3 - **Operating System:** Linux **Confirmation:** - [x] I have read and followed all the instructions provided in the README.md. - [x] I am on the latest version of both Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: `__event_emitter__` should work. ## Actual Behavior: `__event_emitter__` doesn't work, producing an exception. ## Description **Bug Summary:** Seems to be similar to #8168 but this time for Action functions. ## Reproduction Details Use the following test function ([created by Albert Wesker on Discord](https://discord.com/channels/1170866489302188073/1324670852511567933/1324670852511567933)): ```python """ title: TEST SAMPLE version: 0.1 description: TEST SAMPLE """ from typing import Optional, Dict, Any from pydantic import BaseModel from typing import Optional import asyncio class Action: class Valves(BaseModel): pass class UserValves(BaseModel): pass def __init__(self): self.valves = self.Valves() pass async def action( self, body: dict, __user__=None, __event_emitter__=None, __event_call__=None, ) -> Optional[dict]: print(f"action: {__name__}") print(f"body: {body}") print(f"has event emitter: {__event_emitter__}") if __event_emitter__: try: await __event_emitter__( { "type": "status", "data": {"description": "processing", "done": False}, } ) await asyncio.sleep(5) await __event_emitter__( {"type": "message", "data": {"content": " **message 1**"}} ) await asyncio.sleep(5) await __event_emitter__( { "type": "status", "data": {"description": "process done !", "done": True}, } ) except Exception as e: print("error: ", e) print("finished!") return body ``` When executing it nothing happens on the frontend, here's output from the action: ``` action: function_example_action body: {'model': 'image-prompt', 'messages': [{'id': '0144f8cd-74e8-4882-bd3b-185267396838', 'role': 'user', 'content': 'test', 'timestamp': 1735865897}, {'id': 'a7768214-e658-44b7-a442-cbb0ff17c83a', 'role': 'assistant', 'content': 'test', 'timestamp': 1735865984}], 'chat_id': 'b21e93f1-9ad5-473d-901e-c525db2dce24', 'session_id': '1xhzjz3nm1T1T63nAABd', 'id': 'a7768214-e658-44b7-a442-cbb0ff17c83a'} has event emitter: <function get_event_emitter.<locals>.__event_emitter__ at 0xffff93d96200> error: 'user_id' finished! ```
Author
Owner

@tjbck commented on GitHub (Jan 4, 2025):

Might already be resolved in dev, testing wanted here!

<!-- gh-comment-id:2570272614 --> @tjbck commented on GitHub (Jan 4, 2025): Might already be resolved in dev, testing wanted here!
Author
Owner

@deseven commented on GitHub (Jan 4, 2025):

Seems to be doing something, but I'm not sure if it's the correct behaviour or not. It adds a custom message first, but then removes it.

Logs:

openwebui_1  | action: function_example_action
openwebui_1  | body: {'model': 'gpt-4o-mini', 'messages': [{'id': 'b18992e9-42eb-4bcf-a7a7-95d973752773', 'role': 'user', 'content': 'test'}, {'id': '518a4037-7eb2-447a-a956-8ff3902f637c', 'role': 'assistant', 'content': 'Test received! How can I assist you today?', 'timestamp': 1736014760}], 'chat_id': '8efb08e9-b866-485a-993e-5d517b02c0b9', 'session_id': 'l6uIDeHZOhBgVOPeAAAB', 'id': '518a4037-7eb2-447a-a956-8ff3902f637c'}
openwebui_1  | has event emitter: <function get_event_emitter.<locals>.__event_emitter__ at 0x7fa50887c0>
openwebui_1  | finished!

Video (ignore the slowness, I'm running it on a very crappy arm cpu):
https://d7.wtf/s/Recording%20at%202025-01-04%2019.19.40.mp4

<!-- gh-comment-id:2571375344 --> @deseven commented on GitHub (Jan 4, 2025): Seems to be doing something, but I'm not sure if it's the correct behaviour or not. It adds a custom message first, but then removes it. Logs: ``` openwebui_1 | action: function_example_action openwebui_1 | body: {'model': 'gpt-4o-mini', 'messages': [{'id': 'b18992e9-42eb-4bcf-a7a7-95d973752773', 'role': 'user', 'content': 'test'}, {'id': '518a4037-7eb2-447a-a956-8ff3902f637c', 'role': 'assistant', 'content': 'Test received! How can I assist you today?', 'timestamp': 1736014760}], 'chat_id': '8efb08e9-b866-485a-993e-5d517b02c0b9', 'session_id': 'l6uIDeHZOhBgVOPeAAAB', 'id': '518a4037-7eb2-447a-a956-8ff3902f637c'} openwebui_1 | has event emitter: <function get_event_emitter.<locals>.__event_emitter__ at 0x7fa50887c0> openwebui_1 | finished! ``` Video (ignore the slowness, I'm running it on a very crappy arm cpu): https://d7.wtf/s/Recording%20at%202025-01-04%2019.19.40.mp4
Author
Owner

@MaximeRivest commented on GitHub (Jan 4, 2025):

on cuda nothing showed up in the status and on dev I had the 3 messages. So its fixed for me. (not sure if I should use cuda or not...)

<!-- gh-comment-id:2571400979 --> @MaximeRivest commented on GitHub (Jan 4, 2025): on cuda nothing showed up in the status and on dev I had the 3 messages. So its fixed for me. (not sure if I should use cuda or not...)
Author
Owner

@deseven commented on GitHub (Jan 5, 2025):

@MaximeRivest what do you mean by "3 messages"? It should change the status twice and append to the assistant's message, unless I'm missing something.

<!-- gh-comment-id:2571454995 --> @deseven commented on GitHub (Jan 5, 2025): @MaximeRivest what do you mean by "3 messages"? It should change the status twice and append to the assistant's message, unless I'm missing something.
Author
Owner

@MaximeRivest commented on GitHub (Jan 5, 2025):

This, sorry my message was not very clear

Screenshot from 2025-01-04 19-43-04
Screenshot from 2025-01-04 19-44-03
Screenshot from 2025-01-04 19-43-11

<!-- gh-comment-id:2571455653 --> @MaximeRivest commented on GitHub (Jan 5, 2025): This, sorry my message was not very clear ![Screenshot from 2025-01-04 19-43-04](https://github.com/user-attachments/assets/d9717a9f-7da3-4619-a859-e6627ea2babb) ![Screenshot from 2025-01-04 19-44-03](https://github.com/user-attachments/assets/6e21c408-8dda-4ff7-ab8d-f3586a2296db) ![Screenshot from 2025-01-04 19-43-11](https://github.com/user-attachments/assets/979b41cb-d2b2-4d62-837c-a01de00bbe39)
Author
Owner

@deseven commented on GitHub (Jan 5, 2025):

Gotcha, thanks, so what you get is the same. Do you know if it should remove the appended message (message 1) at the last step?

<!-- gh-comment-id:2571456328 --> @deseven commented on GitHub (Jan 5, 2025): Gotcha, thanks, so what you get is the same. Do you know if it should remove the appended message (**message 1**) at the last step?
Author
Owner

@MaximeRivest commented on GitHub (Jan 5, 2025):

It seems due to return body without that it stays

<!-- gh-comment-id:2571461185 --> @MaximeRivest commented on GitHub (Jan 5, 2025): It seems due to `return body` without that it stays
Author
Owner

@deseven commented on GitHub (Jan 5, 2025):

Makes sense :)
Okay, all good then.

<!-- gh-comment-id:2571461654 --> @deseven commented on GitHub (Jan 5, 2025): Makes sense :) Okay, all good then.
Author
Owner

@tjbck commented on GitHub (Jan 5, 2025):

for anyone in the future that comes across this, action should almost always return None instead of return body!

<!-- gh-comment-id:2571462247 --> @tjbck commented on GitHub (Jan 5, 2025): for anyone in the future that comes across this, action should almost always return `None` instead of `return body`!
Author
Owner

@acceleratorlastorder commented on GitHub (Jan 5, 2025):

for anyone in the future that comes across this, action should almost always return None instead of return body!

i'm guessing in the event we want to change the actual content of the body we do have to return it then? if so is there a way to interpolate html or is it not possible at the moment? (one of my guess would be for security reason, but i'm asking in case not)

<!-- gh-comment-id:2571507279 --> @acceleratorlastorder commented on GitHub (Jan 5, 2025): > for anyone in the future that comes across this, action should almost always return `None` instead of `return body`! i'm guessing in the event we want to change the actual content of the body we do have to return it then? if so is there a way to interpolate html or is it not possible at the moment? (one of my guess would be for security reason, but i'm asking in case not)
Author
Owner

@tjbck commented on GitHub (Jan 5, 2025):

@acceleratorlastorder you can still use __event_emitter__ for the use case you described! There's nothing particularly wrong with returning body per se, but it's just not the best practice.

<!-- gh-comment-id:2571510694 --> @tjbck commented on GitHub (Jan 5, 2025): @acceleratorlastorder you can still use `__event_emitter__` for the use case you described! There's nothing particularly wrong with returning body per se, but it's just not the best practice.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#15071