mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(passthrough): match image URL schemes case-insensitively when counting relayed prompt tokens
This commit is contained in:
parent
12d9413860
commit
02b18b4fc6
2 changed files with 12 additions and 1 deletions
|
|
@ -105,7 +105,9 @@ def _is_remote_high_detail_image(part: object) -> bool:
|
|||
if not isinstance(image_url, Mapping):
|
||||
return False
|
||||
url: Final = image_url.get("url")
|
||||
return isinstance(url, str) and url.startswith(("http://", "https://")) and image_url.get("detail") == "high"
|
||||
return (
|
||||
isinstance(url, str) and url.lower().startswith(("http://", "https://")) and image_url.get("detail") == "high"
|
||||
)
|
||||
|
||||
|
||||
def _content_parts(message: Mapping[str, object]) -> Sequence[object]:
|
||||
|
|
|
|||
|
|
@ -2083,3 +2083,12 @@ def test_count_relayed_prompt_tokens_charges_only_the_remote_high_detail_image_a
|
|||
assert count_relayed_prompt_tokens("gpt-4.1-mini", messages) == (
|
||||
litellm.token_counter(model="gpt-4.1-mini", messages=TEXT_ONLY_MESSAGES) + high_detail_image_token_upper_bound()
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("scheme", ["HTTPS://", "Http://"])
|
||||
def test_count_relayed_prompt_tokens_charges_an_uppercase_scheme_remote_high_detail_image_at_the_upper_bound(scheme):
|
||||
messages = _image_messages(scheme + UNREACHABLE_IMAGE_URL.split("://", 1)[1], "high")
|
||||
|
||||
assert count_relayed_prompt_tokens("gpt-4.1-mini", messages) == (
|
||||
litellm.token_counter(model="gpt-4.1-mini", messages=TEXT_ONLY_MESSAGES) + high_detail_image_token_upper_bound()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue