Use Double instead of Float for portable ChatOptions

This change updates the type of portable chat options from Float to
Double. Affected options include:
- frequencyPenalty
- presencePenalty
- temperature
- topP

The motivation for this change is to simplify coding. In Java, Float
values require an "f" suffix (e.g., 0.5f), while Double values don't
need any suffix. This makes Double easier to type and reduces
potential errors from forgetting the "f" suffix.

APIs, tests, and documentation have been updated to reflect this
change.

Fixes gh-712

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit is contained in:
Thomas Vitale
2024-09-08 23:24:48 +02:00
committed by Mark Pollack
parent 40714c984d
commit 4b123a7516
146 changed files with 731 additions and 717 deletions

View File

@@ -296,12 +296,12 @@ AnthropicMessage chatCompletionMessage = new AnthropicMessage(
// Sync request
ResponseEntity<ChatCompletionResponse> response = anthropicApi
.chatCompletionEntity(new ChatCompletionRequest(AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue(),
List.of(chatCompletionMessage), null, 100, 0.8f, false));
List.of(chatCompletionMessage), null, 100, 0.8, false));
// Streaming request
Flux<StreamResponse> response = anthropicApi
.chatCompletionStream(new ChatCompletionRequest(AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue(),
List.of(chatCompletionMessage), null, 100, 0.8f, true));
List.of(chatCompletionMessage), null, 100, 0.8, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api/AnthropicApi.java[AnthropicApi.java]'s JavaDoc for further information.

View File

@@ -312,7 +312,7 @@ var openAIClient = new OpenAIClientBuilder()
var openAIChatOptions = AzureOpenAiChatOptions.builder()
.withDeploymentName("gpt-4o")
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build();

View File

@@ -204,9 +204,9 @@ AnthropicChatBedrockApi anthropicApi = new AnthropicChatBedrockApi(
BedrockAnthropicChatModel chatModel = new BedrockAnthropicChatModel(anthropicApi,
AnthropicChatOptions.builder()
.withTemperature(0.6f)
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.8f)
.withTopP(0.8)
.withMaxTokensToSample(100)
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
@@ -238,7 +238,7 @@ AnthropicChatBedrockApi anthropicChatApi = new AnthropicChatBedrockApi(
AnthropicChatRequest request = AnthropicChatRequest
.builder(String.format(AnthropicChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
.withTemperature(0.8f)
.withTemperature(0.8)
.withMaxTokensToSample(300)
.withTopK(10)
.build();

View File

@@ -245,9 +245,9 @@ Anthropic3ChatBedrockApi anthropicApi = new Anthropic3ChatBedrockApi(
BedrockAnthropic3ChatModel chatModel = new BedrockAnthropic3ChatModel(anthropicApi,
AnthropicChatOptions.builder()
.withTemperature(0.6f)
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.8f)
.withTopP(0.8)
.withMaxTokensToSample(100)
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
@@ -275,7 +275,7 @@ Anthropic3ChatBedrockApi anthropicChatApi = new Anthropic3ChatBedrockApi(
AnthropicChatRequest request = AnthropicChatRequest
.builder(String.format(Anthropic3ChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
.withTemperature(0.8f)
.withTemperature(0.8)
.withMaxTokensToSample(300)
.withTopK(10)
.build();

View File

@@ -195,11 +195,11 @@ CohereChatBedrockApi api = new CohereChatBedrockApi(CohereChatModel.COHERE_COMMA
BedrockCohereChatModel chatModel = new BedrockCohereChatModel(api,
BedrockCohereChatOptions.builder()
.withTemperature(0.6f)
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.5f)
.withTopP(0.5)
.withMaxTokens(678)
.build()
.build());
ChatResponse response = chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -231,8 +231,8 @@ CohereChatBedrockApi cohereChatApi = new CohereChatBedrockApi(
var request = CohereChatRequest
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
.withStream(false)
.withTemperature(0.5f)
.withTopP(0.8f)
.withTemperature(0.5)
.withTopP(0.8)
.withTopK(15)
.withMaxTokens(100)
.withStopSequences(List.of("END"))
@@ -247,8 +247,8 @@ CohereChatResponse response = cohereChatApi.chatCompletion(request);
var request = CohereChatRequest
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
.withStream(true)
.withTemperature(0.5f)
.withTopP(0.8f)
.withTemperature(0.5)
.withTopP(0.8)
.withTopK(15)
.withMaxTokens(100)
.withStopSequences(List.of("END"))

View File

@@ -183,9 +183,9 @@ Ai21Jurassic2ChatBedrockApi api = new Ai21Jurassic2ChatBedrockApi(Ai21Jurassic2C
BedrockAi21Jurassic2ChatModel chatModel = new BedrockAi21Jurassic2ChatModel(api,
BedrockAi21Jurassic2ChatOptions.builder()
.withTemperature(0.5f)
.withTemperature(0.5)
.withMaxTokens(100)
.withTopP(0.9f).build());
.withTopP(0.9).build());
ChatResponse response = chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -209,8 +209,8 @@ Ai21Jurassic2ChatBedrockApi jurassic2ChatApi = new Ai21Jurassic2ChatBedrockApi(
Duration.ofMillis(1000L));
Ai21Jurassic2ChatRequest request = Ai21Jurassic2ChatRequest.builder("Hello, my name is")
.withTemperature(0.9f)
.withTopP(0.9f)
.withTemperature(0.9)
.withTopP(0.9)
.withMaxTokens(20)
.build();

View File

@@ -193,9 +193,9 @@ LlamaChatBedrockApi api = new LlamaChatBedrockApi(LlamaChatModel.LLAMA2_70B_CHAT
BedrockLlamaChatModel chatModel = new BedrockLlamaChatModel(api,
BedrockLlamaChatOptions.builder()
.withTemperature(0.5f)
.withTemperature(0.5)
.withMaxGenLen(100)
.withTopP(0.9f).build());
.withTopP(0.9).build());
ChatResponse response = chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -225,8 +225,8 @@ LlamaChatBedrockApi llamaChatApi = new LlamaChatBedrockApi(
Duration.ofMillis(1000L));
LlamaChatRequest request = LlamaChatRequest.builder("Hello, my name is")
.withTemperature(0.9f)
.withTopP(0.9f)
.withTemperature(0.9)
.withTopP(0.9)
.withMaxGenLen(20)
.build();

View File

@@ -192,8 +192,8 @@ TitanChatBedrockApi titanApi = new TitanChatBedrockApi(
BedrockTitanChatModel chatModel = new BedrockTitanChatModel(titanApi,
BedrockTitanChatOptions.builder()
.withTemperature(0.6f)
.withTopP(0.8f)
.withTemperature(0.6)
.withTopP(0.8)
.withMaxTokenCount(100)
.build());
@@ -223,8 +223,8 @@ TitanChatBedrockApi titanBedrockApi = new TitanChatBedrockApi(TitanChatCompletio
Region.EU_CENTRAL_1.id(), Duration.ofMillis(1000L));
TitanChatRequest titanChatRequest = TitanChatRequest.builder("Give me the names of 3 famous pirates?")
.withTemperature(0.5f)
.withTopP(0.9f)
.withTemperature(0.5)
.withTopP(0.9)
.withMaxTokenCount(100)
.withStopSequences(List.of("|"))
.build();

View File

@@ -122,7 +122,7 @@ ChatResponse response = chatModel.call(
"Generate the names of 5 famous pirates.",
MiniMaxChatOptions.builder()
.withModel(MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue())
.withTemperature(0.5f)
.withTemperature(0.5)
.build()
));
----
@@ -205,7 +205,7 @@ var miniMaxApi = new MiniMaxApi(System.getenv("MINIMAX_API_KEY"));
var chatModel = new MiniMaxChatModel(miniMaxApi, MiniMaxChatOptions.builder()
.withModel(MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue())
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build());
@@ -236,11 +236,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = miniMaxApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue(), 0.7f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue(), 0.7, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = miniMaxApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue(), 0.7f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), MiniMaxApi.ChatModel.ABAB_5_5_Chat.getValue(), 0.7, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/api/MiniMaxApi.java[MiniMaxApi.java]'s JavaDoc for further information.

View File

@@ -128,7 +128,7 @@ ChatResponse response = chatModel.call(
"Generate the names of 5 famous pirates.",
MistralAiChatOptions.builder()
.withModel(MistralAiApi.ChatModel.LARGE.getValue())
.withTemperature(0.5f)
.withTemperature(0.5)
.build()
));
----
@@ -226,7 +226,7 @@ var mistralAiApi = new MistralAiApi(System.getenv("MISTRAL_AI_API_KEY"));
var chatModel = new MistralAiChatModel(mistralAiApi, MistralAiChatOptions.builder()
.withModel(MistralAiApi.ChatModel.LARGE.getValue())
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build());
@@ -257,11 +257,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = mistralAiApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), MistralAiApi.ChatModel.LARGE.getValue(), 0.8f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), MistralAiApi.ChatModel.LARGE.getValue(), 0.8, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = mistralAiApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), MistralAiApi.ChatModel.LARGE.getValue(), 0.8f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), MistralAiApi.ChatModel.LARGE.getValue(), 0.8, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java[MistralAiApi.java]'s JavaDoc for further information.

View File

@@ -121,7 +121,7 @@ ChatResponse response = chatModel.call(
"Generate the names of 5 famous pirates.",
MoonshotChatOptions.builder()
.withModel(MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue())
.withTemperature(0.5f)
.withTemperature(0.5)
.build()
));
----
@@ -204,7 +204,7 @@ var moonshotApi = new MoonshotApi(System.getenv("MOONSHOT_API_KEY"));
var chatModel = new MoonshotChatModel(moonshotApi, MoonshotChatOptions.builder()
.withModel(MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue())
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build());
@@ -235,11 +235,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = moonshotApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue(), 0.7f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue(), 0.7, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = moonshotApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue(), 0.7f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue(), 0.7, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-moonshot/src/main/java/org/springframework/ai/moonshot/api/MoonshotApi.java[MoonshotApi.java]'s JavaDoc for further information.

View File

@@ -278,7 +278,7 @@ var ollamaApi = new OllamaApi();
var chatModel = new OllamaChatModel(ollamaApi,
OllamaOptions.create()
.withModel(OllamaOptions.DEFAULT_MODEL)
.withTemperature(0.9f));
.withTemperature(0.9));
ChatResponse response = chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -318,7 +318,7 @@ var request = ChatRequest.builder("orca-mini")
.withContent("What is the capital of Bulgaria and what is the size? "
+ "What is the national anthem?")
.build()))
.withOptions(OllamaOptions.create().withTemperature(0.9f))
.withOptions(OllamaOptions.create().withTemperature(0.9))
.build();
ChatResponse response = ollamaApi.chat(request);
@@ -329,7 +329,7 @@ var request2 = ChatRequest.builder("orca-mini")
.withMessages(List.of(Message.builder(Role.USER)
.withContent("What is the capital of Bulgaria and what is the size? " + "What is the national anthem?")
.build()))
.withOptions(OllamaOptions.create().withTemperature(0.9f).toMap())
.withOptions(OllamaOptions.create().withTemperature(0.9).toMap())
.build();
Flux<ChatResponse> streamingResponse = ollamaApi.streamingChat(request2);

View File

@@ -429,11 +429,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = openAiApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), "gpt-3.5-turbo", 0.8f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), "gpt-3.5-turbo", 0.8, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = openAiApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), "gpt-3.5-turbo", 0.8f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), "gpt-3.5-turbo", 0.8, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java[OpenAiApi.java]'s JavaDoc for further information.

View File

@@ -124,7 +124,7 @@ ChatResponse response = chatClient.call(
"Generate the names of 5 famous pirates.",
QianFanChatOptions.builder()
.withModel(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.withTemperature(0.5f)
.withTemperature(0.5)
.build()
));
----
@@ -208,7 +208,7 @@ var qianFanApi = new QianFanApi(System.getenv("QIANFAN_API_KEY"), System.getenv(
var chatClient = new QianFanChatModel(qianFanApi, QianFanChatOptions.builder()
.withModel(QianFanApi.ChatModel.ERNIE_Speed_8K.getValue())
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build());
@@ -241,11 +241,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = qianFanApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), systemMessage, QianFanApi.ChatModel.ERNIE_Speed_8K.getValue(), 0.7f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), systemMessage, QianFanApi.ChatModel.ERNIE_Speed_8K.getValue(), 0.7, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = qianFanApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), systemMessage, QianFanApi.ChatModel.ERNIE_Speed_8K.getValue(), 0.7f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), systemMessage, QianFanApi.ChatModel.ERNIE_Speed_8K.getValue(), 0.7, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-qianfan/src/main/java/org/springframework/ai/qianfan/api/QianFanApi.java[QianFanApi.java]'s JavaDoc for further information.

View File

@@ -122,7 +122,7 @@ ChatResponse response = chatModel.call(
"Generate the names of 5 famous pirates.",
ZhiPuAiChatOptions.builder()
.withModel(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue())
.withTemperature(0.5f)
.withTemperature(0.5)
.build()
));
----
@@ -205,7 +205,7 @@ var zhiPuAiApi = new ZhiPuAiApi(System.getenv("ZHIPU_AI_API_KEY"));
var chatModel = new ZhiPuAiChatModel(zhiPuAiApi, ZhiPuAiChatOptions.builder()
.withModel(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue())
.withTemperature(0.4f)
.withTemperature(0.4)
.withMaxTokens(200)
.build());
@@ -236,11 +236,11 @@ ChatCompletionMessage chatCompletionMessage =
// Sync request
ResponseEntity<ChatCompletion> response = zhiPuAiApi.chatCompletionEntity(
new ChatCompletionRequest(List.of(chatCompletionMessage), ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue(), 0.7f, false));
new ChatCompletionRequest(List.of(chatCompletionMessage), ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue(), 0.7, false));
// Streaming request
Flux<ChatCompletionChunk> streamResponse = zhiPuAiApi.chatCompletionStream(
new ChatCompletionRequest(List.of(chatCompletionMessage), ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue(), 0.7f, true));
new ChatCompletionRequest(List.of(chatCompletionMessage), ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue(), 0.7, true));
----
Follow the https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/api/ZhiPuAiApi.java[ZhiPuAiApi.java]'s JavaDoc for further information.

View File

@@ -1,6 +1,10 @@
[[upgrade-notes]]
= Upgrading Notes
== Upgrading to 1.0.0.RC1
* The type of the portable chat options (`frequencyPenalty`, `presencePenalty`, `temperature`, `topP`) has been changed from `Float` to `Double`.
== Upgrading to 1.0.0.M2
* The configuration prefix for the Chroma Vector Store has been changes from `spring.ai.vectorstore.chroma.store` to `spring.ai.vectorstore.chroma` in order to align with the naming conventions of other vector stores.