From 33f301ec862065c154c673c0f6f4a193a7866ca4 Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Fri, 3 Jan 2025 14:40:57 -0800 Subject: [PATCH] Litellm dev 01 02 2025 p1 (#7516) * fix(redact_messages.py): fix redact messages for non-model response input to be dictionary fixes issue with otel logging when message redaction is enabled * fix(proxy_server.py): fix langfuse key leak in exception string * test: fix test * test: fix test * test: fix tests --- litellm/litellm_core_utils/redact_messages.py | 2 +- litellm/proxy/_new_secret_config.yaml | 16 ++-------------- litellm/proxy/proxy_server.py | 6 +++++- .../local_testing/test_custom_callback_input.py | 8 +++++--- .../test_logging_redaction_e2e_test.py | 6 +++--- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/litellm/litellm_core_utils/redact_messages.py b/litellm/litellm_core_utils/redact_messages.py index 3be27c44dfd..3d0cec8d727 100644 --- a/litellm/litellm_core_utils/redact_messages.py +++ b/litellm/litellm_core_utils/redact_messages.py @@ -70,7 +70,7 @@ def perform_redaction(model_call_details: dict, result): choice.delta.content = "redacted-by-litellm" return _result else: - return "redacted-by-litellm" + return {"text": "redacted-by-litellm"} def redact_message_input_output_from_logging( diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index dc7bf9d62b3..61dc6774c09 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -1,5 +1,5 @@ model_list: - - model_name: openai/gpt-3.5-turbo + - model_name: azure-embedding-model litellm_params: model: openai/gpt-3.5-turbo api_key: os.environ/OPENAI_API_KEY @@ -12,16 +12,4 @@ model_list: prompt_id: "jokes" litellm_settings: - default_team_settings: - - team_id: "team_1" - success_callback: ["langfuse"] - failure_callback: ["langfuse"] - langfuse_public_key: os.environ/LANGFUSE_PUBLIC_KEY - langfuse_secret: os.environ/LANGFUSE_SECRET_KEY - langfuse_host: os.environ/LANGFUSE_HOST - - team_id: "team_2" - success_callback: ["langfuse"] - failure_callback: ["langfuse"] - langfuse_public_key: os.environ/LANGFUSE_PROJECT3_PUBLIC - langfuse_secret: os.environ/LANGFUSE_PROJECT3_SECRET - langfuse_host: os.environ/LANGFUSE_HOST \ No newline at end of file + callbacks: ["otel"] \ No newline at end of file diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 2760ad9f7aa..0e614b0ae3d 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1862,8 +1862,12 @@ class ProxyConfig: try: TeamDefaultSettings(**team_setting) except Exception: + if isinstance(team_setting, dict): + raise Exception( + f"team_id missing from default_team_settings at index={idx}\npassed in value={team_setting.keys()}" + ) raise Exception( - f"team_id missing from default_team_settings at index={idx}\npassed in value={team_setting}" + f"team_id missing from default_team_settings at index={idx}\npassed in value={type(team_setting)}" ) verbose_proxy_logger.debug( f"{blue_color_code} setting litellm.{key}={value}{reset_color_code}" diff --git a/tests/local_testing/test_custom_callback_input.py b/tests/local_testing/test_custom_callback_input.py index 747174279f8..911defd0b4d 100644 --- a/tests/local_testing/test_custom_callback_input.py +++ b/tests/local_testing/test_custom_callback_input.py @@ -1264,7 +1264,7 @@ def test_standard_logging_payload(model, turn_off_message_logging): if turn_off_message_logging: print("checks redacted-by-litellm") assert "redacted-by-litellm" == slobject["messages"][0]["content"] - assert "redacted-by-litellm" == slobject["response"] + assert {"text": "redacted-by-litellm"} == slobject["response"] @pytest.mark.parametrize( @@ -1358,7 +1358,7 @@ def test_standard_logging_payload_audio(turn_off_message_logging, stream): if turn_off_message_logging: print("checks redacted-by-litellm") assert "redacted-by-litellm" == slobject["messages"][0]["content"] - assert "redacted-by-litellm" == slobject["response"] + assert {"text": "redacted-by-litellm"} == slobject["response"] @pytest.mark.skip(reason="Works locally. Flaky on ci/cd") @@ -1467,7 +1467,9 @@ def test_logging_async_cache_hit_sync_call(turn_off_message_logging): "redacted-by-litellm" == standard_logging_object["messages"][0]["content"] ) - assert "redacted-by-litellm" == standard_logging_object["response"] + assert {"text": "redacted-by-litellm"} == standard_logging_object[ + "response" + ] def test_logging_standard_payload_failure_call(): diff --git a/tests/logging_callback_tests/test_logging_redaction_e2e_test.py b/tests/logging_callback_tests/test_logging_redaction_e2e_test.py index ea821e78806..5a5b720b2e0 100644 --- a/tests/logging_callback_tests/test_logging_redaction_e2e_test.py +++ b/tests/logging_callback_tests/test_logging_redaction_e2e_test.py @@ -45,7 +45,7 @@ async def test_global_redaction_on(): await asyncio.sleep(1) standard_logging_payload = test_custom_logger.logged_standard_logging_payload assert standard_logging_payload is not None - assert standard_logging_payload["response"] == "redacted-by-litellm" + assert standard_logging_payload["response"] == {"text": "redacted-by-litellm"} assert standard_logging_payload["messages"][0]["content"] == "redacted-by-litellm" print( "logged standard logging payload", @@ -75,7 +75,7 @@ async def test_global_redaction_with_dynamic_params(turn_off_message_logging): ) if turn_off_message_logging is True: - assert standard_logging_payload["response"] == "redacted-by-litellm" + assert standard_logging_payload["response"] == {"text": "redacted-by-litellm"} assert ( standard_logging_payload["messages"][0]["content"] == "redacted-by-litellm" ) @@ -108,7 +108,7 @@ async def test_global_redaction_off_with_dynamic_params(turn_off_message_logging json.dumps(standard_logging_payload, indent=2), ) if turn_off_message_logging is True: - assert standard_logging_payload["response"] == "redacted-by-litellm" + assert standard_logging_payload["response"] == {"text": "redacted-by-litellm"} assert ( standard_logging_payload["messages"][0]["content"] == "redacted-by-litellm" )