mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(databricks): reject a text part holding a non-string locally with a clear 400
This commit is contained in:
parent
807ac1ecca
commit
6676285789
3 changed files with 18 additions and 10 deletions
|
|
@ -189,8 +189,11 @@ def _is_empty_text_block(block: object) -> bool:
|
|||
match block:
|
||||
case {"type": "text", "text": str() as text}:
|
||||
return not text.strip()
|
||||
case {"type": "text", "text": object() as text}:
|
||||
return not text
|
||||
case {"type": "text", "text": object() as text} if text:
|
||||
raise DatabricksException(
|
||||
status_code=400,
|
||||
message=f"A text content block needs a string 'text', got {type(text).__name__}",
|
||||
)
|
||||
case {"type": "text"}:
|
||||
return True
|
||||
case _:
|
||||
|
|
|
|||
|
|
@ -1616,7 +1616,7 @@ def test_databricks_non_string_text_block_is_rejected_before_reaching_upstream(g
|
|||
)
|
||||
received: Final = wire.drain()
|
||||
assert response.status_code == 400, response.text
|
||||
assert "'int' object has no attribute 'strip'" in response.text
|
||||
assert "A text content block needs a string 'text', got int" in response.text
|
||||
assert received == ()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from litellm.constants import (
|
|||
DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET,
|
||||
)
|
||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler
|
||||
from litellm.llms.databricks.common_utils import DatabricksException
|
||||
from litellm.llms.databricks.chat.transformation import (
|
||||
DatabricksChatResponseIterator,
|
||||
DatabricksConfig,
|
||||
|
|
@ -701,14 +702,18 @@ def test_transform_request_joins_plain_text_blocks_only_for_hosted_non_claude_js
|
|||
assert _outgoing_messages(model, messages, optional_params) == [{"role": "user", "content": expected_content}]
|
||||
|
||||
|
||||
def test_transform_request_keeps_a_text_block_whose_text_is_a_truthy_non_string() -> None:
|
||||
block: Final = {"type": "text", "text": 7}
|
||||
@pytest.mark.parametrize("response_format", [None, {"type": "json_object"}], ids=["no-response-format", "json-object"])
|
||||
def test_transform_request_rejects_a_text_block_whose_text_is_a_truthy_non_string(
|
||||
response_format: dict[str, str] | None,
|
||||
) -> None:
|
||||
with pytest.raises(DatabricksException) as error:
|
||||
_outgoing_messages(
|
||||
"databricks-meta-llama-3-3-70b-instruct",
|
||||
[{"role": "user", "content": [{"type": "text", "text": "Reply in JSON"}, {"type": "text", "text": 7}]}],
|
||||
{} if response_format is None else {"response_format": response_format},
|
||||
)
|
||||
|
||||
assert _outgoing_messages(
|
||||
"databricks-meta-llama-3-3-70b-instruct",
|
||||
[{"role": "user", "content": [block]}],
|
||||
{},
|
||||
) == [{"role": "user", "content": [block]}]
|
||||
assert error.value.status_code == 400
|
||||
|
||||
|
||||
def test_transform_request_json_object_keeps_earlier_turns_as_sent() -> None:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue