|
| 1 | +""" |
| 2 | +Unit test for LiteLLM Proxy Responses API configuration. |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from litellm.types.utils import LlmProviders |
| 8 | +from litellm.utils import ProviderConfigManager |
| 9 | + |
| 10 | + |
| 11 | +def test_litellm_proxy_responses_api_config(): |
| 12 | + """Test that litellm_proxy provider returns correct Responses API config""" |
| 13 | + from litellm.llms.litellm_proxy.responses.transformation import ( |
| 14 | + LiteLLMProxyResponsesAPIConfig, |
| 15 | + ) |
| 16 | + |
| 17 | + config = ProviderConfigManager.get_provider_responses_api_config( |
| 18 | + model="litellm_proxy/gpt-4", |
| 19 | + provider=LlmProviders.LITELLM_PROXY, |
| 20 | + ) |
| 21 | + print(f"config: {config}") |
| 22 | + assert config is not None, "Config should not be None for litellm_proxy provider" |
| 23 | + assert isinstance( |
| 24 | + config, LiteLLMProxyResponsesAPIConfig |
| 25 | + ), f"Expected LiteLLMProxyResponsesAPIConfig, got {type(config)}" |
| 26 | + assert ( |
| 27 | + config.custom_llm_provider == LlmProviders.LITELLM_PROXY |
| 28 | + ), "custom_llm_provider should be LITELLM_PROXY" |
| 29 | + |
| 30 | + |
| 31 | +def test_litellm_proxy_responses_api_config_get_complete_url(): |
| 32 | + """Test that get_complete_url works correctly""" |
| 33 | + import os |
| 34 | + from litellm.llms.litellm_proxy.responses.transformation import ( |
| 35 | + LiteLLMProxyResponsesAPIConfig, |
| 36 | + ) |
| 37 | + |
| 38 | + config = LiteLLMProxyResponsesAPIConfig() |
| 39 | + |
| 40 | + # Test with explicit api_base |
| 41 | + url = config.get_complete_url( |
| 42 | + api_base="https://my-proxy.example.com", |
| 43 | + litellm_params={}, |
| 44 | + ) |
| 45 | + assert url == "https://my-proxy.example.com/responses" |
| 46 | + |
| 47 | + # Test with trailing slash |
| 48 | + url = config.get_complete_url( |
| 49 | + api_base="https://my-proxy.example.com/", |
| 50 | + litellm_params={}, |
| 51 | + ) |
| 52 | + assert url == "https://my-proxy.example.com/responses" |
| 53 | + |
| 54 | + # Test that it raises error when api_base is None and env var is not set |
| 55 | + if "LITELLM_PROXY_API_BASE" in os.environ: |
| 56 | + del os.environ["LITELLM_PROXY_API_BASE"] |
| 57 | + |
| 58 | + with pytest.raises(ValueError, match="api_base not set"): |
| 59 | + config.get_complete_url(api_base=None, litellm_params={}) |
| 60 | + |
| 61 | + |
| 62 | +def test_litellm_proxy_responses_api_config_inherits_from_openai(): |
| 63 | + """Test that LiteLLMProxyResponsesAPIConfig extends OpenAI config properly""" |
| 64 | + from litellm.llms.litellm_proxy.responses.transformation import ( |
| 65 | + LiteLLMProxyResponsesAPIConfig, |
| 66 | + ) |
| 67 | + from litellm.llms.openai.responses.transformation import ( |
| 68 | + OpenAIResponsesAPIConfig, |
| 69 | + ) |
| 70 | + |
| 71 | + config = LiteLLMProxyResponsesAPIConfig() |
| 72 | + |
| 73 | + # Should inherit from OpenAI config |
| 74 | + assert isinstance(config, OpenAIResponsesAPIConfig) |
| 75 | + |
| 76 | + # Should have the correct provider set |
| 77 | + assert config.custom_llm_provider == LlmProviders.LITELLM_PROXY |
| 78 | + |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + test_litellm_proxy_responses_api_config() |
| 82 | + test_litellm_proxy_responses_api_config_get_complete_url() |
| 83 | + test_litellm_proxy_responses_api_config_inherits_from_openai() |
| 84 | + print("All tests passed!") |
0 commit comments