Skip to content

Commit e0ccd3d

Browse files
feat: langfuse user id (#3533)
# Description Adding user ID and session ID (chat ID) to Langfuse
1 parent d0adb81 commit e0ccd3d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/quivr_core/brain/brain.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ def __init__(
116116
vector_db: VectorStore | None = None,
117117
embedder: Embeddings | None = None,
118118
storage: StorageBase | None = None,
119+
user_id: UUID | None = None,
120+
chat_id: UUID | None = None,
119121
):
120122
self.id = id
121123
self.name = name
122124
self.storage = storage
123-
125+
self.user_id = user_id
126+
self.chat_id = chat_id
124127
# Chat history
125128
self._chats = self._init_chats()
126129
self.default_chat = list(self._chats.values())[0]
@@ -535,8 +538,15 @@ async def ask_streaming(
535538
list_files = [] if list_files is None else list_files
536539

537540
full_answer = ""
541+
metadata = {
542+
"langfuse_user_id": str(self.user_id),
543+
"langfuse_session_id": str(self.chat_id),
544+
}
538545
async for response in rag_instance.answer_astream(
539-
question=question, history=chat_history, list_files=list_files
546+
question=question,
547+
history=chat_history,
548+
list_files=list_files,
549+
metadata=metadata,
540550
):
541551
# Format output to be correct servicedf;j
542552
if not response.last_chunk:

0 commit comments

Comments
 (0)