Skip to content

Commit

Permalink
Litellm dev 01 02 2025 p1 (BerriAI#7516)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
krrishdholakia authored Jan 3, 2025
1 parent fb59f20 commit 33f301e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion litellm/litellm_core_utils/redact_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 2 additions & 14 deletions litellm/proxy/_new_secret_config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
callbacks: ["otel"]
6 changes: 5 additions & 1 deletion litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,12 @@ async def load_config( # noqa: PLR0915
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}"
Expand Down
8 changes: 5 additions & 3 deletions tests/local_testing/test_custom_callback_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down

0 comments on commit 33f301e

Please sign in to comment.