Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openjudge/models/openai_chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def __init__(

# Initialize client
client_args = client_args or {}

# Add timeout and max_retries defaults if not explicitly provided
client_args.setdefault("timeout", 60.0)
client_args.setdefault("max_retries", 2)

Comment on lines +86 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are a couple of minor formatting issues here:

  1. The comment on line 86 has an extra space at the beginning, causing it to be misaligned with the code block it describes.
  2. The blank line on line 89 is unnecessary and can be removed for better readability.
Suggested change
# Add timeout and max_retries defaults if not explicitly provided
client_args.setdefault("timeout", 60.0)
client_args.setdefault("max_retries", 2)
# Add timeout and max_retries defaults if not explicitly provided
client_args.setdefault("timeout", 60.0)
client_args.setdefault("max_retries", 2)

if api_key:
client_args["api_key"] = api_key
else:
Expand Down
31 changes: 31 additions & 0 deletions tests/models/test_openai_chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,37 @@ def test_qwen_omni_audio_formatting(self):
"data:;base64,",
)

@patch("openjudge.models.openai_chat_model.AsyncOpenAI")
def test_timeout_and_max_retries_passed(self, mock_async_openai):
"""Test that timeout and max_retries are passed to AsyncOpenAI."""
OpenAIChatModel(
model="gpt-4",
api_key="test-key",
client_args={
"timeout": 30.0,
"max_retries": 3,
},
)

_, kwargs = mock_async_openai.call_args

assert kwargs["timeout"] == 30.0
assert kwargs["max_retries"] == 3

@patch("openjudge.models.openai_chat_model.AsyncOpenAI")
def test_default_timeout_and_max_retries(self, mock_async_openai):
"""Test that default timeout and max_retries are applied."""
OpenAIChatModel(
model="gpt-4",
api_key="test-key",
)

_, kwargs = mock_async_openai.call_args

assert kwargs["timeout"] == 60.0
assert kwargs["max_retries"] == 2

Comment on lines +299 to +328
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

These new test methods are defined inside test_qwen_omni_audio_formatting. Because they are nested, pytest will not discover or run them.

To fix this, please move test_timeout_and_max_retries_passed and test_default_timeout_and_max_retries to be methods of the TestOpenAIChatModel class, at the same indentation level as test_qwen_omni_audio_formatting.



if __name__ == "__main__":
pytest.main([__file__])