|
1 | 1 | import os |
2 | 2 | import sys |
3 | | -from typing import Any, Dict |
4 | | -from unittest.mock import MagicMock, call, patch |
| 3 | +from unittest.mock import patch |
5 | 4 |
|
6 | 5 | import pytest |
7 | 6 |
|
|
11 | 10 | 0, os.path.abspath("../../..") |
12 | 11 | ) # Adds the parent directory to the system path |
13 | 12 |
|
14 | | -import litellm |
15 | 13 | from litellm.llms.vertex_ai.common_utils import ( |
16 | 14 | _get_vertex_url, |
17 | 15 | convert_anyof_null_to_nullable, |
@@ -798,9 +796,54 @@ def test_fix_enum_empty_strings(): |
798 | 796 | assert "mobile" in enum_values |
799 | 797 | assert "tablet" in enum_values |
800 | 798 |
|
801 | | - # 3. Other properties preserved |
802 | | - assert input_schema["properties"]["user_agent_type"]["type"] == "string" |
803 | | - assert input_schema["properties"]["user_agent_type"]["description"] == "Device type for user agent" |
| 799 | + |
| 800 | +def test_get_vertex_model_id_from_url(): |
| 801 | + """Test get_vertex_model_id_from_url with various URLs""" |
| 802 | + from litellm.llms.vertex_ai.common_utils import get_vertex_model_id_from_url |
| 803 | + |
| 804 | + # Test with valid URL |
| 805 | + url = "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google/models/gemini-pro:streamGenerateContent" |
| 806 | + model_id = get_vertex_model_id_from_url(url) |
| 807 | + assert model_id == "gemini-pro" |
| 808 | + |
| 809 | + # Test with invalid URL |
| 810 | + url = "https://invalid-url.com" |
| 811 | + model_id = get_vertex_model_id_from_url(url) |
| 812 | + assert model_id is None |
| 813 | + |
| 814 | + |
| 815 | +def test_construct_target_url_with_version_prefix(): |
| 816 | + """Test construct_target_url with version prefixes""" |
| 817 | + from litellm.llms.vertex_ai.common_utils import construct_target_url |
| 818 | + |
| 819 | + # Test with /v1/ prefix |
| 820 | + url = "/v1/publishers/google/models/gemini-pro:streamGenerateContent" |
| 821 | + vertex_project = "test-project" |
| 822 | + vertex_location = "us-central1" |
| 823 | + base_url = "https://us-central1-aiplatform.googleapis.com" |
| 824 | + |
| 825 | + target_url = construct_target_url( |
| 826 | + base_url=base_url, |
| 827 | + requested_route=url, |
| 828 | + vertex_project=vertex_project, |
| 829 | + vertex_location=vertex_location, |
| 830 | + ) |
| 831 | + |
| 832 | + expected_url = "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/publishers/google/models/gemini-pro:streamGenerateContent" |
| 833 | + assert str(target_url) == expected_url |
| 834 | + |
| 835 | + # Test with /v1beta1/ prefix |
| 836 | + url = "/v1beta1/publishers/google/models/gemini-pro:streamGenerateContent" |
| 837 | + |
| 838 | + target_url = construct_target_url( |
| 839 | + base_url=base_url, |
| 840 | + requested_route=url, |
| 841 | + vertex_project=vertex_project, |
| 842 | + vertex_location=vertex_location, |
| 843 | + ) |
| 844 | + |
| 845 | + expected_url = "https://us-central1-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/us-central1/publishers/google/models/gemini-pro:streamGenerateContent" |
| 846 | + assert str(target_url) == expected_url |
804 | 847 |
|
805 | 848 |
|
806 | 849 | def test_fix_enum_types(): |
@@ -862,7 +905,7 @@ def test_fix_enum_types(): |
862 | 905 | "truncateMode": { |
863 | 906 | "enum": ["auto", "none", "start", "end"], # Kept - string type |
864 | 907 | "type": "string", |
865 | | - "description": "How to truncate content" |
| 908 | + "description": "How to truncate content", |
866 | 909 | }, |
867 | 910 | "maxLength": { # enum removed |
868 | 911 | "type": "integer", |
|
0 commit comments