From e0ccd3dc04b7527b27520465b2cf179e9789bf3f Mon Sep 17 00:00:00 2001 From: Jacopo Chevallard Date: Wed, 18 Dec 2024 16:29:11 +0100 Subject: [PATCH] feat: langfuse user id (#3533) # Description Adding user ID and session ID (chat ID) to Langfuse --- core/quivr_core/brain/brain.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/quivr_core/brain/brain.py b/core/quivr_core/brain/brain.py index e8d657fcfbf5..b19c7c0a7e3f 100644 --- a/core/quivr_core/brain/brain.py +++ b/core/quivr_core/brain/brain.py @@ -116,11 +116,14 @@ def __init__( vector_db: VectorStore | None = None, embedder: Embeddings | None = None, storage: StorageBase | None = None, + user_id: UUID | None = None, + chat_id: UUID | None = None, ): self.id = id self.name = name self.storage = storage - + self.user_id = user_id + self.chat_id = chat_id # Chat history self._chats = self._init_chats() self.default_chat = list(self._chats.values())[0] @@ -535,8 +538,15 @@ async def ask_streaming( list_files = [] if list_files is None else list_files full_answer = "" + metadata = { + "langfuse_user_id": str(self.user_id), + "langfuse_session_id": str(self.chat_id), + } async for response in rag_instance.answer_astream( - question=question, history=chat_history, list_files=list_files + question=question, + history=chat_history, + list_files=list_files, + metadata=metadata, ): # Format output to be correct servicedf;j if not response.last_chunk: