[integration][openai] Align default parameters for openai chat model between java and python#883
[integration][openai] Align default parameters for openai chat model between java and python#883rob-9 wants to merge 16 commits into
Conversation
wenjin272
left a comment
There was a problem hiding this comment.
Thanks for taking this on @rob-9. The code looks good to me, but I think we should also update the documentation.
The user-facing docs still describe the old Java defaults. After this PR, Java OpenAI/Azure connections explicitly default to timeout=60 and max_retries=3, but these tables still mention SDK fallback/None and max_retries=2. Please update the docs to match the new constructor behavior.
|
@wenjin272 thx |
98af5a7 to
cf9be98
Compare
| Integer maxRetries = descriptor.getArgument("max_retries"); | ||
| if (maxRetries != null && maxRetries >= 0) { | ||
| builder.maxRetries(maxRetries); | ||
| builder.timeout(Duration.ofSeconds(this.timeoutSeconds)); |
There was a problem hiding this comment.
timeout=0 has opposite semantics in Java and Python. openai-java interprets Duration.ZERO as no timeout, while Python forwards 0.0 to HTTPX as a zero-second timeout. Please define one consistent zero-value contract across both languages and test the effective SDK timeout rather than only the stored field.
The same pattern is also present in AzureOpenAIChatModelConnection and OpenAIResponsesModelConnection.
| builder.timeout(Duration.ofSeconds(timeoutSeconds)); | ||
| this.timeoutSeconds = | ||
| Optional.ofNullable(descriptor.<Number>getArgument("timeout")) | ||
| .map(Number::intValue) |
There was a problem hiding this comment.
Calling Number.intValue() before validation silently truncates or overflows the input. For example, -0.5 becomes 0 and bypasses the negative check, while fractional timeouts lose precision and fractional retry counts differ from Python validation. Please validate the original value first, preserve fractional timeout values, and require an exact bounded integer for max_retries.
The same pattern is also present in AzureOpenAIChatModelConnection and OpenAIResponsesModelConnection.
purpose
the Java OpenAI chat model connections (
OpenAICompletionsConnection,AzureOpenAIChatModelConnection, andOpenAIResponsesModelConnection) didn't set explicit defaults fortimeoutandmax_retries, falling through to the openai-java SDK's internal values. the Python SDK explicitly defaults totimeout=60sandmax_retries=3, meaning the same agent config behaves differently across languages.this PR aligns Java to match Python:
DEFAULT_TIMEOUT_SECONDS = 60/DEFAULT_MAX_RETRIES = 3constants inOpenAIChatCompletionsUtils.Optional.ofNullable(...).orElse(DEFAULT_*)so absent args get the explicit default.IllegalArgumentExceptionat construction time instead of being silently skipped.testing
OpenAICompletionsConnectionTest— asserts correct defaults, explicit overrides, negative rejection, zero acceptance, and api_key validation.OpenAIResponsesModelConnectionTest— same coverage for the Responses API connection.AzureOpenAIChatModelConnectionTestwith default-resolution, override, and boundary assertions.timeout == 60.0andmax_retries == 3.breaking changes
max_retriesdefault changed from 2 → 3 forOpenAICompletionsConnectionandOpenAIResponsesModelConnection.timeout=0was previously silently ignored (SDK default applied); it is now passed through asDuration.ofSeconds(0).docs
doc-not-needed