Skip to content

Commit 796964a

Browse files
nileshpatil6GWeale
authored andcommitted
fix(LiteLlm): recognize assistant- prefix as valid OpenAI file ID
Merge #5758 Azure OpenAI files uploaded with `purpose="assistants"` receive IDs with an `assistant-` prefix (e.g. `assistant-abc123`). `_looks_like_openai_file_id` only checked for the `file-` prefix, causing Azure PDF attachments to be silently dropped from requests instead of being routed through the Responses API content block. Fix: extend the `startswith` check to include `"assistant-"`. Also updated `_redact_file_uri_for_log` to return `assistant-<redacted>` for `assistant-` prefixed IDs, consistent with how `file-` IDs are handled. Fixes #5664 ## Testing plan Added unit tests in `tests/unittests/models/test_litellm.py`: - `test_looks_like_openai_file_id` (parametrized) covers: - `file-abc123` -> True (existing behavior) - `assistant-abc123` -> True (new behavior) - `https://example.com/file.pdf` -> False - `not-a-file-id` -> False - empty string -> False - `FILE-abc123` -> False (case sensitive) - `test_redact_file_uri_for_log_openai_prefixes` (parametrized): - `file-abc123` -> `file-<redacted>` - `assistant-abc123` -> `assistant-<redacted>` (new behavior) - `test_redact_file_uri_for_log_uses_display_name_when_provided` confirms `display_name` short-circuits redaction. - `test_redact_file_uri_for_log_http_url_keeps_scheme_and_tail` confirms HTTP URLs still redact host but preserve scheme and filename. Run locally with: ``` pytest tests/unittests/models/test_litellm.py -k "looks_like_openai_file_id or redact_file_uri_for_log" ``` Co-authored-by: George Weale <gweale@google.com> COPYBARA_INTEGRATE_REVIEW=#5758 from nileshpatil6:fix/lite-llm-assistant-file-id-prefix 6b2afd7 PiperOrigin-RevId: 933898777
1 parent 2b7e08a commit 796964a

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/google/adk/models/lite_llm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ def _redact_file_uri_for_log(
395395
"""Returns a privacy-preserving identifier for logs."""
396396
if display_name:
397397
return display_name
398+
if file_uri.startswith("assistant-"):
399+
return "assistant-<redacted>"
398400
if _looks_like_openai_file_id(file_uri):
399401
return "file-<redacted>"
400402
try:

tests/unittests/models/test_litellm.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
from google.adk.models.lite_llm import _get_content
4141
from google.adk.models.lite_llm import _get_provider_from_model
4242
from google.adk.models.lite_llm import _is_anthropic_model
43+
from google.adk.models.lite_llm import _looks_like_openai_file_id
4344
from google.adk.models.lite_llm import _message_to_generate_content_response
4445
from google.adk.models.lite_llm import _MISSING_TOOL_RESULT_MESSAGE
4546
from google.adk.models.lite_llm import _model_response_to_chunk
4647
from google.adk.models.lite_llm import _model_response_to_generate_content_response
4748
from google.adk.models.lite_llm import _parse_tool_calls_from_text
49+
from google.adk.models.lite_llm import _redact_file_uri_for_log
4850
from google.adk.models.lite_llm import _redirect_litellm_loggers_to_stdout
4951
from google.adk.models.lite_llm import _safe_json_serialize
5052
from google.adk.models.lite_llm import _schema_to_dict
@@ -5124,3 +5126,44 @@ async def test_generate_content_async_skips_request_log_build_above_debug(
51245126
assert mock_build.called is should_call
51255127
finally:
51265128
litellm_logger.setLevel(original_level)
5129+
5130+
5131+
@pytest.mark.parametrize(
5132+
"file_uri, expected",
5133+
[
5134+
("file-abc123", True),
5135+
("assistant-abc123", True),
5136+
("https://example.com/file.pdf", False),
5137+
("not-a-file-id", False),
5138+
("", False),
5139+
("FILE-abc123", False),
5140+
],
5141+
)
5142+
def test_looks_like_openai_file_id(file_uri, expected):
5143+
"""Both `file-` and `assistant-` (Azure assistants) prefixes count as OpenAI file IDs."""
5144+
assert _looks_like_openai_file_id(file_uri) is expected
5145+
5146+
5147+
@pytest.mark.parametrize(
5148+
"file_uri, expected",
5149+
[
5150+
("file-abc123", "file-<redacted>"),
5151+
("assistant-abc123", "assistant-<redacted>"),
5152+
],
5153+
)
5154+
def test_redact_file_uri_for_log_openai_prefixes(file_uri, expected):
5155+
"""OpenAI-style IDs are redacted while preserving the prefix kind."""
5156+
assert _redact_file_uri_for_log(file_uri) == expected
5157+
5158+
5159+
def test_redact_file_uri_for_log_uses_display_name_when_provided():
5160+
assert (
5161+
_redact_file_uri_for_log("file-abc123", display_name="my.pdf") == "my.pdf"
5162+
)
5163+
5164+
5165+
def test_redact_file_uri_for_log_http_url_keeps_scheme_and_tail():
5166+
assert (
5167+
_redact_file_uri_for_log("https://example.com/path/file.pdf")
5168+
== "https://<redacted>/file.pdf"
5169+
)

0 commit comments

Comments
 (0)