Skip to content

remove unnecessary Assert.notNull which caused ChatClient.create to fail #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
import java.util.Map;
import java.util.Set;

import com.azure.ai.openai.models.AzureChatEnhancementConfiguration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallingOptions;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;
import org.stringtemplate.v4.compiler.CodeGenerator.primary_return;

import com.azure.ai.openai.models.AzureChatEnhancementConfiguration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* The configuration information for a chat completions request. Completions support a
Expand Down Expand Up @@ -283,7 +282,6 @@ public Builder withFunction(String functionName) {
}

public Builder withResponseFormat(AzureOpenAiResponseFormat responseFormat) {
Assert.notNull(responseFormat, "responseFormat must not be null");
this.options.responseFormat = responseFormat;
return this;
}
Expand All @@ -294,25 +292,21 @@ public Builder withProxyToolCalls(Boolean proxyToolCalls) {
}

public Builder withSeed(Long seed) {
Assert.notNull(seed, "seed must not be null");
this.options.seed = seed;
return this;
}

public Builder withLogprobs(Boolean logprobs) {
Assert.notNull(logprobs, "logprobs must not be null");
this.options.logprobs = logprobs;
return this;
}

public Builder withTopLogprobs(Integer topLogprobs) {
Assert.notNull(topLogprobs, "topLogprobs must not be null");
this.options.topLogProbs = topLogprobs;
return this;
}

public Builder withEnhancements(AzureChatEnhancementConfiguration enhancements) {
Assert.notNull(enhancements, "enhancements must not be null");
this.options.enhancements = enhancements;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@

package org.springframework.ai.azure.openai;

import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.models.AzureChatEnhancementConfiguration;
import com.azure.ai.openai.models.AzureChatOCREnhancementConfiguration;
import com.azure.ai.openai.models.ChatCompletionsJsonResponseFormat;
import com.azure.ai.openai.models.ChatCompletionsTextResponseFormat;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;

import org.springframework.ai.chat.prompt.Prompt;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.models.AzureChatEnhancementConfiguration;
import com.azure.ai.openai.models.ChatCompletionsJsonResponseFormat;
import com.azure.ai.openai.models.ChatCompletionsTextResponseFormat;

/**
* @author Christian Tzolov
Expand Down Expand Up @@ -163,4 +162,18 @@ public void createChatOptionsWithPresencePenaltyAndFrequencyPenalty(Double prese
}
}

@Test
void fromOptionsCheckWithNullValuesExpectSuccess() {
var sourceOptions = AzureOpenAiChatOptions.builder().withMaxTokens(100).withPresencePenalty(0.5).build();

var targetOptions = AzureOpenAiChatOptions.fromOptions(sourceOptions);

assertThat(targetOptions.getMaxTokens()).isEqualTo(100);
assertThat(targetOptions.getPresencePenalty()).isEqualTo(0.5);
assertThat(targetOptions.getFrequencyPenalty()).isNull();
assertThat(targetOptions.getResponseFormat()).isNull();
assertThat(targetOptions.getSeed()).isNull();

}

}