From 7b3863b304cfeb9236068bab2d72279c5de7e92b Mon Sep 17 00:00:00 2001 From: yuu341 Date: Sun, 19 Jan 2025 05:39:57 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20Problem=20with=20langfuse=5Ftags=20when?= =?UTF-8?q?=20using=20litellm=20proxy=20with=20langfus=E2=80=A6=20(#7825)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Problem with langfuse_tags when using litellm proxy with langfuse integration (#7801) * Refactor: Create method get_langfuse_tags * Fix: Exception Handling --- litellm/integrations/langfuse/langfuse.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/langfuse/langfuse.py b/litellm/integrations/langfuse/langfuse.py index 2a459af9b91..9fb2f86f683 100644 --- a/litellm/integrations/langfuse/langfuse.py +++ b/litellm/integrations/langfuse/langfuse.py @@ -1,6 +1,7 @@ #### What this does #### # On success, logs events to Langfuse import copy +import json import os import traceback from collections.abc import MutableMapping, MutableSequence, MutableSet @@ -457,7 +458,7 @@ class LangFuseLogger: supports_costs = langfuse_version >= Version("2.7.3") supports_completion_start_time = langfuse_version >= Version("2.7.3") - tags = metadata.pop("tags", []) if supports_tags else [] + tags = self._get_langfuse_tags(metadata) if supports_tags else [] standard_logging_object: Optional[StandardLoggingPayload] = cast( Optional[StandardLoggingPayload], @@ -732,6 +733,14 @@ class LangFuseLogger: verbose_logger.error(f"Langfuse Layer Error - {traceback.format_exc()}") return None, None + @staticmethod + def _get_langfuse_tags(metadata: dict) -> list[str]: + try: + return json.loads(metadata.pop("tags", "[]")) + except Exception as e: + verbose_logger.exception("error getting langfuse tags %s", str(e)) + return [] + def add_default_langfuse_tags(self, tags, kwargs, metadata): """ Helper function to add litellm default langfuse tags