Updates to ZhiPuAi model
* Adjust chat api request options and add unit test Fix options of zhipu ai chat model
This commit is contained in:
@@ -23,7 +23,6 @@ import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.model.function.FunctionCallback;
|
||||
import org.springframework.ai.model.function.FunctionCallingOptions;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionRequest.ResponseFormat;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.FunctionTool;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -47,40 +46,13 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
* ID of the model to use.
|
||||
*/
|
||||
private @JsonProperty("model") String model;
|
||||
/**
|
||||
* Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
|
||||
* frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
||||
*/
|
||||
private @JsonProperty("frequency_penalty") Float frequencyPenalty;
|
||||
/**
|
||||
* The maximum number of tokens to generate in the chat completion. The total length of input
|
||||
* tokens and generated tokens is limited by the model's context length.
|
||||
*/
|
||||
private @JsonProperty("max_tokens") Integer maxTokens;
|
||||
/**
|
||||
* How many chat completion choices to generate for each input message. Note that you will be charged based
|
||||
* on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
|
||||
*/
|
||||
private @JsonProperty("n") Integer n;
|
||||
/**
|
||||
* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they
|
||||
* appear in the text so far, increasing the model's likelihood to talk about new topics.
|
||||
*/
|
||||
private @JsonProperty("presence_penalty") Float presencePenalty;
|
||||
/**
|
||||
* An object specifying the format that the model must output. Setting to { "type":
|
||||
* "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
|
||||
*/
|
||||
private @JsonProperty("response_format") ResponseFormat responseFormat;
|
||||
/**
|
||||
* This feature is in Beta. If specified, our system will make a best effort to sample
|
||||
* deterministically, such that repeated requests with the same seed and parameters should return the same result.
|
||||
* Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor
|
||||
* changes in the backend.
|
||||
*/
|
||||
private @JsonProperty("seed") Integer seed;
|
||||
/**
|
||||
* Up to 4 sequences where the API will stop generating further tokens.
|
||||
* The model will stop generating characters specified by stop, and currently only supports a single stop word in the format of ["stop_word1"].
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private @JsonProperty("stop") List<String> stop;
|
||||
@@ -115,6 +87,18 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
* ID length requirement: minimum of 6 characters, maximum of 128 characters.
|
||||
*/
|
||||
private @JsonProperty("user_id") String user;
|
||||
/**
|
||||
* The parameter is passed by the client and must ensure uniqueness.
|
||||
* It is used to distinguish the unique identifier for each request.
|
||||
* If the client does not provide it, the platform will generate it by default.
|
||||
*/
|
||||
private @JsonProperty("request_id") String requestId;
|
||||
/**
|
||||
* When do_sample is set to true, the sampling strategy is enabled.
|
||||
* If do_sample is false, the sampling strategy parameters temperature and top_p will not take effect.
|
||||
* The default value is true.
|
||||
*/
|
||||
private @JsonProperty("do_sample") Boolean doSample;
|
||||
|
||||
/**
|
||||
* ZhiPuAI Tool Function Callbacks to register with the ChatModel.
|
||||
@@ -161,36 +145,11 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFrequencyPenalty(Float frequencyPenalty) {
|
||||
this.options.frequencyPenalty = frequencyPenalty;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMaxTokens(Integer maxTokens) {
|
||||
this.options.maxTokens = maxTokens;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withN(Integer n) {
|
||||
this.options.n = n;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withPresencePenalty(Float presencePenalty) {
|
||||
this.options.presencePenalty = presencePenalty;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withResponseFormat(ResponseFormat responseFormat) {
|
||||
this.options.responseFormat = responseFormat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withSeed(Integer seed) {
|
||||
this.options.seed = seed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withStop(List<String> stop) {
|
||||
this.options.stop = stop;
|
||||
return this;
|
||||
@@ -221,6 +180,16 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRequestId(String requestId) {
|
||||
this.options.requestId = requestId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withDoSample(Boolean doSample) {
|
||||
this.options.doSample = doSample;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
|
||||
this.options.functionCallbacks = functionCallbacks;
|
||||
return this;
|
||||
@@ -252,14 +221,6 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public Float getFrequencyPenalty() {
|
||||
return this.frequencyPenalty;
|
||||
}
|
||||
|
||||
public void setFrequencyPenalty(Float frequencyPenalty) {
|
||||
this.frequencyPenalty = frequencyPenalty;
|
||||
}
|
||||
|
||||
public Integer getMaxTokens() {
|
||||
return this.maxTokens;
|
||||
}
|
||||
@@ -268,38 +229,6 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
this.maxTokens = maxTokens;
|
||||
}
|
||||
|
||||
public Integer getN() {
|
||||
return this.n;
|
||||
}
|
||||
|
||||
public void setN(Integer n) {
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
public Float getPresencePenalty() {
|
||||
return this.presencePenalty;
|
||||
}
|
||||
|
||||
public void setPresencePenalty(Float presencePenalty) {
|
||||
this.presencePenalty = presencePenalty;
|
||||
}
|
||||
|
||||
public ResponseFormat getResponseFormat() {
|
||||
return this.responseFormat;
|
||||
}
|
||||
|
||||
public void setResponseFormat(ResponseFormat responseFormat) {
|
||||
this.responseFormat = responseFormat;
|
||||
}
|
||||
|
||||
public Integer getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public void setSeed(Integer seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public List<String> getStop() {
|
||||
return this.stop;
|
||||
}
|
||||
@@ -350,6 +279,22 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getRequestId() {
|
||||
return requestId;
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
public Boolean getDoSample() {
|
||||
return doSample;
|
||||
}
|
||||
|
||||
public void setDoSample(Boolean doSample) {
|
||||
this.doSample = doSample;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FunctionCallback> getFunctionCallbacks() {
|
||||
return this.functionCallbacks;
|
||||
@@ -374,12 +319,7 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((model == null) ? 0 : model.hashCode());
|
||||
result = prime * result + ((frequencyPenalty == null) ? 0 : frequencyPenalty.hashCode());
|
||||
result = prime * result + ((maxTokens == null) ? 0 : maxTokens.hashCode());
|
||||
result = prime * result + ((n == null) ? 0 : n.hashCode());
|
||||
result = prime * result + ((presencePenalty == null) ? 0 : presencePenalty.hashCode());
|
||||
result = prime * result + ((responseFormat == null) ? 0 : responseFormat.hashCode());
|
||||
result = prime * result + ((seed == null) ? 0 : seed.hashCode());
|
||||
result = prime * result + ((stop == null) ? 0 : stop.hashCode());
|
||||
result = prime * result + ((temperature == null) ? 0 : temperature.hashCode());
|
||||
result = prime * result + ((topP == null) ? 0 : topP.hashCode());
|
||||
@@ -404,42 +344,12 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
}
|
||||
else if (!model.equals(other.model))
|
||||
return false;
|
||||
if (this.frequencyPenalty == null) {
|
||||
if (other.frequencyPenalty != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.frequencyPenalty.equals(other.frequencyPenalty))
|
||||
return false;
|
||||
if (this.maxTokens == null) {
|
||||
if (other.maxTokens != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.maxTokens.equals(other.maxTokens))
|
||||
return false;
|
||||
if (this.n == null) {
|
||||
if (other.n != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.n.equals(other.n))
|
||||
return false;
|
||||
if (this.presencePenalty == null) {
|
||||
if (other.presencePenalty != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.presencePenalty.equals(other.presencePenalty))
|
||||
return false;
|
||||
if (this.responseFormat == null) {
|
||||
if (other.responseFormat != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.responseFormat.equals(other.responseFormat))
|
||||
return false;
|
||||
if (this.seed == null) {
|
||||
if (other.seed != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.seed.equals(other.seed))
|
||||
return false;
|
||||
if (this.stop == null) {
|
||||
if (other.stop != null)
|
||||
return false;
|
||||
@@ -476,6 +386,18 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
}
|
||||
else if (!this.user.equals(other.user))
|
||||
return false;
|
||||
if (this.requestId == null) {
|
||||
if (other.requestId != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.requestId.equals(other.requestId))
|
||||
return false;
|
||||
if (this.doSample == null) {
|
||||
if (other.doSample != null)
|
||||
return false;
|
||||
}
|
||||
else if (!this.doSample.equals(other.doSample))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -493,18 +415,15 @@ public class ZhiPuAiChatOptions implements FunctionCallingOptions, ChatOptions {
|
||||
public static ZhiPuAiChatOptions fromOptions(ZhiPuAiChatOptions fromOptions) {
|
||||
return ZhiPuAiChatOptions.builder()
|
||||
.withModel(fromOptions.getModel())
|
||||
.withFrequencyPenalty(fromOptions.getFrequencyPenalty())
|
||||
.withMaxTokens(fromOptions.getMaxTokens())
|
||||
.withN(fromOptions.getN())
|
||||
.withPresencePenalty(fromOptions.getPresencePenalty())
|
||||
.withResponseFormat(fromOptions.getResponseFormat())
|
||||
.withSeed(fromOptions.getSeed())
|
||||
.withStop(fromOptions.getStop())
|
||||
.withTemperature(fromOptions.getTemperature())
|
||||
.withTopP(fromOptions.getTopP())
|
||||
.withTools(fromOptions.getTools())
|
||||
.withToolChoice(fromOptions.getToolChoice())
|
||||
.withUser(fromOptions.getUser())
|
||||
.withRequestId(fromOptions.getRequestId())
|
||||
.withDoSample(fromOptions.getDoSample())
|
||||
.withFunctionCallbacks(fromOptions.getFunctionCallbacks())
|
||||
.withFunctions(fromOptions.getFunctions())
|
||||
.build();
|
||||
|
||||
@@ -44,7 +44,7 @@ import java.util.function.Predicate;
|
||||
* <a href="https://open.bigmodel.cn/dev/api#text_embedding">ZhiPuAI Embedding API</a>.
|
||||
*
|
||||
* @author Geng Rong
|
||||
* @since 1.0.0 M1
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ZhiPuAiApi {
|
||||
|
||||
@@ -200,20 +200,8 @@ public class ZhiPuAiApi {
|
||||
*
|
||||
* @param messages A list of messages comprising the conversation so far.
|
||||
* @param model ID of the model to use.
|
||||
* @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
|
||||
* frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
||||
* @param maxTokens The maximum number of tokens to generate in the chat completion. The total length of input
|
||||
* tokens and generated tokens is limited by the model's context length.
|
||||
* @param n How many chat completion choices to generate for each input message. Note that you will be charged based
|
||||
* on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
|
||||
* @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they
|
||||
* appear in the text so far, increasing the model's likelihood to talk about new topics.
|
||||
* @param responseFormat An object specifying the format that the model must output. Setting to { "type":
|
||||
* "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
|
||||
* @param seed This feature is in Beta. If specified, our system will make a best effort to sample
|
||||
* deterministically, such that repeated requests with the same seed and parameters should return the same result.
|
||||
* Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor
|
||||
* changes in the backend.
|
||||
* @param stop Up to 4 sequences where the API will stop generating further tokens.
|
||||
* @param stream If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as
|
||||
* they become available, with the stream terminated by a data: [DONE] message.
|
||||
@@ -237,19 +225,16 @@ public class ZhiPuAiApi {
|
||||
public record ChatCompletionRequest (
|
||||
@JsonProperty("messages") List<ChatCompletionMessage> messages,
|
||||
@JsonProperty("model") String model,
|
||||
@JsonProperty("frequency_penalty") Float frequencyPenalty,
|
||||
@JsonProperty("max_tokens") Integer maxTokens,
|
||||
@JsonProperty("n") Integer n,
|
||||
@JsonProperty("presence_penalty") Float presencePenalty,
|
||||
@JsonProperty("response_format") ResponseFormat responseFormat,
|
||||
@JsonProperty("seed") Integer seed,
|
||||
@JsonProperty("stop") List<String> stop,
|
||||
@JsonProperty("stream") Boolean stream,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("top_p") Float topP,
|
||||
@JsonProperty("tools") List<FunctionTool> tools,
|
||||
@JsonProperty("tool_choice") Object toolChoice,
|
||||
@JsonProperty("user") String user) {
|
||||
@JsonProperty("user") String user,
|
||||
@JsonProperty("request_id") String requestId,
|
||||
@JsonProperty("do_sample") Boolean doSample) {
|
||||
|
||||
/**
|
||||
* Shortcut constructor for a chat completion request with the given messages and model.
|
||||
@@ -259,9 +244,8 @@ public class ZhiPuAiApi {
|
||||
* @param temperature What sampling temperature to use, between 0 and 1.
|
||||
*/
|
||||
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model, Float temperature) {
|
||||
this(messages, model, null, null, null, null,
|
||||
null, null, null, false, temperature, null,
|
||||
null, null, null);
|
||||
this(messages, model, null, null, false, temperature, null,
|
||||
null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,9 +258,8 @@ public class ZhiPuAiApi {
|
||||
* as they become available, with the stream terminated by a data: [DONE] message.
|
||||
*/
|
||||
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model, Float temperature, boolean stream) {
|
||||
this(messages, model, null, null, null, null,
|
||||
null, null, null, stream, temperature, null,
|
||||
null, null, null);
|
||||
this(messages, model, null, null, stream, temperature, null,
|
||||
null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,12 +273,11 @@ public class ZhiPuAiApi {
|
||||
*/
|
||||
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
|
||||
List<FunctionTool> tools, Object toolChoice) {
|
||||
this(messages, model, null, null, null, null,
|
||||
null, null, null, false, 0.8f, null,
|
||||
tools, toolChoice, null);
|
||||
this(messages, model, null, null, false, 0.8f, null,
|
||||
tools, toolChoice, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Shortcut constructor for a chat completion request with the given messages, model, tools and tool choice.
|
||||
* Streaming is set to false, temperature to 0.8 and all other parameters are null.
|
||||
*
|
||||
@@ -304,9 +286,8 @@ public class ZhiPuAiApi {
|
||||
* as they become available, with the stream terminated by a data: [DONE] message.
|
||||
*/
|
||||
public ChatCompletionRequest(List<ChatCompletionMessage> messages, Boolean stream) {
|
||||
this(messages, null, null, null, null, null,
|
||||
null, null, null, stream, null, null,
|
||||
null, null, null);
|
||||
this(messages, null, null, null, stream, null, null,
|
||||
null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,13 +17,8 @@ package org.springframework.ai.zhipuai.api;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletion;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionChunk;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.*;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionMessage.Role;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.ChatCompletionRequest;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.Embedding;
|
||||
import org.springframework.ai.zhipuai.api.ZhiPuAiApi.EmbeddingList;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@@ -42,9 +37,20 @@ public class ZhiPuAiApiIT {
|
||||
|
||||
@Test
|
||||
void chatCompletionEntity() {
|
||||
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
|
||||
ResponseEntity<ChatCompletion> response = zhiPuAiApi.chatCompletionEntity(
|
||||
new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-3-turbo", 0.7f, false));
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getBody()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void chatCompletionEntityWithMoreParams() {
|
||||
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
|
||||
ResponseEntity<ChatCompletion> response = zhiPuAiApi
|
||||
.chatCompletionEntity(new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-4-air", 0.7f, false));
|
||||
.chatCompletionEntity(new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-3-turbo", 1024, null,
|
||||
false, 0.95f, 0.7f, null, null, null, "test_request_id", false));
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getBody()).isNotNull();
|
||||
@@ -54,7 +60,7 @@ public class ZhiPuAiApiIT {
|
||||
void chatCompletionStream() {
|
||||
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
|
||||
Flux<ChatCompletionChunk> response = zhiPuAiApi
|
||||
.chatCompletionStream(new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-4-air", 0.7f, true));
|
||||
.chatCompletionStream(new ChatCompletionRequest(List.of(chatCompletionMessage), "glm-3-turbo", 0.7f, true));
|
||||
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.collectList().block()).isNotNull();
|
||||
|
||||
@@ -92,13 +92,12 @@ The prefix `spring.ai.zhipuai.chat` is the property prefix that lets you configu
|
||||
| spring.ai.zhipuai.chat.api-key | Optional overrides the spring.ai.zhipuai.api-key to provide chat specific api-key | -
|
||||
| spring.ai.zhipuai.chat.options.model | This is the ZhiPuAI Chat model to use | `GLM-3-Turbo` (the `GLM-3-Turbo`, `GLM-4`, `GLM-4-Air`, `GLM-4-AirX`, `GLM-4-Flash`, and `GLM-4V` point to the latest model versions)
|
||||
| spring.ai.zhipuai.chat.options.maxTokens | The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. | -
|
||||
| spring.ai.zhipuai.chat.options.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.7
|
||||
| spring.ai.zhipuai.chat.options.topP | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. | 1.0
|
||||
| spring.ai.zhipuai.chat.options.n | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Default value is 1 and cannot be greater than 5. Specifically, when the temperature is very small and close to 0, we can only return 1 result. If n is already set and>1 at this time, service will return an illegal input parameter (invalid_request_error) | 1
|
||||
| spring.ai.zhipuai.chat.options.presencePenalty | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. | 0.0f
|
||||
| spring.ai.zhipuai.chat.options.frequencyPenalty | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. | 0.0f
|
||||
| spring.ai.zhipuai.chat.options.temperature | What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both. | 0.7
|
||||
| spring.ai.zhipuai.chat.options.topP | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.. | 1.0
|
||||
| spring.ai.zhipuai.chat.options.stop | The model will stop generating characters specified by stop, and currently only supports a single stop word in the format of ["stop_word1"] | -
|
||||
| spring.ai.zhipuai.chat.options.user | A unique identifier representing your end-user, which can help ZhiPuAI to monitor and detect abuse. | -
|
||||
| spring.ai.zhipuai.chat.options.requestId | The parameter is passed by the client and must ensure uniqueness. It is used to distinguish the unique identifier for each request. If the client does not provide it, the platform will generate it by default. | -
|
||||
| spring.ai.zhipuai.chat.options.doSample | When do_sample is set to true, the sampling strategy is enabled. If do_sample is false, the sampling strategy parameters temperature and top_p will not take effect. | true
|
||||
|====
|
||||
|
||||
NOTE: You can override the common `spring.ai.zhipuai.base-url` and `spring.ai.zhipuai.api-key` for the `ChatModel` implementations.
|
||||
|
||||
@@ -215,6 +215,8 @@ public class ZhiPuAiPropertiesTests {
|
||||
"spring.ai.zhipuai.chat.options.stop=boza,koza",
|
||||
"spring.ai.zhipuai.chat.options.temperature=0.55",
|
||||
"spring.ai.zhipuai.chat.options.topP=0.56",
|
||||
"spring.ai.zhipuai.chat.options.getRequestId=RequestId",
|
||||
"spring.ai.zhipuai.chat.options.doSample=true",
|
||||
|
||||
// "spring.ai.zhipuai.chat.options.toolChoice.functionName=toolChoiceFunctionName",
|
||||
"spring.ai.zhipuai.chat.options.toolChoice=" + ModelOptionsUtils.toJsonString(ZhiPuAiApi.ChatCompletionRequest.ToolChoiceBuilder.function("toolChoiceFunctionName")),
|
||||
@@ -261,16 +263,12 @@ public class ZhiPuAiPropertiesTests {
|
||||
assertThat(embeddingProperties.getOptions().getModel()).isEqualTo("Embedding-2");
|
||||
|
||||
assertThat(chatProperties.getOptions().getModel()).isEqualTo("MODEL_XYZ");
|
||||
assertThat(chatProperties.getOptions().getFrequencyPenalty()).isEqualTo(-1.5f);
|
||||
assertThat(chatProperties.getOptions().getMaxTokens()).isEqualTo(123);
|
||||
assertThat(chatProperties.getOptions().getN()).isEqualTo(10);
|
||||
assertThat(chatProperties.getOptions().getPresencePenalty()).isEqualTo(0);
|
||||
assertThat(chatProperties.getOptions().getResponseFormat())
|
||||
.isEqualTo(new ZhiPuAiApi.ChatCompletionRequest.ResponseFormat("json"));
|
||||
assertThat(chatProperties.getOptions().getSeed()).isEqualTo(66);
|
||||
assertThat(chatProperties.getOptions().getStop()).contains("boza", "koza");
|
||||
assertThat(chatProperties.getOptions().getTemperature()).isEqualTo(0.55f);
|
||||
assertThat(chatProperties.getOptions().getTopP()).isEqualTo(0.56f);
|
||||
assertThat(chatProperties.getOptions().getRequestId()).isEqualTo("RequestId");
|
||||
assertThat(chatProperties.getOptions().getDoSample()).isEqualTo(Boolean.TRUE);
|
||||
|
||||
JSONAssert.assertEquals("{\"type\":\"function\",\"function\":{\"name\":\"toolChoiceFunctionName\"}}",
|
||||
chatProperties.getOptions().getToolChoice(), JSONCompareMode.LENIENT);
|
||||
|
||||
Reference in New Issue
Block a user