@@ -119,6 +119,46 @@ def test_create_chat_instance_invalid_provider():
119119 _create_chat_instance ("invalid" , "model" )
120120
121121
122+ def test_create_chat_instance_azure_openai_missing_endpoint (monkeypatch ):
123+ """Azure OpenAI provider raises if AZURE_OPENAI_ENDPOINT is unset."""
124+ pytest .importorskip ("openai" )
125+ monkeypatch .delenv ("AZURE_OPENAI_ENDPOINT" , raising = False )
126+ monkeypatch .setenv ("OPENAI_API_VERSION" , "2024-06-01" )
127+ with pytest .raises (ValueError , match = "AZURE_OPENAI_ENDPOINT" ):
128+ _create_chat_instance ("azure-openai" , "my-deployment" )
129+
130+
131+ def test_create_chat_instance_azure_openai_missing_api_version (monkeypatch ):
132+ """Azure OpenAI provider raises if OPENAI_API_VERSION is unset."""
133+ pytest .importorskip ("openai" )
134+ monkeypatch .setenv ("AZURE_OPENAI_ENDPOINT" , "https://example.openai.azure.com" )
135+ monkeypatch .delenv ("OPENAI_API_VERSION" , raising = False )
136+ with pytest .raises (ValueError , match = "OPENAI_API_VERSION" ):
137+ _create_chat_instance ("azure-openai" , "my-deployment" )
138+
139+
140+ def test_create_chat_instance_azure_openai_forwards_params (monkeypatch ):
141+ """Azure OpenAI provider forwards env vars + deployment id to ChatAzureOpenAI."""
142+ pytest .importorskip ("openai" )
143+ chatlas = pytest .importorskip ("chatlas" )
144+ monkeypatch .setenv ("AZURE_OPENAI_ENDPOINT" , "https://example.openai.azure.com" )
145+ monkeypatch .setenv ("OPENAI_API_VERSION" , "2024-06-01" )
146+
147+ sentinel = object ()
148+ with patch .object (chatlas , "ChatAzureOpenAI" , return_value = sentinel ) as mock_cls :
149+ result = _create_chat_instance ("azure-openai" , "my-deployment" , api_key = "secret" )
150+
151+ assert result is sentinel
152+ mock_cls .assert_called_once ()
153+ kwargs = mock_cls .call_args .kwargs
154+ assert kwargs ["endpoint" ] == "https://example.openai.azure.com"
155+ assert kwargs ["deployment_id" ] == "my-deployment"
156+ assert kwargs ["api_version" ] == "2024-06-01"
157+ assert kwargs ["api_key" ] == "secret"
158+ assert "system_prompt" in kwargs
159+ assert "http_client" in kwargs ["kwargs" ]
160+
161+
122162# ============================================================================
123163# Test BatchConfig
124164# ============================================================================
0 commit comments