From c0befe9bbb48681223d24482e2071002127a1b4e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Apr 2024 15:48:00 -0700 Subject: [PATCH 1/5] feat - log base_url to langfuse as a tag --- litellm/integrations/langfuse.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 3b13446a6a7..38536f55c46 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -300,6 +300,11 @@ class LangFuseLogger: else: clean_metadata[key] = value + # if user has set proxy_base_url in env -> log to langfuse as a tag + proxy_base_url = os.getenv("PROXY_BASE_URL", None) + if proxy_base_url is not None: + tags.append(f"proxy_base_url:{proxy_base_url}") + api_base = litellm_params.get("api_base", None) if api_base: clean_metadata["api_base"] = api_base From 2c76448756c420bd94639cbd3f9e607cfb7a882e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Apr 2024 16:01:27 -0700 Subject: [PATCH 2/5] fix - allow users to opt into langfuse default tags --- litellm/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/litellm/__init__.py b/litellm/__init__.py index 21f98e8b364..b9d9891ca25 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -16,11 +16,24 @@ dotenv.load_dotenv() if set_verbose == True: _turn_on_debug() ############################################# +### Callbacks /Logging / Success / Failure Handlers ### input_callback: List[Union[str, Callable]] = [] success_callback: List[Union[str, Callable]] = [] failure_callback: List[Union[str, Callable]] = [] service_callback: List[Union[str, Callable]] = [] callbacks: List[Callable] = [] +_langfuse_default_tags: Optional[ + List[ + Literal[ + "user_api_key_alias", + "user_api_key_user_id", + "user_api_key_user_email", + "user_api_key_team_alias", + "semantic-similarity", + "proxy_base_url", + ] + ] +] = None _async_input_callback: List[Callable] = ( [] ) # internal variable - async custom callbacks are routed here. @@ -32,6 +45,8 @@ _async_failure_callback: List[Callable] = ( ) # internal variable - async custom callbacks are routed here. pre_call_rules: List[Callable] = [] post_call_rules: List[Callable] = [] +## end of callbacks ############# + email: Optional[str] = ( None # Not used anymore, will be removed in next MAJOR release - https://github.com/BerriAI/litellm/discussions/648 ) From c59051895b4be9cef3a9dfe687a2e466ecf114e9 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Apr 2024 16:05:31 -0700 Subject: [PATCH 3/5] fix - allow users to opt into langfuse default tags --- litellm/integrations/langfuse.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 38536f55c46..3322fd4c474 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -280,13 +280,13 @@ class LangFuseLogger: clean_metadata = {} if isinstance(metadata, dict): for key, value in metadata.items(): - # generate langfuse tags - if key in [ - "user_api_key_alias", - "user_api_key_user_id", - "user_api_key_team_alias", - "semantic-similarity", - ]: + + # generate langfuse tags - Default Tags sent to Langfuse from LiteLLM Proxy + if ( + litellm._langfuse_default_tags is not None + and isinstance(litellm._langfuse_default_tags, list) + and key in litellm._langfuse_default_tags + ): tags.append(f"{key}:{value}") # clean litellm metadata before logging @@ -300,10 +300,14 @@ class LangFuseLogger: else: clean_metadata[key] = value - # if user has set proxy_base_url in env -> log to langfuse as a tag - proxy_base_url = os.getenv("PROXY_BASE_URL", None) - if proxy_base_url is not None: - tags.append(f"proxy_base_url:{proxy_base_url}") + if ( + litellm._langfuse_default_tags is not None + and isinstance(litellm._langfuse_default_tags, list) + and "proxy_base_url" in litellm._langfuse_default_tags + ): + proxy_base_url = os.environ.get("PROXY_BASE_URL", None) + if proxy_base_url: + tags.append(f"proxy_base_url:{proxy_base_url}") api_base = litellm_params.get("api_base", None) if api_base: From def5ce4888764ab66c57087e02cc96a5f8958d54 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Apr 2024 16:13:14 -0700 Subject: [PATCH 4/5] fix user needs to opt in to langfuse tags --- litellm/proxy/proxy_config.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index d1bf53a6bf8..cd625564934 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -13,4 +13,8 @@ model_list: general_settings: store_model_in_db: true master_key: sk-1234 - alerting: ["slack"] \ No newline at end of file + alerting: ["slack"] + +litellm_settings: + success_callback: ["langfuse"] + _langfuse_default_tags: ["user_api_key_alias", "user_api_key_user_id", "user_api_key_user_email", "user_api_key_team_alias", "semantic-similarity", "proxy_base_url"] \ No newline at end of file From 788394b1ececf78600e996342efc3c4a724a7fe1 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 19 Apr 2024 16:20:46 -0700 Subject: [PATCH 5/5] fix - logging proxy base url to langfuse --- litellm/integrations/langfuse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 3322fd4c474..38ab9c994b2 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -306,7 +306,7 @@ class LangFuseLogger: and "proxy_base_url" in litellm._langfuse_default_tags ): proxy_base_url = os.environ.get("PROXY_BASE_URL", None) - if proxy_base_url: + if proxy_base_url is not None: tags.append(f"proxy_base_url:{proxy_base_url}") api_base = litellm_params.get("api_base", None)