Merge pull request #407 from veleinfobip/my_correction

Fix issue with chat_id handling
This commit is contained in:
Timothy Jaeryang Baek 2025-02-14 13:09:28 -08:00 committed by GitHub
commit a07b306a8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,9 +80,12 @@ class Pipeline:
print(f"User: {user}") print(f"User: {user}")
# Check for presence of required keys and generate chat_id if missing # Check for presence of required keys and generate chat_id if missing
if "chat_id" not in body: if "chat_id" not in body.get("metadata", {}):
unique_id = f"SYSTEM MESSAGE {uuid.uuid4()}" unique_id = f"SYSTEM MESSAGE {uuid.uuid4()}"
body["chat_id"] = unique_id # Ensure the metadata key exists before assigning chat_id
if "metadata" not in body:
body["metadata"] = {} # Correct this indentation
body["metadata"]["chat_id"] = unique_id
print(f"chat_id was missing, set to: {unique_id}") print(f"chat_id was missing, set to: {unique_id}")
required_keys = ["model", "messages"] required_keys = ["model", "messages"]
@ -93,23 +96,27 @@ class Pipeline:
print(error_message) print(error_message)
raise ValueError(error_message) raise ValueError(error_message)
user_id = user.get("id") if user else None
user_name = user.get("name") if user else None
user_email = user.get("email") if user else None
trace = self.langfuse.trace( trace = self.langfuse.trace(
name=f"filter:{__name__}", name=f"filter:{__name__}",
input=body, input=body,
user_id=user["email"], user_id=user_email,
metadata={"user_name": user["name"], "user_id": user["id"]}, metadata={"user_name": user_name, "user_id": user_id,"chat_id": body["metadata"]["chat_id"]},
session_id=body["chat_id"], session_id=body["metadata"]["chat_id"],
) )
generation = trace.generation( generation = trace.generation(
name=body["chat_id"], name=body["metadata"]["chat_id"],
model=body["model"], model=body["model"],
input=body["messages"], input=body["messages"],
metadata={"interface": "open-webui"}, metadata={"interface": "open-webui"},
) )
self.chat_traces[body["chat_id"]] = trace self.chat_traces[body["metadata"]["chat_id"]] = trace
self.chat_generations[body["chat_id"]] = generation self.chat_generations[body["metadata"]["chat_id"]] = generation
return body return body