Skip to content

Commit 571b3f5

Browse files
Fix tests for Azure OpenAI models, add GPT-4.1-nano (#286)
* fix tests for openai azure models after changes. add gpt-4.1-nano * update test models to 4.1 nano * formatting
1 parent 0b1eb18 commit 571b3f5

File tree

8 files changed

+57
-6
lines changed

8 files changed

+57
-6
lines changed

src/agentlab/agents/generic_agent/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
AGENT_AZURE_4o_MINI_VISION,
2929
AGENT_AZURE_41,
3030
AGENT_AZURE_41_MINI,
31+
AGENT_AZURE_41_NANO,
3132
AGENT_AZURE_41_VISION,
3233
AGENT_AZURE_41_MINI_VISION,
34+
AGENT_AZURE_41_NANO_VISION,
3335
AGENT_AZURE_5,
3436
AGENT_AZURE_5_MINI,
3537
AGENT_AZURE_5_NANO,
@@ -66,8 +68,10 @@
6668
"AGENT_AZURE_4o_MINI_VISION",
6769
"AGENT_AZURE_41",
6870
"AGENT_AZURE_41_MINI",
71+
"AGENT_AZURE_41_NANO",
6972
"AGENT_AZURE_41_VISION",
7073
"AGENT_AZURE_41_MINI_VISION",
74+
"AGENT_AZURE_41_NANO_VISION",
7175
"AGENT_AZURE_5",
7276
"AGENT_AZURE_5_MINI",
7377
"AGENT_AZURE_5_NANO",

src/agentlab/agents/generic_agent/agent_configs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@
279279
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-4.1-mini-2025-04-14"],
280280
flags=FLAGS_GPT_4o,
281281
)
282+
AGENT_AZURE_41_NANO = GenericAgentArgs(
283+
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-4.1-nano-2025-04-14"],
284+
flags=FLAGS_GPT_4o,
285+
)
282286

283287
AGENT_AZURE_5 = GenericAgentArgs(
284288
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-5-2025-08-07"],
@@ -350,6 +354,10 @@
350354
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-4.1-mini-2025-04-14"],
351355
flags=FLAGS_GPT_4o_VISION,
352356
)
357+
AGENT_AZURE_41_NANO_VISION = GenericAgentArgs(
358+
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-4.1-nano-2025-04-14"],
359+
flags=FLAGS_GPT_4o_VISION,
360+
)
353361

354362
AGENT_AZURE_5_VISION = GenericAgentArgs(
355363
chat_model_args=CHAT_MODEL_ARGS_DICT["azure/gpt-5-2025-08-07"],

src/agentlab/llm/chat_api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def make_model(self):
110110
class AzureModelArgs(BaseModelArgs):
111111
"""Serializable object for instantiating a generic chat model with an Azure model."""
112112

113+
deployment_name: str = (
114+
None # NOTE: deployment_name is deprecated for Azure OpenAI and won't be used.
115+
)
116+
113117
def make_model(self):
114118
return AzureChatModel(
115119
model_name=self.model_name,
@@ -396,13 +400,25 @@ def __init__(
396400
model_name,
397401
api_key=None,
398402
temperature=0.5,
403+
deployment_name=None,
399404
max_tokens=100,
400405
max_retry=4,
401406
min_retry_wait_time=60,
402407
log_probs=False,
403408
):
409+
api_key = api_key or os.getenv("AZURE_OPENAI_API_KEY")
410+
assert (
411+
api_key
412+
), "AZURE_OPENAI_API_KEY has to be defined in the environment when using AzureChatModel"
404413
endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
405-
assert endpoint, "AZURE_OPENAI_ENDPOINT has to be defined in the environment"
414+
assert (
415+
endpoint
416+
), "AZURE_OPENAI_ENDPOINT has to be defined in the environment when using AzureChatModel"
417+
418+
if deployment_name is not None:
419+
logging.info(
420+
f"Deployment name is deprecated for Azure OpenAI and won't be used. Using model name: {model_name}."
421+
)
406422

407423
client_args = {
408424
"base_url": endpoint,
@@ -411,7 +427,6 @@ def __init__(
411427
super().__init__(
412428
model_name=model_name,
413429
api_key=api_key,
414-
api_key_env_var="AZURE_OPENAI_API_KEY",
415430
temperature=temperature,
416431
max_tokens=max_tokens,
417432
max_retry=max_retry,

src/agentlab/llm/llm_configs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
temperature=1, # gpt-5 supports temperature of 1 only
4545
vision_support=True,
4646
),
47+
"openai/gpt-4.1-nano-2025-04-14": OpenAIModelArgs(
48+
model_name="gpt-4.1-nano-2025-04-14",
49+
max_total_tokens=128_000,
50+
max_input_tokens=128_000,
51+
max_new_tokens=16_384,
52+
vision_support=True,
53+
),
4754
"openai/gpt-4.1-mini-2025-04-14": OpenAIModelArgs(
4855
model_name="gpt-4.1-mini-2025-04-14",
4956
max_total_tokens=128_000,
@@ -160,6 +167,13 @@
160167
max_new_tokens=16_384,
161168
vision_support=True,
162169
),
170+
"azure/gpt-4.1-nano-2025-04-14": AzureModelArgs(
171+
model_name="gpt-4.1-nano",
172+
max_total_tokens=128_000,
173+
max_input_tokens=128_000,
174+
max_new_tokens=16_384,
175+
vision_support=True,
176+
),
163177
"azure/gpt-5-2025-08-07": AzureModelArgs(
164178
model_name="gpt-5",
165179
max_total_tokens=400_000,

tests/llm/test_chat_api.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121

2222
@pytest.mark.pricy
2323
@pytest.mark.skipif(skip_tests, reason="Skipping on remote as Azure is pricy")
24+
@pytest.mark.skipif(
25+
not os.getenv("AZURE_OPENAI_API_KEY"), reason="Skipping as Azure API key not set"
26+
)
2427
def test_api_model_args_azure():
2528
model_args = AzureModelArgs(
26-
model_name="gpt-35-turbo",
27-
deployment_name="gpt-35-turbo",
29+
model_name="gpt-4.1-nano",
30+
deployment_name="gpt-4.1-nano",
2831
max_total_tokens=8192,
2932
max_input_tokens=8192 - 512,
3033
max_new_tokens=512,
@@ -43,6 +46,7 @@ def test_api_model_args_azure():
4346

4447
@pytest.mark.pricy
4548
@pytest.mark.skipif(skip_tests, reason="Skipping on remote as Azure is pricy")
49+
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason="Skipping as OpenAI API key not set")
4650
def test_api_model_args_openai():
4751
model_args = OpenAIModelArgs(
4852
model_name="gpt-4o-mini",
@@ -64,6 +68,9 @@ def test_api_model_args_openai():
6468

6569
@pytest.mark.pricy
6670
@pytest.mark.skipif(skip_tests, reason="Skipping on remote as Anthropic is pricy")
71+
@pytest.mark.skipif(
72+
not os.getenv("ANTHROPIC_API_KEY"), reason="Skipping as Anthropic API key not set"
73+
)
6774
def test_api_model_args_anthropic():
6875
model_args = AnthropicModelArgs(
6976
model_name="claude-3-haiku-20240307",

tests/llm/test_litellm_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import os
12
from functools import partial
23

34
import pytest
4-
55
from agentlab.llm.litellm_api import LiteLLMModelArgs
66
from agentlab.llm.response_api import APIPayload, LLMOutput
77

@@ -106,6 +106,7 @@ def test_multi_action_tool_calls():
106106

107107

108108
@pytest.mark.pricy
109+
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason="Skipping as OpenAI API key not set")
109110
def test_single_tool_call():
110111
"""
111112
Test that the LLMOutput contains only one tool call when use_only_first_toolcall is True.
@@ -137,6 +138,7 @@ def test_single_tool_call():
137138

138139

139140
@pytest.mark.pricy
141+
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason="Skipping as OpenAI API key not set")
140142
def test_force_tool_call():
141143
"""
142144
Test that the model can produce a specific tool call when requested.

tests/llm/test_response_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ def test_claude_model_with_multiple_messages_pricy_call():
686686

687687
## Test multiaction
688688
@pytest.mark.pricy
689+
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason="Skipping as OpenAI API key not set")
689690
def test_multi_action_tool_calls():
690691
"""
691692
Test that the model can produce multiple tool calls in parallel.

tests/llm/test_tracking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_openai_chat_model():
146146
not AZURE_OPENAI_API_KEY_AVAILABLE, reason="Azure OpenAI API key is not available"
147147
)
148148
def test_azure_chat_model():
149-
chat_model = AzureChatModel(model_name="gpt-35-turbo", deployment_name="gpt-35-turbo")
149+
chat_model = AzureChatModel(model_name="gpt-4.1-nano", deployment_name="gpt-4.1-nano")
150150
assert chat_model.input_cost > 0
151151
assert chat_model.output_cost > 0
152152

0 commit comments

Comments
 (0)