Feature Request: Chat UUID included in pipeline body argument
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.
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
when i use def inlet with pipe, i cant access pipe. there should be a way to get chat_id within def pipe
@tcgumus hi
- You set it in your init:
def __init__(self):
self.name = "Dream Pipeline"
self.valves = self.Valves()
self.chat_id = None
- 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
- 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
This works great! Thanks!
In new versions of Open WebUI it doesnt work. How to get chat_id now?
I agree that recent changes paired with inadequate documentation has been frustrating.
check this recent example
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 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.
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."
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
I think it should be changed first Open-webui code
https://github.com/open-webui/open-webui/discussions/6999
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