From 451b1a5fe08c9e419238c2099b3065fac2389791 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 13 Apr 2024 17:17:07 -0700 Subject: [PATCH 1/4] fix - instantly propogate langfuse callback shange --- litellm/proxy/proxy_server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index c376437bb9..6b73a39205 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -8123,7 +8123,7 @@ async def update_config(config_info: ConfigYAML): Currently supports modifying General Settings + LiteLLM settings """ - global llm_router, llm_model_list, general_settings, proxy_config, proxy_logging_obj, master_key + global llm_router, llm_model_list, general_settings, proxy_config, proxy_logging_obj, master_key, prisma_client try: import base64 @@ -8191,6 +8191,12 @@ async def update_config(config_info: ConfigYAML): # Save the updated config await proxy_config.save_config(new_config=config) + # make sure the change is instantly rolled out for langfuse + if prisma_client is not None: + await proxy_config.add_deployment( + prisma_client=prisma_client, proxy_logging_obj=proxy_logging_obj + ) + # Test new connections ## Slack if "slack" in config.get("general_settings", {}).get("alerting", []): From dbe3cf81ebc86c6af3c88d7e9e779c4363243bdc Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 13 Apr 2024 17:24:31 -0700 Subject: [PATCH 2/4] fix - show default langfuse host value --- .../src/components/settings.tsx | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/ui/litellm-dashboard/src/components/settings.tsx b/ui/litellm-dashboard/src/components/settings.tsx index 28e273d219..25ccb5070e 100644 --- a/ui/litellm-dashboard/src/components/settings.tsx +++ b/ui/litellm-dashboard/src/components/settings.tsx @@ -147,8 +147,6 @@ const Settings: React.FC = ({ Callback Callback Env Vars - - {/* Test Callback */} @@ -159,29 +157,22 @@ const Settings: React.FC = ({
    - {Object.entries(callback.variables).map(([key, value]) => ( -
  • - {key} - -
  • - ))} + {Object.entries(callback.variables).map(([key, value]) => ( +
  • + {key} + {key === "LANGFUSE_HOST" ? ( +

    default value="https://cloud.langfuse.com"

    + ) : ( +
    + )} + +
  • +))}
-
- - - - - - - - @@ -192,6 +183,7 @@ const Settings: React.FC = ({ + From f2c6f1d83714565e722d48114ede6127ce5c3684 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 13 Apr 2024 17:31:13 -0700 Subject: [PATCH 3/4] ui - edit slack alerting settings --- litellm/proxy/proxy_server.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 6b73a39205..6d5ef1a546 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -8241,6 +8241,7 @@ async def get_config(): config_data = await proxy_config.get_config() _litellm_settings = config_data.get("litellm_settings", {}) + _general_settings = config_data.get("general_settings", {}) environment_variables = config_data.get("environment_variables", {}) # check if "langfuse" in litellm_settings @@ -8283,6 +8284,27 @@ async def get_config(): {"name": _callback, "variables": _langfuse_env_vars} ) + # Check if slack alerting is on + _alerting = _general_settings.get("alerting", []) + if "slack" in _alerting: + _slack_vars = [ + "SLACK_WEBHOOK_URL", + ] + _slack_env_vars = {} + for _var in _slack_vars: + env_variable = environment_variables.get(_var, None) + if env_variable is None: + _slack_env_vars[_var] = None + else: + # decode + decrypt the value + decoded_b64 = base64.b64decode(env_variable) + _decrypted_value = decrypt_value( + value=decoded_b64, master_key=master_key + ) + _slack_env_vars[_var] = _decrypted_value + + _data_to_return.append({"name": "slack", "variables": _slack_env_vars}) + return {"status": "success", "data": _data_to_return} except Exception as e: traceback.print_exc() From 11d1a0fd9515d04b565a0fe3ee91d77acb08d36a Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 13 Apr 2024 17:44:57 -0700 Subject: [PATCH 4/4] test - slack alerting --- litellm/proxy/proxy_server.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 6d5ef1a546..c46b350f88 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -2441,7 +2441,7 @@ class ProxyConfig: - Check if model id's in router already - If not, add to router """ - global llm_router, llm_model_list, master_key + global llm_router, llm_model_list, master_key, general_settings import base64 @@ -2541,7 +2541,7 @@ class ProxyConfig: config_data = await proxy_config.get_config() litellm_settings = config_data.get("litellm_settings", {}) or {} success_callbacks = litellm_settings.get("success_callback", None) - _added_callback = False + if success_callbacks is not None and isinstance(success_callbacks, list): for success_callback in success_callbacks: if success_callback not in litellm.success_callback: @@ -2557,6 +2557,13 @@ class ProxyConfig: verbose_proxy_logger.error( "Error setting env variable: %s - %s", k, str(e) ) + + # general_settings + _general_settings = config_data.get("general_settings", {}) + if "alerting" in _general_settings: + general_settings["alerting"] = _general_settings["alerting"] + proxy_logging_obj.alerting = general_settings["alerting"] + except Exception as e: verbose_proxy_logger.error( "{}\nTraceback:{}".format(str(e), traceback.format_exc()) @@ -8379,7 +8386,7 @@ async def test_endpoint(request: Request): ) async def health_services_endpoint( user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), - service: Literal["slack_budget_alerts", "langfuse"] = fastapi.Query( + service: Literal["slack_budget_alerts", "langfuse", "slack"] = fastapi.Query( description="Specify the service being hit." ), ): @@ -8395,7 +8402,7 @@ async def health_services_endpoint( raise HTTPException( status_code=400, detail={"error": "Service must be specified."} ) - if service not in ["slack_budget_alerts", "langfuse"]: + if service not in ["slack_budget_alerts", "langfuse", "slack"]: raise HTTPException( status_code=400, detail={ @@ -8422,6 +8429,10 @@ async def health_services_endpoint( if "slack" in general_settings.get("alerting", []): test_message = f"""\n🚨 `ProjectedLimitExceededError` 💸\n\n`Key Alias:` litellm-ui-test-alert \n`Expected Day of Error`: 28th March \n`Current Spend`: $100.00 \n`Projected Spend at end of month`: $1000.00 \n`Soft Limit`: $700""" await proxy_logging_obj.alerting_handler(message=test_message, level="Low") + return { + "status": "success", + "message": "Mock Slack Alert sent, verify Slack Alert Received on your channel", + } else: raise HTTPException( status_code=422,