Skip to content

Max_retries and timeout#126

Open
eeshaKondlapudi wants to merge 1 commit intoagentscope-ai:mainfrom
eeshaKondlapudi:main
Open

Max_retries and timeout#126
eeshaKondlapudi wants to merge 1 commit intoagentscope-ai:mainfrom
eeshaKondlapudi:main

Conversation

@eeshaKondlapudi
Copy link

OpenJudge Version

[The version of OpenJudge you are working on, e.g. import openjudge; print(openjudge.__version__)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with pre-commit run --all-files command
  • All tests are passing
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @eeshaKondlapudi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of OpenAI API interactions by introducing default "timeout" and "max_retries" configurations for the "AsyncOpenAI" client. This ensures that API calls have sensible default retry mechanisms and time limits, improving stability and error handling without requiring explicit configuration from the user unless custom behavior is desired.

Highlights

  • OpenAI Client Configuration: Default "timeout" and "max_retries" values (60.0 seconds and 2 retries, respectively) have been introduced for the "AsyncOpenAI" client within the "OpenAIChatModel" constructor. These defaults are applied if not explicitly provided in "client_args".
  • Test Coverage: New unit tests were added to ensure that custom "timeout" and "max_retries" values are correctly passed to the "AsyncOpenAI" client, and that the newly introduced default values are applied when no custom values are specified.
Changelog
  • openjudge/models/openai_chat_model.py
    • Added "setdefault" calls for "timeout" and "max_retries" to "client_args" with default values of 60.0 and 2, respectively.
  • tests/models/test_openai_chat_model.py
    • Added "test_timeout_and_max_retries_passed" to verify custom "timeout" and "max_retries" are correctly used.
    • Added "test_default_timeout_and_max_retries" to confirm the new default values are applied.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for max_retries and timeout to the OpenAIChatModel. The implementation is a good addition. However, I've found a critical issue in the tests where the new test cases are nested inside another test method, which will prevent them from being discovered and executed by pytest. I've also pointed out a minor formatting issue in the model file.

Comment on lines +299 to +328
@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

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.

Comment on lines +86 to +89
# Add timeout and max_retries defaults if not explicitly provided
client_args.setdefault("timeout", 60.0)
client_args.setdefault("max_retries", 2)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant