Skip to content

Commit

Permalink
feat: langfuse user id (#3533)
Browse files Browse the repository at this point in the history
# Description

Adding user ID and session ID (chat ID) to Langfuse
  • Loading branch information
jacopo-chevallard authored Dec 18, 2024
1 parent d0adb81 commit e0ccd3d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/quivr_core/brain/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e0ccd3d

Please # to comment.