Fix: Problem with langfuse_tags when using litellm proxy with langfus… (#7825)

* Fix: Problem with langfuse_tags when using litellm proxy with langfuse integration (#7801)

* Refactor: Create method get_langfuse_tags

* Fix: Exception Handling
This commit is contained in:
yuu341 2025-01-19 05:39:57 +09:00 committed by GitHub
parent 3dc74c6670
commit 7b3863b304
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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