Skip to content

Commit ae8c32d

Browse files
authored
Merge pull request #524 from chriskhanhtran/feature/fix_langfuse_tracing_temporary_chats
Feat: Use session_id to trace temporary chats with Langfuse
2 parents adec657 + 7d0c33b commit ae8c32d

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

examples/filters/langfuse_filter_pipeline.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
title: Langfuse Filter Pipeline
33
author: open-webui
4-
date: 2025-03-28
4+
date: 2025-06-16
55
version: 1.7
66
license: MIT
77
description: A filter pipeline that uses Langfuse.
@@ -126,6 +126,12 @@ async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
126126

127127
metadata = body.get("metadata", {})
128128
chat_id = metadata.get("chat_id", str(uuid.uuid4()))
129+
130+
# Handle temporary chats
131+
if chat_id == "local":
132+
session_id = metadata.get("session_id")
133+
chat_id = f"temporary-session-{session_id}"
134+
129135
metadata["chat_id"] = chat_id
130136
body["metadata"] = metadata
131137

@@ -233,6 +239,12 @@ async def outlet(self, body: dict, user: Optional[dict] = None) -> dict:
233239
self.log(f"Outlet function called with body: {body}")
234240

235241
chat_id = body.get("chat_id")
242+
243+
# Handle temporary chats
244+
if chat_id == "local":
245+
session_id = body.get("session_id")
246+
chat_id = f"temporary-session-{session_id}"
247+
236248
metadata = body.get("metadata", {})
237249
# Defaulting to 'llm_response' if no task is provided
238250
task_name = metadata.get("task", "llm_response")

0 commit comments

Comments
 (0)