pipelines icon indicating copy to clipboard operation
pipelines copied to clipboard

Feature Request: Chat UUID included in pipeline body argument

Open PlebeiusGaragicus opened this issue 1 year ago • 12 comments

Is your feature request related to a problem? Please describe. No, not a problem.

Describe the solution you'd like I'm working with pipelines. The pipe() function is given a parameter called body which is a dict and includes information about the user, message history, etc. I'd like to include more information - specifically the UUID of the chat. For example, when you share a chat if gives a link with ".../c/84966624-bd6a-45fa-a045-323f86334b79/" I'm just looking for that unique UUID included in the URL to be passed into a pipeline.

Describe alternatives you've considered I've considered creating and tracking UUIDs myself - but it is duplicative and prone to add more bugs into my flow.

Additional context Since pipelines allow for calling arbitrary code (read: custom agentic workflows, etc) it would be useful and allow for tracking of conversation threads inside these agents.

PlebeiusGaragicus avatar Jul 20 '24 01:07 PlebeiusGaragicus

Thanks for raising @PlebeiusGaragicus

Actually there's a workaround for you - you would not find the chat_id in in the def pipe() body object, but you will find it in the def inlet

zebra-doom avatar Jul 22 '24 13:07 zebra-doom

when i use def inlet with pipe, i cant access pipe. there should be a way to get chat_id within def pipe

tcgumus avatar Jul 25 '24 07:07 tcgumus

@tcgumus hi

  1. You set it in your init:
    def __init__(self):
        self.name = "Dream Pipeline"
        self.valves = self.Valves()
        self.chat_id = None
  1. You store it in your inlet:
    async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
        print(f"inlet:{__name__}")
        print(f"user: {user}")
        print(f"body: {body}")
        # Store the chat_id from body
        self.chat_id = body.get("chat_id")
        print(f"Stored chat_id: {self.chat_id}")

        return body

  1. You access it in your pipe
    def pipe(
        self, user_message: str, model_id: str, messages: List[dict], body: dict
    ) -> Union[str, Generator, Iterator]:
        print(f"pipe:{__name__}")

        print(f"chat_id available in pipe: {self.chat_id}")

        print(messages)
        print(user_message)

        if body.get("title", False):
            print("Title Generation")
            return "Python Code Pipeline"
        else:
            stdout, return_code = self.execute_python_code(user_message)
            return stdout

Certainly issues with concurrent user access, need to have threading local storage, etc. but that's your workaround, waiting for the orchestrator (webui) to do their part.

Happy coding

zebra-doom avatar Jul 25 '24 08:07 zebra-doom

This works great! Thanks!

PlebeiusGaragicus avatar Jul 27 '24 02:07 PlebeiusGaragicus

In new versions of Open WebUI it doesnt work. How to get chat_id now?

VadimPoliakov avatar Dec 24 '24 14:12 VadimPoliakov

I agree that recent changes paired with inadequate documentation has been frustrating.

check this recent example

PlebeiusGaragicus avatar Dec 27 '24 20:12 PlebeiusGaragicus

for anybody wanting similar thing.. yes it did break.. but it was just a data model change the below modification should work.

    async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
        print(f"inlet:{__name__}")
        print(f"body: {body}")
        print(f"user: {user}")
        self.user_id = user.get("id")
        self.user_name = user.get("name")
        self.user_email = user.get("email")
        self.chat_id = body.get("metadata").get("chat_id")
        self.message_id = body.get("metadata").get("message_id")

rajuptvs avatar Feb 26 '25 22:02 rajuptvs

@rajuptvs it seems that chat_id in metadata is always local now. not sure what's wrong.

edit: I use temperal chat, which set chat_id to local. silly me.

hubutui avatar May 03 '25 06:05 hubutui

Now I need to get the PARENT chat_id or message_id.

In order to use a pipeline with LangGraph agents and 'fork' a conversation thread, my agent needs to know the PARENT chat_id so I can resume from there. I'm not just passing the body with the messages list - state is managed inside the agent itself.

I'm wondering if we can import some code from Open WebUI inside the pipeline (like what people do to access knowledge base files) and use some API to get the current thread's message chain in order to find the current query's "parent."

PlebeiusGaragicus avatar May 25 '25 19:05 PlebeiusGaragicus

i cant get that running :(

i implemented this function:

But its not working... i always get None

Thats my initial pipe: https://github.com/sboily/open-webui-n8n-pipe/blob/main/n8n_pipe/n8n_pipe.py

    async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
        print(f"inlet:{__name__}")
        print(f"user: {user}")
        print(f"body: {body}")
        # Store the chat_id from body
        self.chat_id = body.get("metadata").get("chat_id")
        print(f"Stored chat_id: {self.chat_id}")

        return body

TryAnixx avatar Sep 16 '25 07:09 TryAnixx

I think it should be changed first Open-webui code

https://github.com/open-webui/open-webui/discussions/6999

HERIUN avatar Oct 02 '25 02:10 HERIUN

This Open WebUI pipe for enriching the Pipeline's pipe with metadata works well! No need to process inlet or use class attributes and thus seems to also resolve the race condition issue.

  • https://github.com/open-webui/open-webui/discussions/6999#discussioncomment-11731449

aallgeier avatar Nov 04 '25 18:11 aallgeier