The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge branch 'main' into litellm_fix_vertex_ai_ft_models
Ishaan Jaffbaa9b3495067
diff --cc tests/local_testing/test_amazing_vertex_completion.pyindex 3687212e844,5e3ebf6a668..86f7e83dacf--- a/tests/local_testing/test_amazing_vertex_completion.py+++ b/tests/local_testing/test_amazing_vertex_completion.py@@@ -3329,93 -3330,44 +3330,136 @@@ def test_signed_s3_url_with_format()assert "image/png" not in json_str+def test_gemini_fine_tuned_model_request_consistency():+ """+ Assert the same transformation is applied to Fine tuned gemini 2.0 flash and gemini 2.0 flash++ - Request 1: Fine tuned: vertex_ai/ft-uuid with base_model: vertex_ai/gemini-2.0-flash-001+ - Request 2: vertex_ai/gemini-2.0-flash-001+ """+ litellm.set_verbose = True+ load_vertex_ai_credentials()+ from litellm.llms.custom_httpx.http_handler import HTTPHandler+ from unittest.mock import patch, MagicMock++ # Set up the messages+ messages = [+ {+ "role": "system",+ "content": "Your name is Litellm Bot, you are a helpful assistant",+ },+ {+ "role": "user",+ "content": "Hello, what is your name and can you tell me the weather?",+ },+ ]++ # Define tools+ tools = [+ {+ "type": "function",+ "function": {+ "name": "get_weather",+ "description": "Get the current weather in a given location",+ "parameters": {+ "type": "object",+ "properties": {+ "location": {+ "type": "string",+ "description": "The city and state, e.g. San Francisco, CA",+ }+ },+ "required": ["location"],+ },+ },+ }+ ]++ client = HTTPHandler(concurrent_limit=1)++ # First request+ with patch.object(client, "post", new=MagicMock()) as mock_post_1:+ try:+ response_1 = completion(+ model="vertex_ai/gemini/ft-uuid",+ messages=messages,+ tools=tools,+ tool_choice="auto",+ client=client,+ )++ except Exception as e:+ print(e)++ # Store the request body from the first call+ first_request_body = mock_post_1.call_args.kwargs["json"]+ print("first_request_body", first_request_body)++ # Second request+ with patch.object(client, "post", new=MagicMock()) as mock_post_2:+ try:+ response_2 = completion(+ model="vertex_ai/gemini-2.0-flash-001",+ messages=messages,+ tools=tools,+ tool_choice="auto",+ client=client,+ )+ except Exception as e:+ print(e)++ # Store the request body from the second call+ second_request_body = mock_post_2.call_args.kwargs["json"]+ print("second_request_body", second_request_body)++ # Get the diff between the two request bodies+ # Convert dictionaries to formatted JSON strings+ import json++ first_json = json.dumps(first_request_body, indent=2).splitlines()+ second_json = json.dumps(second_request_body, indent=2).splitlines()+ # Assert there is no difference between the request bodies+ assert first_json == second_json, "Request bodies should be identical"+++++ @pytest.mark.parametrize("provider", ["vertex_ai", "gemini"])+ @pytest.mark.parametrize("route", ["completion", "embedding", "image_generation"])+ def test_litellm_api_base(monkeypatch, provider, route):+ from litellm.llms.custom_httpx.http_handler import HTTPHandler++ client = HTTPHandler()++ import litellm++ monkeypatch.setattr(litellm, "api_base", "https://litellm.com")++ load_vertex_ai_credentials()++ if route == "image_generation" and provider == "gemini":+ pytest.skip("Gemini does not support image generation")++ with patch.object(client, "post", new=MagicMock()) as mock_client:+ try:+ if route == "completion":+ response = completion(+ model=f"{provider}/gemini-2.0-flash-001",+ messages=[{"role": "user", "content": "Hello, world!"}],+ client=client,+ )+ elif route == "embedding":+ response = embedding(+ model=f"{provider}/gemini-2.0-flash-001",+ input=["Hello, world!"],+ client=client,+ )+ elif route == "image_generation":+ response = image_generation(+ model=f"{provider}/gemini-2.0-flash-001",+ prompt="Hello, world!",+ client=client,+ )+ except Exception as e:+ print(e)++ mock_client.assert_called()+ assert mock_client.call_args.kwargs["url"].startswith("https://litellm.com")