Skip to content

feat(google-genai): add timeout and max_retries to chat generator#2875

Merged
bogdankostic merged 4 commits intodeepset-ai:mainfrom
Keyur-S-Patel:feat/google-genai-chat-timeout-retries
Mar 3, 2026
Merged

feat(google-genai): add timeout and max_retries to chat generator#2875
bogdankostic merged 4 commits intodeepset-ai:mainfrom
Keyur-S-Patel:feat/google-genai-chat-timeout-retries

Conversation

@Keyur-S-Patel
Copy link
Copy Markdown
Contributor

@Keyur-S-Patel Keyur-S-Patel commented Feb 25, 2026

Related Issues

Proposed Changes:

  • Added timeout and max_retries to GoogleGenAIChatGenerator.__init__.
  • Extended _get_client(...) to accept timeout and max_retries.
  • Implemented SDK-native HTTP config:
    • types.HttpRetryOptions(attempts=max_retries)
    • types.HttpOptions(timeout=<milliseconds>, retry_options=...)
    • passed to genai.Client(..., http_options=...).
  • Added separate handling for timeout and retries before constructing HttpOptions.
  • Stored and serialized the new fields on GoogleGenAIChatGenerator.
  • Updated unit tests to validate:
    • _get_client forwarding through http_options
    • chat generator init/serde behavior with new fields.

How did you test it?

  • hatch run test:unit tests/test_utils.py
  • hatch run test:unit tests/test_chat_generator.py

All selected unit tests passed on this branch.

Notes for the reviewer

  • Timeout is converted from seconds to milliseconds for HttpOptions.
  • The implementation follows the Google GenAI client pattern (http_options + retry policy) rather than passing raw top-level kwargs.

Checklist

@Keyur-S-Patel Keyur-S-Patel requested a review from a team as a code owner February 25, 2026 11:09
@Keyur-S-Patel Keyur-S-Patel requested review from bogdankostic and removed request for a team February 25, 2026 11:09
@github-actions github-actions Bot added integration:google-genai type:documentation Improvements or additions to documentation labels Feb 25, 2026
@Keyur-S-Patel
Copy link
Copy Markdown
Contributor Author

@anakin87 Can you help me close this PR, its similar to the one you reviewed here

Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Keyur-S-Patel! I just have a small comment on how the PR can be improved.

Comment on lines 73 to 80
if http_options is not None:
return Client(
vertexai=True,
project=vertex_ai_project,
location=vertex_ai_location,
http_options=http_options,
)
return Client(vertexai=True, project=vertex_ai_project, location=vertex_ai_location)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the SDK accepts http_options=None (default), we can simplify this branch by always passing http_options=http_options

Suggested change
if http_options is not None:
return Client(
vertexai=True,
project=vertex_ai_project,
location=vertex_ai_location,
http_options=http_options,
)
return Client(vertexai=True, project=vertex_ai_project, location=vertex_ai_location)
return Client(vertexai=True, project=vertex_ai_project, location=vertex_ai_location, http_options=http_options)

Comment on lines 85 to 87
if http_options is not None:
return Client(vertexai=True, api_key=resolved_api_key, http_options=http_options)
return Client(vertexai=True, api_key=resolved_api_key)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if http_options is not None:
return Client(vertexai=True, api_key=resolved_api_key, http_options=http_options)
return Client(vertexai=True, api_key=resolved_api_key)
return Client(vertexai=True, api_key=resolved_api_key, http_options=http_options)

Comment on lines 94 to 96
if http_options is not None:
return Client(api_key=resolved_api_key, http_options=http_options)
return Client(api_key=resolved_api_key)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if http_options is not None:
return Client(api_key=resolved_api_key, http_options=http_options)
return Client(api_key=resolved_api_key)
return Client(api_key=resolved_api_key, http_options=http_options)

Copy link
Copy Markdown
Contributor Author

@Keyur-S-Patel Keyur-S-Patel left a comment

Choose a reason for hiding this comment

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

Address the feedback regarding None branch

Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Keyur-S-Patel, looking good :)

@bogdankostic bogdankostic merged commit 81b2660 into deepset-ai:main Mar 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:google-genai type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose timeout and max_retries in ChatGenerators to help work around rate limits

2 participants