Thank you for taking time to contribute this pull request! You might have already read the [contributor guide][1], but as a reminder, please make sure to:
- Sign the contributor license agreement ✅
- Rebase your changes on the latest
main
branch and squash your commits ✅ - Add/Update unit tests as needed ✅
- Run a build and make sure all tests pass prior to submission ✅
I discovered a null safety issue while working with spring-ai in Kotlin.
The AzureOpenAiChatOptions
builder does not handle null values properly.
Specifically, the withFrequencyPenalty
and withPresencePenalty
methods call doubleValue()
without checking if the parameter is null.
Here is the problematic code:
public Builder withFrequencyPenalty(Float frequencyPenalty) {
this.options.frequencyPenalty = frequencyPenalty.doubleValue();
return this;
}
public Builder withPresencePenalty(Float presencePenalty) {
this.options.presencePenalty = presencePenalty.doubleValue();
return this;
}
I managed to work around this issue in Kotlin by ensuring null safety as shown below:
val chatOptions = this.chatOptions?.let {
AzureOpenAiChatOptions().apply {
maxTokens = it.maxTokens
temperature = it.temperature
topP = it.topP
logitBias = it.logitBias
user = it.user
n = it.n
stop = it.stop
presencePenalty = it.presencePenalty?.toDouble() // like this
frequencyPenalty = it.frequencyPenalty?.toDouble() // like this
}
}
...
However, I believe it would be beneficial to address this issue at its source. Therefore, I am submitting this pull request with additional test cases to highlight and resolve this issue.
Comment From: tzolov
Thanks for the improvement @Hyune-c