From 4b88635372dfafa6503b8e2edcc86ea9bb544946 Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Mon, 20 Jan 2025 20:16:11 -0800 Subject: [PATCH] fix(fireworks_ai/): fix global disable flag with transform messages helper (#7847) fixes issue where .get() = none was preventing global disable flag from being picked up --- .../llms/fireworks_ai/chat/transformation.py | 6 +-- .../test_fireworks_ai_translation.py | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/litellm/llms/fireworks_ai/chat/transformation.py b/litellm/llms/fireworks_ai/chat/transformation.py index ab0555920d..30de3c3ed0 100644 --- a/litellm/llms/fireworks_ai/chat/transformation.py +++ b/litellm/llms/fireworks_ai/chat/transformation.py @@ -143,10 +143,8 @@ class FireworksAIConfig(OpenAIGPTConfig): """ disable_add_transform_inline_image_block = cast( Optional[bool], - litellm_params.get( - "disable_add_transform_inline_image_block", - litellm.disable_add_transform_inline_image_block, - ), + litellm_params.get("disable_add_transform_inline_image_block") + or litellm.disable_add_transform_inline_image_block, ) for message in messages: if message["role"] == "user": diff --git a/tests/llm_translation/test_fireworks_ai_translation.py b/tests/llm_translation/test_fireworks_ai_translation.py index 9a0926abd2..5e1a1c0512 100644 --- a/tests/llm_translation/test_fireworks_ai_translation.py +++ b/tests/llm_translation/test_fireworks_ai_translation.py @@ -196,3 +196,48 @@ def test_global_disable_flag(model, is_disabled, expected_url): ) assert result["image_url"] == expected_url litellm.disable_add_transform_inline_image_block = False # Reset for other tests + + +def test_global_disable_flag_with_transform_messages_helper(monkeypatch): + from openai import OpenAI + from unittest.mock import patch + from litellm import completion + + monkeypatch.setattr(litellm, "disable_add_transform_inline_image_block", True) + + client = OpenAI() + + with patch.object( + client.chat.completions.with_raw_response, + "create", + ) as mock_post: + try: + completion( + model="fireworks_ai/accounts/fireworks/models/llama-v3p3-70b-instruct", + messages=[ + { + "role": "user", + "content": [ + {"type": "text", "text": "What's in this image?"}, + { + "type": "image_url", + "image_url": { + "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" + }, + }, + ], + } + ], + client=client, + ) + except Exception as e: + print(e) + + mock_post.assert_called_once() + print(mock_post.call_args.kwargs) + assert ( + "#transform=inline" + not in mock_post.call_args.kwargs["messages"][0]["content"][1]["image_url"][ + "url" + ] + )