Remove setters from options interface
* Add test code
This commit is contained in:
@@ -312,7 +312,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -322,7 +321,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -333,7 +331,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getTopK'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public void setTopK(Integer topK) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'setTopK'");
|
||||
@@ -344,7 +341,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
|
||||
return this.functionCallbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
|
||||
this.functionCallbacks = functionCallbacks;
|
||||
}
|
||||
@@ -354,7 +350,6 @@ public class AzureOpenAiChatOptions implements FunctionCallingOptions, ChatOptio
|
||||
return this.functions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFunctions(Set<String> functions) {
|
||||
this.functions = functions;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,6 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -137,7 +136,6 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
return this.topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = topK;
|
||||
}
|
||||
@@ -147,7 +145,6 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,6 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -154,7 +153,6 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -164,7 +162,6 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
return this.topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = topK;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,6 @@ public class BedrockLlama2ChatOptions implements ChatOptions {
|
||||
throw new UnsupportedOperationException("Unsupported option: 'TopK'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public void setTopK(Integer topK) {
|
||||
throw new UnsupportedOperationException("Unsupported option: 'TopK'");
|
||||
|
||||
@@ -125,7 +125,6 @@ public class BedrockTitanChatOptions implements ChatOptions {
|
||||
throw new UnsupportedOperationException("Bedrock Titian Chat does not support the 'TopK' option.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
throw new UnsupportedOperationException("Bedrock Titian Chat does not support the 'TopK' option.'");
|
||||
}
|
||||
|
||||
@@ -264,7 +264,6 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -274,7 +273,6 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -285,7 +283,6 @@ public class MistralAiChatOptions implements FunctionCallingOptions, ChatOptions
|
||||
throw new UnsupportedOperationException("Unsupported option: 'TopK'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public void setTopK(Integer topK) {
|
||||
throw new UnsupportedOperationException("Unsupported option: 'TopK'");
|
||||
|
||||
@@ -333,7 +333,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -343,7 +342,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -387,7 +385,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
return functions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFunctions(Set<String> functionNames) {
|
||||
this.functions = functionNames;
|
||||
}
|
||||
@@ -515,7 +512,6 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getTopK'");
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public void setTopK(Integer topK) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'setTopK'");
|
||||
|
||||
@@ -190,7 +190,6 @@ public class VertexAiGeminiChatOptions implements FunctionCallingOptions, ChatOp
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -200,7 +199,6 @@ public class VertexAiGeminiChatOptions implements FunctionCallingOptions, ChatOp
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -215,7 +213,6 @@ public class VertexAiGeminiChatOptions implements FunctionCallingOptions, ChatOp
|
||||
this.topK = topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = (topK != null) ? topK.floatValue() : null;
|
||||
|
||||
@@ -98,7 +98,6 @@ public class VertexAiPaLm2ChatOptions implements ChatOptions {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -116,7 +115,6 @@ public class VertexAiPaLm2ChatOptions implements ChatOptions {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -126,7 +124,6 @@ public class VertexAiPaLm2ChatOptions implements ChatOptions {
|
||||
return this.topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = topK;
|
||||
}
|
||||
|
||||
@@ -25,14 +25,8 @@ public interface ChatOptions extends ModelOptions {
|
||||
|
||||
Float getTemperature();
|
||||
|
||||
void setTemperature(Float temperature);
|
||||
|
||||
Float getTopP();
|
||||
|
||||
void setTopP(Float topP);
|
||||
|
||||
Integer getTopK();
|
||||
|
||||
void setTopK(Integer topK);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ public class ChatOptionsBuilder {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -41,7 +40,6 @@ public class ChatOptionsBuilder {
|
||||
return topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -51,7 +49,6 @@ public class ChatOptionsBuilder {
|
||||
return topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = topK;
|
||||
}
|
||||
@@ -86,4 +83,4 @@ public class ChatOptionsBuilder {
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,4 @@ public interface FunctionCallingOptions {
|
||||
return new FunctionCallingOptionsBuilder();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,6 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this.functionCallbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
|
||||
Assert.notNull(functionCallbacks, "FunctionCallbacks must not be null");
|
||||
this.functionCallbacks = functionCallbacks;
|
||||
@@ -109,7 +108,6 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this.functions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFunctions(Set<String> functions) {
|
||||
Assert.notNull(functions, "Functions must not be null");
|
||||
this.functions = functions;
|
||||
@@ -120,7 +118,6 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
@@ -130,7 +127,6 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopP(Float topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
@@ -140,11 +136,10 @@ public class FunctionCallingOptionsBuilder {
|
||||
return this.topK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopK(Integer topK) {
|
||||
this.topK = topK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.chat;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.model.function.FunctionCallbackWrapper;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptions;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder;
|
||||
|
||||
/**
|
||||
* Unit Tests for {@link Prompt}.
|
||||
*
|
||||
* @author youngmon
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public class ChatBuilderTests {
|
||||
|
||||
@Test
|
||||
void createNewChatOptionsTest() {
|
||||
Float temperature = 1.1f;
|
||||
Float topP = 2.2f;
|
||||
Integer topK = 111;
|
||||
|
||||
ChatOptions options = ChatOptionsBuilder.builder()
|
||||
.withTemperature(temperature)
|
||||
.withTopK(topK)
|
||||
.withTopP(topP)
|
||||
.build();
|
||||
|
||||
assertThat(options.getTemperature()).isEqualTo(temperature);
|
||||
assertThat(options.getTopP()).isEqualTo(topP);
|
||||
assertThat(options.getTopK()).isEqualTo(topK);
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateChatOptionsTest() {
|
||||
Float initTemperature = 1.1f;
|
||||
Float initTopP = 2.2f;
|
||||
Integer initTopK = 111;
|
||||
|
||||
ChatOptions options = ChatOptionsBuilder.builder()
|
||||
.withTemperature(initTemperature)
|
||||
.withTopP(initTopP)
|
||||
.withTopK(initTopK)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void createFunctionCallingOptionTest() {
|
||||
Float temperature = 1.1f;
|
||||
Float topP = 2.2f;
|
||||
Integer topK = 111;
|
||||
List<FunctionCallback> functionCallbacks = new ArrayList<>();
|
||||
Set<String> functions = new HashSet<>();
|
||||
|
||||
String func = "func";
|
||||
FunctionCallback cb = FunctionCallbackWrapper.<Integer, Integer>builder(i -> i)
|
||||
.withName("cb")
|
||||
.withDescription("cb")
|
||||
.build();
|
||||
|
||||
functions.add(func);
|
||||
functionCallbacks.add(cb);
|
||||
|
||||
FunctionCallingOptions options = FunctionCallingOptions.builder()
|
||||
.withFunctionCallbacks(functionCallbacks)
|
||||
.withFunctions(functions)
|
||||
.withTopK(topK)
|
||||
.withTopP(topP)
|
||||
.withTemperature(temperature)
|
||||
.build();
|
||||
|
||||
// Callback Functions
|
||||
assertThat(options.getFunctionCallbacks()).isNotNull();
|
||||
assertThat(options.getFunctionCallbacks().size()).isEqualTo(1);
|
||||
assertThat(options.getFunctionCallbacks().contains(cb));
|
||||
|
||||
// Functions
|
||||
assertThat(options.getFunctions()).isNotNull();
|
||||
assertThat(options.getFunctions().size()).isEqualTo(1);
|
||||
assertThat(options.getFunctions().contains(func));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user