|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from agents.models.interface import Model |
8 | | -from openai import AsyncAzureOpenAI |
| 8 | +from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel |
| 9 | +from agents.models.openai_responses import OpenAIResponsesModel |
9 | 10 |
|
10 | 11 | from bot.agent import DEFAULT_INSTRUCTIONS |
11 | 12 | from bot.agent import MAX_TURNS |
@@ -162,56 +163,30 @@ def _call_get_model(self, env_vars: dict): |
162 | 163 | with patch.dict("os.environ", env_vars, clear=True): |
163 | 164 | return agent_module._get_model() |
164 | 165 |
|
165 | | - def test_azure_path_when_both_key_and_endpoint_set(self): |
166 | | - env = { |
167 | | - "AZURE_OPENAI_API_KEY": "test-azure-key", |
168 | | - "AZURE_OPENAI_ENDPOINT": "https://my-resource.openai.azure.com", |
169 | | - } |
170 | | - model = self._call_get_model(env) |
171 | | - assert isinstance(model._client, AsyncAzureOpenAI) |
172 | | - |
173 | | - def test_azure_key_without_endpoint_does_not_use_azure(self): |
174 | | - """When AZURE_OPENAI_API_KEY is set but AZURE_OPENAI_ENDPOINT is missing, |
175 | | - should NOT enter the Azure path (and should not crash).""" |
176 | | - env = { |
177 | | - "AZURE_OPENAI_API_KEY": "test-azure-key", |
178 | | - "OPENAI_API_KEY": "fallback-key", |
179 | | - } |
| 166 | + def test_custom_model_name(self): |
| 167 | + env = {"OPENAI_MODEL": "gpt-5.2", "OPENAI_API_KEY": "test-key"} |
180 | 168 | model = self._call_get_model(env) |
181 | | - assert not isinstance(model._client, AsyncAzureOpenAI) |
| 169 | + assert model.model == "gpt-5.2" |
182 | 170 |
|
183 | | - def test_proxy_path_uses_base_url(self): |
184 | | - env = { |
185 | | - "OPENAI_PROXY_BASE_URL": "https://my-proxy.example.com/v1", |
186 | | - "OPENAI_PROXY_API_KEY": "proxy-key", |
187 | | - } |
188 | | - model = self._call_get_model(env) |
189 | | - assert not isinstance(model._client, AsyncAzureOpenAI) |
190 | | - assert str(model._client.base_url).rstrip("/") == "https://my-proxy.example.com/v1" |
191 | | - |
192 | | - def test_proxy_path_without_api_key_uses_openai_key(self): |
193 | | - """Proxy base URL set but no proxy API key — should fall back to OPENAI_API_KEY.""" |
194 | | - env = { |
195 | | - "OPENAI_PROXY_BASE_URL": "https://my-proxy.example.com/v1", |
196 | | - "OPENAI_API_KEY": "fallback-key", |
197 | | - } |
| 171 | + def test_default_model_name(self): |
| 172 | + env = {"OPENAI_API_KEY": "test-key"} |
198 | 173 | model = self._call_get_model(env) |
199 | | - assert str(model._client.base_url).rstrip("/") == "https://my-proxy.example.com/v1" |
| 174 | + assert model.model == "gpt-5.4" |
200 | 175 |
|
201 | | - def test_default_path_uses_vanilla_openai(self): |
| 176 | + def test_returns_responses_model_by_default(self): |
202 | 177 | env = {"OPENAI_API_KEY": "test-key"} |
203 | 178 | model = self._call_get_model(env) |
204 | | - assert not isinstance(model._client, AsyncAzureOpenAI) |
| 179 | + assert isinstance(model, OpenAIResponsesModel) |
205 | 180 |
|
206 | | - def test_custom_model_name(self): |
207 | | - env = {"OPENAI_MODEL": "gpt-5.2", "OPENAI_API_KEY": "test-key"} |
| 181 | + def test_returns_chat_completions_model_when_api_type_set(self): |
| 182 | + env = {"OPENAI_API_KEY": "test-key", "OPENAI_API_TYPE": "chat_completions"} |
208 | 183 | model = self._call_get_model(env) |
209 | | - assert model.model == "gpt-5.2" |
| 184 | + assert isinstance(model, OpenAIChatCompletionsModel) |
210 | 185 |
|
211 | | - def test_default_model_name(self): |
212 | | - env = {"OPENAI_API_KEY": "test-key"} |
| 186 | + def test_returns_chat_completions_when_api_type_set(self): |
| 187 | + env = {"OPENAI_API_KEY": "test-key", "OPENAI_API_TYPE": "chat_completions"} |
213 | 188 | model = self._call_get_model(env) |
214 | | - assert model.model == "gpt-5.4" |
| 189 | + assert isinstance(model, OpenAIChatCompletionsModel) |
215 | 190 |
|
216 | 191 |
|
217 | 192 | class TestFromDict: |
|
0 commit comments