mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-06 07:48:06 +00:00
fix(managed files): answer 400 for a chat file part with no file object instead of 500
This commit is contained in:
parent
2065b40fa5
commit
8cc51b31d7
2 changed files with 24 additions and 3 deletions
|
|
@ -1742,10 +1742,11 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints):
|
|||
continue
|
||||
for c in content:
|
||||
if c.get("type") == "file":
|
||||
file_object = cast(ChatCompletionFileObject, c)
|
||||
file_object_file_field = file_object["file"]
|
||||
file_object_file_field = cast(Dict[str, object], c).get("file")
|
||||
if not isinstance(file_object_file_field, dict):
|
||||
continue
|
||||
file_id = file_object_file_field.get("file_id")
|
||||
if file_id:
|
||||
if isinstance(file_id, str) and file_id:
|
||||
file_ids.append(file_id)
|
||||
return file_ids
|
||||
|
||||
|
|
|
|||
|
|
@ -332,6 +332,26 @@ def test_get_file_ids_from_messages_skips_bedrock_content_blocks_without_type():
|
|||
assert file_ids == ["file-keep"]
|
||||
|
||||
|
||||
def test_get_file_ids_from_messages_leaves_malformed_file_parts_to_request_validation():
|
||||
proxy_managed_files = PROXY_LiteLLMManagedFiles(
|
||||
DualCache(), prisma_client=MagicMock()
|
||||
)
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "file"},
|
||||
{"type": "file", "file": "file-raw"},
|
||||
{"type": "file", "file": None},
|
||||
{"type": "file", "file": {"file_id": 7}},
|
||||
{"type": "file", "file": {"file_id": "file-keep"}},
|
||||
],
|
||||
}
|
||||
]
|
||||
file_ids = proxy_managed_files.get_file_ids_from_messages(messages)
|
||||
assert file_ids == ["file-keep"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_pre_call_hook_batch_retrieve():
|
||||
from litellm.proxy._types import UserAPIKeyAuth
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue