-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fix(fireworks): skip #transform=inline for base64 data URLs #23729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1125350
2a3801a
19cb9d3
6a3a2d9
37e1885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,6 +110,35 @@ def test_get_supported_openai_params_reasoning_effort(): | |||||||||||||
| assert "reasoning_effort" not in unsupported_params | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def test_add_transform_inline_image_block_skips_data_urls(): | ||||||||||||||
| """ | ||||||||||||||
| data: URLs must not have #transform=inline appended — doing so corrupts the | ||||||||||||||
| base64 payload and raises binascii.Error: Incorrect padding on the Fireworks side. | ||||||||||||||
| Regression test for https://github.com/BerriAI/litellm/issues/23583 | ||||||||||||||
| """ | ||||||||||||||
| config = FireworksAIConfig() | ||||||||||||||
| data_url = "data:image/jpeg;base64,/9j/4AAQSkZJRgAB" | ||||||||||||||
|
|
||||||||||||||
| # str branch | ||||||||||||||
| str_content = {"type": "image_url", "image_url": data_url} | ||||||||||||||
| result = config._add_transform_inline_image_block( | ||||||||||||||
| str_content, model="non-vision-model", disable_add_transform_inline_image_block=False | ||||||||||||||
| ) | ||||||||||||||
| assert result["image_url"] == data_url, "data URL must not be modified (str branch)" | ||||||||||||||
|
|
||||||||||||||
| # dict branch | ||||||||||||||
| dict_content = {"type": "image_url", "image_url": {"url": data_url}} | ||||||||||||||
| result = config._add_transform_inline_image_block( | ||||||||||||||
| dict_content, model="non-vision-model", disable_add_transform_inline_image_block=False | ||||||||||||||
| ) | ||||||||||||||
| assert result["image_url"]["url"] == data_url, "data URL must not be modified (dict branch)" | ||||||||||||||
|
|
||||||||||||||
| # regular https URL should still get the suffix | ||||||||||||||
| https_content = {"type": "image_url", "image_url": "https://example.com/image.jpg"} | ||||||||||||||
| result = config._add_transform_inline_image_block( | ||||||||||||||
| https_content, model="non-vision-model", disable_add_transform_inline_image_block=False | ||||||||||||||
| ) | ||||||||||||||
| assert result["image_url"].endswith("#transform=inline"), "https URL should get #transform=inline" | ||||||||||||||
| @pytest.mark.parametrize( | ||||||||||||||
|
Comment on lines
+141
to
142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
PEP 8 requires two blank lines between top-level definitions. There is no blank line between the closing assert of
Suggested change
|
||||||||||||||
| "api_base, expected_url_prefix", | ||||||||||||||
| [ | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test cases for the data: URL fix
The fix adds guards for both the
stranddictbranches, but no test cases were added to validate this behaviour. The existingtest_transform_inlineparametrized test intests/llm_translation/test_fireworks_ai_translation.pycovers HTTP URLs and vision-model bypass, but has no coverage fordata:URLs (the exact scenario described in the linked issue).The pre-submission checklist also explicitly requires at least one test in
tests/test_litellm/. Without it, a future refactor could reintroduce the regression silently. The following cases are missing:strbranch:{"image_url": "data:image/png;base64,abc123"}→ URL should remain unchangeddictbranch:{"image_url": {"url": "data:image/jpeg;base64,xyz=="}}→ URL should remain unchangedExample additions to the
test_transform_inlineparametrize list:( {"image_url": "data:image/png;base64,iVBORw0KGgo="}, "gpt-4", "data:image/png;base64,iVBORw0KGgo=", # must not be modified ), ( {"image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ=="}}, "gpt-4", {"url": "data:image/jpeg;base64,/9j/4AAQ=="}, # must not be modified ),Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)