diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatModel.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatModel.java index e3043b1d6bd..3c9163d0fd2 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatModel.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatModel.java @@ -123,8 +123,7 @@ public class ZhiPuAiChatModel extends AbstractToolCallSupport implements ChatMod * @throws IllegalArgumentException if zhiPuAiApi is null */ public ZhiPuAiChatModel(ZhiPuAiApi zhiPuAiApi) { - this(zhiPuAiApi, - ZhiPuAiChatOptions.builder().withModel(ZhiPuAiApi.DEFAULT_CHAT_MODEL).withTemperature(0.7).build()); + this(zhiPuAiApi, ZhiPuAiChatOptions.builder().model(ZhiPuAiApi.DEFAULT_CHAT_MODEL).temperature(0.7).build()); } /** @@ -434,7 +433,7 @@ else if (message.getMessageType() == MessageType.TOOL) { if (!CollectionUtils.isEmpty(enabledToolsToUse)) { request = ModelOptionsUtils.merge( - ZhiPuAiChatOptions.builder().withTools(this.getFunctionTools(enabledToolsToUse)).build(), request, + ZhiPuAiChatOptions.builder().tools(this.getFunctionTools(enabledToolsToUse)).build(), request, ChatCompletionRequest.class); } diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatOptions.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatOptions.java index 70db60e1be0..1758a2f46fd 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatOptions.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiChatOptions.java @@ -37,6 +37,7 @@ * * @author Geng Rong * @author Thomas Vitale + * @author Ilayaperumal Gopinathan * @since 1.0.0 M1 */ @JsonInclude(Include.NON_NULL) @@ -136,20 +137,20 @@ public static Builder builder() { public static ZhiPuAiChatOptions fromOptions(ZhiPuAiChatOptions fromOptions) { return ZhiPuAiChatOptions.builder() - .withModel(fromOptions.getModel()) - .withMaxTokens(fromOptions.getMaxTokens()) - .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()) - .withProxyToolCalls(fromOptions.getProxyToolCalls()) - .withToolContext(fromOptions.getToolContext()) + .model(fromOptions.getModel()) + .maxTokens(fromOptions.getMaxTokens()) + .stop(fromOptions.getStop()) + .temperature(fromOptions.getTemperature()) + .topP(fromOptions.getTopP()) + .tools(fromOptions.getTools()) + .toolChoice(fromOptions.getToolChoice()) + .user(fromOptions.getUser()) + .requestId(fromOptions.getRequestId()) + .doSample(fromOptions.getDoSample()) + .functionCallbacks(fromOptions.getFunctionCallbacks()) + .functions(fromOptions.getFunctions()) + .proxyToolCalls(fromOptions.getProxyToolCalls()) + .toolContext(fromOptions.getToolContext()) .build(); } @@ -449,78 +450,220 @@ public Builder(ZhiPuAiChatOptions options) { this.options = options; } + public Builder model(String model) { + this.options.model = model; + return this; + } + + public Builder maxTokens(Integer maxTokens) { + this.options.maxTokens = maxTokens; + return this; + } + + public Builder stop(List stop) { + this.options.stop = stop; + return this; + } + + public Builder temperature(Double temperature) { + this.options.temperature = temperature; + return this; + } + + public Builder topP(Double topP) { + this.options.topP = topP; + return this; + } + + public Builder tools(List tools) { + this.options.tools = tools; + return this; + } + + public Builder toolChoice(String toolChoice) { + this.options.toolChoice = toolChoice; + return this; + } + + public Builder user(String user) { + this.options.user = user; + return this; + } + + public Builder requestId(String requestId) { + this.options.requestId = requestId; + return this; + } + + public Builder doSample(Boolean doSample) { + this.options.doSample = doSample; + return this; + } + + public Builder functionCallbacks(List functionCallbacks) { + this.options.functionCallbacks = functionCallbacks; + return this; + } + + public Builder functions(Set functionNames) { + Assert.notNull(functionNames, "Function names must not be null"); + this.options.functions = functionNames; + return this; + } + + public Builder function(String functionName) { + Assert.hasText(functionName, "Function name must not be empty"); + this.options.functions.add(functionName); + return this; + } + + public Builder proxyToolCalls(Boolean proxyToolCalls) { + this.options.proxyToolCalls = proxyToolCalls; + return this; + } + + public Builder toolContext(Map toolContext) { + if (this.options.toolContext == null) { + this.options.toolContext = toolContext; + } + else { + this.options.toolContext.putAll(toolContext); + } + return this; + } + + /** + * @deprecated use {@link #model(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withModel(String model) { this.options.model = model; return this; } + /** + * @deprecated use {@link #maxTokens(Integer)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withMaxTokens(Integer maxTokens) { this.options.maxTokens = maxTokens; return this; } + /** + * @deprecated use {@link #stop(List)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withStop(List stop) { this.options.stop = stop; return this; } + /** + * @deprecated use {@link #temperature(Double)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withTemperature(Double temperature) { this.options.temperature = temperature; return this; } + /** + * @deprecated use {@link #topP(Double)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withTopP(Double topP) { this.options.topP = topP; return this; } + /** + * @deprecated use {@link #tools(List)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withTools(List tools) { this.options.tools = tools; return this; } + /** + * @deprecated use {@link #toolChoice(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withToolChoice(String toolChoice) { this.options.toolChoice = toolChoice; return this; } + /** + * @deprecated use {@link #user(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withUser(String user) { this.options.user = user; return this; } + /** + * @deprecated use {@link #requestId(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withRequestId(String requestId) { this.options.requestId = requestId; return this; } + /** + * @deprecated use {@link #doSample(Boolean)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withDoSample(Boolean doSample) { this.options.doSample = doSample; return this; } + /** + * @deprecated use {@link #functionCallbacks(List)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withFunctionCallbacks(List functionCallbacks) { this.options.functionCallbacks = functionCallbacks; return this; } + /** + * @deprecated use {@link #functions(Set)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withFunctions(Set functionNames) { Assert.notNull(functionNames, "Function names must not be null"); this.options.functions = functionNames; return this; } + /** + * @deprecated use {@link #function(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withFunction(String functionName) { Assert.hasText(functionName, "Function name must not be empty"); this.options.functions.add(functionName); return this; } + /** + * @deprecated use {@link #proxyToolCalls(Boolean)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withProxyToolCalls(Boolean proxyToolCalls) { this.options.proxyToolCalls = proxyToolCalls; return this; } + /** + * @deprecated use {@link #toolContext(Map)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withToolContext(Map toolContext) { if (this.options.toolContext == null) { this.options.toolContext = toolContext; diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingModel.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingModel.java index 214679c32ec..eb21c21ea50 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingModel.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingModel.java @@ -90,7 +90,7 @@ public ZhiPuAiEmbeddingModel(ZhiPuAiApi zhiPuAiApi) { */ public ZhiPuAiEmbeddingModel(ZhiPuAiApi zhiPuAiApi, MetadataMode metadataMode) { this(zhiPuAiApi, metadataMode, - ZhiPuAiEmbeddingOptions.builder().withModel(ZhiPuAiApi.DEFAULT_EMBEDDING_MODEL).build(), + ZhiPuAiEmbeddingOptions.builder().model(ZhiPuAiApi.DEFAULT_EMBEDDING_MODEL).build(), RetryUtils.DEFAULT_RETRY_TEMPLATE); } @@ -220,7 +220,7 @@ private ZhiPuAiEmbeddingOptions mergeOptions(@Nullable EmbeddingOptions runtimeO } return ZhiPuAiEmbeddingOptions.builder() - .withModel(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel())) + .model(ModelOptionsUtils.mergeOption(runtimeOptionsForProvider.getModel(), defaultOptions.getModel())) .build(); } diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingOptions.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingOptions.java index 02119d53c3b..7855d53fbef 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingOptions.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiEmbeddingOptions.java @@ -28,6 +28,7 @@ * * @author Geng Rong * @author Thomas Vitale + * @author Ilayaperumal Gopinathan * @since 1.0.0 M1 */ @JsonInclude(Include.NON_NULL) @@ -67,6 +68,15 @@ public Builder() { this.options = new ZhiPuAiEmbeddingOptions(); } + public Builder model(String model) { + this.options.setModel(model); + return this; + } + + /** + * @deprecated use {@link #model(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withModel(String model) { this.options.setModel(model); return this; diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageModel.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageModel.java index cb267fd2fd7..5963703d1c8 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageModel.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageModel.java @@ -122,11 +122,11 @@ private ZhiPuAiImageOptions toZhiPuAiImageOptions(ImageOptions runtimeImageOptio ZhiPuAiImageOptions.Builder zhiPuAiImageOptionsBuilder = ZhiPuAiImageOptions.builder(); if (runtimeImageOptions != null) { if (runtimeImageOptions.getModel() != null) { - zhiPuAiImageOptionsBuilder.withModel(runtimeImageOptions.getModel()); + zhiPuAiImageOptionsBuilder.model(runtimeImageOptions.getModel()); } if (runtimeImageOptions instanceof ZhiPuAiImageOptions runtimeZhiPuAiImageOptions) { if (runtimeZhiPuAiImageOptions.getUser() != null) { - zhiPuAiImageOptionsBuilder.withUser(runtimeZhiPuAiImageOptions.getUser()); + zhiPuAiImageOptionsBuilder.user(runtimeZhiPuAiImageOptions.getUser()); } } } diff --git a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageOptions.java b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageOptions.java index 6def22698e6..8b432b02afb 100644 --- a/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageOptions.java +++ b/models/spring-ai-zhipuai/src/main/java/org/springframework/ai/zhipuai/ZhiPuAiImageOptions.java @@ -43,6 +43,7 @@ * * * @author Geng Rong + * @author Ilayaperumal Gopinathan * @since 1.0.0 M1 */ @JsonInclude(JsonInclude.Include.NON_NULL) @@ -142,11 +143,29 @@ private Builder() { this.options = new ZhiPuAiImageOptions(); } + public Builder model(String model) { + this.options.setModel(model); + return this; + } + + public Builder user(String user) { + this.options.setUser(user); + return this; + } + + /** + * @deprecated use {@link #model(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withModel(String model) { this.options.setModel(model); return this; } + /** + * @deprecated use {@link #user(String)} instead. + */ + @Deprecated(forRemoval = true, since = "1.0.0-M5") public Builder withUser(String user) { this.options.setUser(user); return this; diff --git a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/ChatCompletionRequestTests.java b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/ChatCompletionRequestTests.java index 56b090edc89..f7e6a70dda4 100644 --- a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/ChatCompletionRequestTests.java +++ b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/ChatCompletionRequestTests.java @@ -36,7 +36,7 @@ public class ChatCompletionRequestTests { public void createRequestWithChatOptions() { var client = new ZhiPuAiChatModel(new ZhiPuAiApi("TEST"), - ZhiPuAiChatOptions.builder().withModel("DEFAULT_MODEL").withTemperature(66.6).build()); + ZhiPuAiChatOptions.builder().model("DEFAULT_MODEL").temperature(66.6).build()); var request = client.createRequest(new Prompt("Test message content"), false); @@ -47,7 +47,7 @@ public void createRequestWithChatOptions() { assertThat(request.temperature()).isEqualTo(66.6); request = client.createRequest(new Prompt("Test message content", - ZhiPuAiChatOptions.builder().withModel("PROMPT_MODEL").withTemperature(99.9).build()), true); + ZhiPuAiChatOptions.builder().model("PROMPT_MODEL").temperature(99.9).build()), true); assertThat(request.messages()).hasSize(1); assertThat(request.stream()).isTrue(); @@ -62,12 +62,12 @@ public void promptOptionsTools() { final String TOOL_FUNCTION_NAME = "CurrentWeather"; var client = new ZhiPuAiChatModel(new ZhiPuAiApi("TEST"), - ZhiPuAiChatOptions.builder().withModel("DEFAULT_MODEL").build()); + ZhiPuAiChatOptions.builder().model("DEFAULT_MODEL").build()); var request = client.createRequest(new Prompt("Test message content", ZhiPuAiChatOptions.builder() - .withModel("PROMPT_MODEL") - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .model("PROMPT_MODEL") + .functionCallbacks(List.of(FunctionCallback.builder() .function(TOOL_FUNCTION_NAME, new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) @@ -93,8 +93,8 @@ public void defaultOptionsTools() { var client = new ZhiPuAiChatModel(new ZhiPuAiApi("TEST"), ZhiPuAiChatOptions.builder() - .withModel("DEFAULT_MODEL") - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .model("DEFAULT_MODEL") + .functionCallbacks(List.of(FunctionCallback.builder() .function(TOOL_FUNCTION_NAME, new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) @@ -116,8 +116,9 @@ public void defaultOptionsTools() { .isNullOrEmpty(); // Explicitly enable the function - request = client.createRequest(new Prompt("Test message content", - ZhiPuAiChatOptions.builder().withFunction(TOOL_FUNCTION_NAME).build()), false); + request = client.createRequest( + new Prompt("Test message content", ZhiPuAiChatOptions.builder().function(TOOL_FUNCTION_NAME).build()), + false); assertThat(request.tools()).hasSize(1); assertThat(request.tools().get(0).getFunction().getName()).as("Explicitly enabled function") @@ -126,7 +127,7 @@ public void defaultOptionsTools() { // Override the default options function with one from the prompt request = client.createRequest(new Prompt("Test message content", ZhiPuAiChatOptions.builder() - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .functionCallbacks(List.of(FunctionCallback.builder() .function(TOOL_FUNCTION_NAME, new MockWeatherService()) .description("Overridden function description") .inputType(MockWeatherService.Request.class) diff --git a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java index 1b2e12a5109..40aa9741950 100644 --- a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java +++ b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java @@ -229,8 +229,8 @@ void functionCallTest() { List messages = new ArrayList<>(List.of(userMessage)); var promptOptions = ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_4.getValue()) - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .model(ZhiPuAiApi.ChatModel.GLM_4.getValue()) + .functionCallbacks(List.of(FunctionCallback.builder() .function("getCurrentWeather", new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) @@ -255,8 +255,8 @@ void streamFunctionCallTest() { List messages = new ArrayList<>(List.of(userMessage)); var promptOptions = ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_4.getValue()) - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .model(ZhiPuAiApi.ChatModel.GLM_4.getValue()) + .functionCallbacks(List.of(FunctionCallback.builder() .function("getCurrentWeather", new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) @@ -289,7 +289,7 @@ void multiModalityEmbeddedImage(String modelName) throws IOException { List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData))); var response = this.chatModel - .call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withModel(modelName).build())); + .call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().model(modelName).build())); logger.info(response.getResult().getOutput().getText()); assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple"); @@ -307,7 +307,7 @@ void multiModalityImageUrl(String modelName) throws IOException { .build())); ChatResponse response = this.chatModel - .call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withModel(modelName).build())); + .call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().model(modelName).build())); logger.info(response.getResult().getOutput().getText()); assertThat(response.getResult().getOutput().getText()).contains("bananas", "apple"); @@ -324,7 +324,7 @@ void streamingMultiModalityImageUrl() throws IOException { .build())); Flux response = this.streamingChatModel.stream(new Prompt(List.of(userMessage), - ZhiPuAiChatOptions.builder().withModel(ZhiPuAiApi.ChatModel.GLM_4V.getValue()).build())); + ZhiPuAiChatOptions.builder().model(ZhiPuAiApi.ChatModel.GLM_4V.getValue()).build())); String content = Objects.requireNonNull(response.collectList().block()) .stream() diff --git a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelObservationIT.java b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelObservationIT.java index 63ea779cb0a..a46f50f1a94 100644 --- a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelObservationIT.java +++ b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelObservationIT.java @@ -70,11 +70,11 @@ void beforeEach() { void observationForChatOperation() { var options = ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_4_Air.getValue()) - .withMaxTokens(2048) - .withStop(List.of("this-is-the-end")) - .withTemperature(0.7) - .withTopP(1.0) + .model(ZhiPuAiApi.ChatModel.GLM_4_Air.getValue()) + .maxTokens(2048) + .stop(List.of("this-is-the-end")) + .temperature(0.7) + .topP(1.0) .build(); Prompt prompt = new Prompt("Why does a raven look like a desk?", options); @@ -91,11 +91,11 @@ void observationForChatOperation() { @Test void observationForStreamingChatOperation() { var options = ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_4_Air.getValue()) - .withMaxTokens(2048) - .withStop(List.of("this-is-the-end")) - .withTemperature(0.7) - .withTopP(1.0) + .model(ZhiPuAiApi.ChatModel.GLM_4_Air.getValue()) + .maxTokens(2048) + .stop(List.of("this-is-the-end")) + .temperature(0.7) + .topP(1.0) .build(); Prompt prompt = new Prompt("Why does a raven look like a desk?", options); diff --git a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/embedding/ZhiPuAiEmbeddingModelObservationIT.java b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/embedding/ZhiPuAiEmbeddingModelObservationIT.java index 9ad910595d7..4238088e890 100644 --- a/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/embedding/ZhiPuAiEmbeddingModelObservationIT.java +++ b/models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/embedding/ZhiPuAiEmbeddingModelObservationIT.java @@ -60,9 +60,7 @@ public class ZhiPuAiEmbeddingModelObservationIT { @Test void observationForEmbeddingOperation() { - var options = ZhiPuAiEmbeddingOptions.builder() - .withModel(ZhiPuAiApi.EmbeddingModel.Embedding_2.getValue()) - .build(); + var options = ZhiPuAiEmbeddingOptions.builder().model(ZhiPuAiApi.EmbeddingModel.Embedding_2.getValue()).build(); EmbeddingRequest embeddingRequest = new EmbeddingRequest(List.of("Here comes the sun"), options); @@ -108,7 +106,7 @@ public ZhiPuAiApi zhiPuAiApi() { public ZhiPuAiEmbeddingModel zhiPuAiEmbeddingModel(ZhiPuAiApi zhiPuAiApi, TestObservationRegistry observationRegistry) { return new ZhiPuAiEmbeddingModel(zhiPuAiApi, MetadataMode.EMBED, - ZhiPuAiEmbeddingOptions.builder().withModel(ZhiPuAiApi.DEFAULT_EMBEDDING_MODEL).build(), + ZhiPuAiEmbeddingOptions.builder().model(ZhiPuAiApi.DEFAULT_EMBEDDING_MODEL).build(), RetryTemplate.defaultInstance(), observationRegistry); } diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/zhipuai-chat-functions.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/zhipuai-chat-functions.adoc index 3de67f38b0b..c05b37b0083 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/zhipuai-chat-functions.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/zhipuai-chat-functions.adoc @@ -155,7 +155,7 @@ ZhiPuAiChatModel chatModel = ... UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); ChatResponse response = this.chatModel.call(new Prompt(List.of(this.userMessage), - ZhiPuAiChatOptions.builder().withFunction("CurrentWeather").build())); // (1) Enable the function + ZhiPuAiChatOptions.builder().function("CurrentWeather").build())); // (1) Enable the function logger.info("Response: {}", response); ---- @@ -185,7 +185,7 @@ ZhiPuAiChatModel chatModel = ... UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?"); var promptOptions = ZhiPuAiChatOptions.builder() - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .functionCallbacks(List.of(FunctionCallback.builder() .function("CurrentWeather", new MockWeatherService()) // (1) function name and instance .description("Get the weather in location") // (2) function description .inputType(MockWeatherService.Request.class) // (3) function signature diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/zhipuai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/zhipuai-chat.adoc index 9a178bbe6d7..6c453e70724 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/zhipuai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/zhipuai-chat.adoc @@ -122,8 +122,8 @@ ChatResponse response = chatModel.call( new Prompt( "Generate the names of 5 famous pirates.", ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue()) - .withTemperature(0.5) + .model(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue()) + .temperature(0.5) .build() )); ---- @@ -205,9 +205,9 @@ Next, create a `ZhiPuAiChatModel` and use it for text generations: var zhiPuAiApi = new ZhiPuAiApi(System.getenv("ZHIPU_AI_API_KEY")); var chatModel = new ZhiPuAiChatModel(this.zhiPuAiApi, ZhiPuAiChatOptions.builder() - .withModel(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue()) - .withTemperature(0.4) - .withMaxTokens(200) + .model(ZhiPuAiApi.ChatModel.GLM_3_Turbo.getValue()) + .temperature(0.4) + .maxTokens(200) .build()); ChatResponse response = this.chatModel.call( diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/zhipuai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/zhipuai-embeddings.adoc index c98eb612682..cc6a0558950 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/zhipuai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/zhipuai-embeddings.adoc @@ -116,7 +116,7 @@ For example to override the default model name for a specific request: EmbeddingResponse embeddingResponse = embeddingModel.call( new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"), ZhiPuAiEmbeddingOptions.builder() - .withModel("Different-Embedding-Model-Deployment-Name") + .model("Different-Embedding-Model-Deployment-Name") .build())); ---- @@ -183,10 +183,10 @@ Next, create an `ZhiPuAiEmbeddingModel` instance and use it to compute the simil ---- var zhiPuAiApi = new ZhiPuAiApi(System.getenv("ZHIPU_AI_API_KEY")); -var embeddingModel = new ZhiPuAiEmbeddingModel(this.zhiPuAiApi) - .withDefaultOptions(ZhiPuAiChatOptions.build() - .withModel("embedding-2") - .build()); +var embeddingModel = new ZhiPuAiEmbeddingModel(api, MetadataMode.EMBED, + ZhiPuAiEmbeddingOptions.builder() + .model("embedding-2") + .build()); EmbeddingResponse embeddingResponse = this.embeddingModel .embedForResponse(List.of("Hello World", "World is big and salvation is near")); diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/image/zhipuai-image.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/image/zhipuai-image.adoc index aeedede6c0c..f9f13470e60 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/image/zhipuai-image.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/image/zhipuai-image.adoc @@ -106,10 +106,10 @@ For example to override the ZhiPuAI specific options such as quality and the num ImageResponse response = zhiPuAiImageModel.call( new ImagePrompt("A light cream colored mini golden doodle", ZhiPuAiImageOptions.builder() - .withQuality("hd") - .withN(4) - .withHeight(1024) - .withWidth(1024).build()) + .quality("hd") + .N(4) + .height(1024) + .width(1024).build()) ); ---- diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiChatProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiChatProperties.java index ce89974e84c..516105c2552 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiChatProperties.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiChatProperties.java @@ -42,8 +42,8 @@ public class ZhiPuAiChatProperties extends ZhiPuAiParentProperties { @NestedConfigurationProperty private ZhiPuAiChatOptions options = ZhiPuAiChatOptions.builder() - .withModel(DEFAULT_CHAT_MODEL) - .withTemperature(DEFAULT_TEMPERATURE) + .model(DEFAULT_CHAT_MODEL) + .temperature(DEFAULT_TEMPERATURE) .build(); public ZhiPuAiChatOptions getOptions() { diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiEmbeddingProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiEmbeddingProperties.java index 771c26a048c..f069170517d 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiEmbeddingProperties.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/zhipuai/ZhiPuAiEmbeddingProperties.java @@ -42,9 +42,7 @@ public class ZhiPuAiEmbeddingProperties extends ZhiPuAiParentProperties { private MetadataMode metadataMode = MetadataMode.EMBED; @NestedConfigurationProperty - private ZhiPuAiEmbeddingOptions options = ZhiPuAiEmbeddingOptions.builder() - .withModel(DEFAULT_EMBEDDING_MODEL) - .build(); + private ZhiPuAiEmbeddingOptions options = ZhiPuAiEmbeddingOptions.builder().model(DEFAULT_EMBEDDING_MODEL).build(); public ZhiPuAiEmbeddingOptions getOptions() { return this.options; diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackInPromptIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackInPromptIT.java index 7bea61c1c18..556e7df8c19 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackInPromptIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackInPromptIT.java @@ -64,7 +64,7 @@ void functionCallTest() { "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); var promptOptions = ZhiPuAiChatOptions.builder() - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .functionCallbacks(List.of(FunctionCallback.builder() .function("CurrentWeatherService", new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) @@ -92,7 +92,7 @@ void streamingFunctionCallTest() { "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); var promptOptions = ZhiPuAiChatOptions.builder() - .withFunctionCallbacks(List.of(FunctionCallback.builder() + .functionCallbacks(List.of(FunctionCallback.builder() .function("CurrentWeatherService", new MockWeatherService()) .description("Get the weather in location") .inputType(MockWeatherService.Request.class) diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackWithPlainFunctionBeanIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackWithPlainFunctionBeanIT.java index a83c29c65a8..7107cb6771e 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackWithPlainFunctionBeanIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/FunctionCallbackWithPlainFunctionBeanIT.java @@ -70,8 +70,8 @@ void functionCallTest() { UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); - ChatResponse response = chatModel.call(new Prompt(List.of(userMessage), - ZhiPuAiChatOptions.builder().withFunction("weatherFunction").build())); + ChatResponse response = chatModel.call( + new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().function("weatherFunction").build())); logger.info("Response: {}", response); @@ -79,7 +79,7 @@ void functionCallTest() { // Test weatherFunctionTwo response = chatModel.call(new Prompt(List.of(userMessage), - ZhiPuAiChatOptions.builder().withFunction("weatherFunctionTwo").build())); + ZhiPuAiChatOptions.builder().function("weatherFunctionTwo").build())); logger.info("Response: {}", response); @@ -118,8 +118,8 @@ void streamFunctionCallTest() { UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); - Flux response = chatModel.stream(new Prompt(List.of(userMessage), - ZhiPuAiChatOptions.builder().withFunction("weatherFunction").build())); + Flux response = chatModel.stream( + new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().function("weatherFunction").build())); String content = response.collectList() .block() @@ -137,7 +137,7 @@ void streamFunctionCallTest() { // Test weatherFunctionTwo response = chatModel.stream(new Prompt(List.of(userMessage), - ZhiPuAiChatOptions.builder().withFunction("weatherFunctionTwo").build())); + ZhiPuAiChatOptions.builder().function("weatherFunctionTwo").build())); content = response.collectList() .block() diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/ZhipuAiFunctionCallbackIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/ZhipuAiFunctionCallbackIT.java index db3a177f479..6b258e98d1a 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/ZhipuAiFunctionCallbackIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/zhipuai/tool/ZhipuAiFunctionCallbackIT.java @@ -66,8 +66,8 @@ void functionCallTest() { UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); - ChatResponse response = chatModel.call( - new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withFunction("WeatherInfo").build())); + ChatResponse response = chatModel + .call(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().function("WeatherInfo").build())); logger.info("Response: {}", response); @@ -85,8 +85,8 @@ void streamFunctionCallTest() { UserMessage userMessage = new UserMessage( "What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."); - Flux response = chatModel.stream( - new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().withFunction("WeatherInfo").build())); + Flux response = chatModel + .stream(new Prompt(List.of(userMessage), ZhiPuAiChatOptions.builder().function("WeatherInfo").build())); String content = response.collectList() .block()