From f54c16aa549ce18d85a972ebfbf0fd022c17b709 Mon Sep 17 00:00:00 2001 From: YunLong Date: Wed, 20 Nov 2024 10:56:44 +0800 Subject: [PATCH 01/10] 1.add ding talk custom robot send group message --- .../pom.xml | 61 +++++++++++++++++++ .../java/com/alibaba/cloud/ai/Config.java | 21 +++++++ .../CustomRobotSendMessageService.java | 60 ++++++++++++++++++ .../com/alibaba/cloud/ai/utils/SignUtils.java | 29 +++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + pom.xml | 1 + .../function-calling-example/pom.xml | 7 +++ .../FunctionCallingController.java | 9 +++ .../src/main/resources/application.yml | 9 ++- 9 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml b/community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml new file mode 100644 index 00000000..1d4bd741 --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + + com.alibaba.cloud.ai + spring-ai-alibaba + ${revision} + ../../../pom.xml + + spring-ai-alibaba-starter-ding-talk + jar + Spring Ai Alibaba Starter Ding Talk + https://github.com/alibaba/spring-ai-alibaba + + + 2.1.68 + 2.0.0 + + + + + + com.fasterxml.jackson.core + jackson-annotations + + + + org.springframework.ai + spring-ai-spring-boot-autoconfigure + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + commons-codec + commons-codec + + + + + com.aliyun + dingtalk + ${dingtalk-sdk-version} + + + + + com.aliyun + alibaba-dingtalk-service-sdk + ${old-dingtalk-sdk-version} + + + + + ding-talk-plugin-starter + + \ No newline at end of file diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java new file mode 100644 index 00000000..746ff2dd --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java @@ -0,0 +1,21 @@ +package com.alibaba.cloud.ai; + +import com.alibaba.cloud.ai.service.CustomRobotSendMessageService; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Description; + +/** + * @author YunLong + */ +@AutoConfiguration +public class Config { + + @Bean + @ConditionalOnMissingBean + @Description("Send group chat messages using a custom robot") + public CustomRobotSendMessageService CustomRobotSendMessageFunction() { + return new CustomRobotSendMessageService(); + } +} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java new file mode 100644 index 00000000..2a0e169b --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java @@ -0,0 +1,60 @@ +package com.alibaba.cloud.ai.service; + +import com.alibaba.cloud.ai.utils.SignUtils; +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiRobotSendRequest; +import com.dingtalk.api.response.OapiRobotSendResponse; +import com.fasterxml.jackson.annotation.JsonClassDescription; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import org.springframework.beans.factory.annotation.Value; + +import java.util.function.Function; + +/** + * @author YunLong + */ +public class CustomRobotSendMessageService implements Function { + + @Value("${plugins.dingTalk.customRobot.accessToken}") + private String accessToken; + + @Value("${plugins.dingTalk.customRobot.signature}") + private String signature; + + /** + * The old version of DingTalk SDK. Some interfaces have not been fully replaced yet. + * Official Document Address:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages + */ + @Override + public Response apply(Request request) { + + // Request Body, please see the official document for more parameters. + OapiRobotSendRequest req = new OapiRobotSendRequest(); + req.setMsgtype("text"); + req.setText(String.format("{\"content\":\"%s\"}", request.message())); + + try { + DingTalkClient client = new DefaultDingTalkClient(String.format("https://oapi.dingtalk.com/robot/send?%s", SignUtils.getSign(signature))); + OapiRobotSendResponse response = client.execute(req, accessToken); + + if (response.isSuccess()) { + return new Response("The custom robot message was sent successfully!"); + } + } catch (Exception e) { + throw new RuntimeException("Custom robot message sending failed!"); + } + + return null; + } + + @JsonClassDescription("Send group chat messages using a custom robot") + public record Request( + @JsonProperty(required = true, value = "message") + @JsonPropertyDescription("Customize what the robot needs to send") String message) { + } + + public record Response(String message) { + } +} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java new file mode 100644 index 00000000..56414916 --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java @@ -0,0 +1,29 @@ +package com.alibaba.cloud.ai.utils; + +import org.apache.commons.codec.binary.Base64; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +/** + * @author YunLong + */ +public class SignUtils { + + public static String getSign(String signature) { + Long timestamp = System.currentTimeMillis(); + String stringToSign = timestamp + "\n" + signature; + + try { + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(new SecretKeySpec(signature.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); + byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8)); + String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), StandardCharsets.UTF_8); + return "×tamp=" + timestamp + "&sign=" + sign; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..7be8ad9e --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.alibaba.cloud.ai.Config \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1ae9e9cf..63b8ff60 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ spring-ai-alibaba-core spring-ai-alibaba-starter spring-ai-alibaba-autoconfigure + community/plugins/spring-ai-alibaba-starter-ding-talk diff --git a/spring-ai-alibaba-examples/function-calling-example/pom.xml b/spring-ai-alibaba-examples/function-calling-example/pom.xml index 9733732b..6d1984c0 100644 --- a/spring-ai-alibaba-examples/function-calling-example/pom.xml +++ b/spring-ai-alibaba-examples/function-calling-example/pom.xml @@ -54,6 +54,13 @@ spring-boot-starter-web + + + com.alibaba.cloud.ai + spring-ai-alibaba-starter-ding-talk + 1.0.0-M3.2 + + diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java index 82e0c38c..243968e3 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java @@ -50,4 +50,13 @@ public String orderDetail() { .content(); } + @GetMapping("/dingTalk-custom-robot-send") + public String dingTalkCustomRobotSend(String input) { + return chatClient.prompt() + .functions("CustomRobotSendMessageFunction") + .user(String.format("帮我用自定义机器人发送'%s'", input)) + .call() + .content(); + } + } diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml index 55c73637..7ee3d33d 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml @@ -1,7 +1,14 @@ spring: application: - name: cfunction-calling-example + name: function-calling-example ai: dashscope: api-key: ${AI_DASHSCOPE_API_KEY} + + +plugins: + dingTalk: + customRobot: + accessToken: ${plugins.dingTalk.customRobot.customRobot.accessToken} # accessToken of custom robot + signature: ${plugins.dingTalk.customRobot.customRobot.signature} # sign of custom robot \ No newline at end of file From 9b9a7e1ed2503c621600de294ef1541b1ef1002c Mon Sep 17 00:00:00 2001 From: YunLong Date: Wed, 20 Nov 2024 11:25:58 +0800 Subject: [PATCH 02/10] 1.code format --- pom.xml | 4 +- .../FunctionCallingController.java | 73 ++++++++++--------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 3179fed2..74cb7992 100644 --- a/pom.xml +++ b/pom.xml @@ -33,9 +33,9 @@ spring-ai-alibaba-core spring-ai-alibaba-starter - spring-ai-alibaba-autoconfigure + spring-ai-alibaba-autoconfigure community/plugins/spring-ai-alibaba-starter-time - community/plugins/spring-ai-alibaba-starter-ding-talk + community/plugins/spring-ai-alibaba-starter-ding-talk diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java index 1bfaa3a9..3e21b6d4 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java @@ -26,45 +26,46 @@ @RequestMapping("/ai/func") public class FunctionCallingController { - private final ChatClient chatClient; + private final ChatClient chatClient; - public FunctionCallingController(ChatClient.Builder chatClientBuilder) { - this.chatClient = chatClientBuilder.build(); - } + public FunctionCallingController(ChatClient.Builder chatClientBuilder) { + this.chatClient = chatClientBuilder.build(); + } - @GetMapping("/weather-service") - public String weatherService(String subject) { - return chatClient.prompt() - .function("getWeather", "根据城市查询天气", new MockWeatherService()) - .user(subject) - .call() - .content(); - } + @GetMapping("/weather-service") + public String weatherService(String subject) { + return chatClient.prompt() + .function("getWeather", "根据城市查询天气", new MockWeatherService()) + .user(subject) + .call() + .content(); + } - @GetMapping("/order-detail") - public String orderDetail() { - return chatClient.prompt() - .functions("getOrderFunction") - .user("帮我查询一下订单, 用户编号为1001, 订单编号为2001") - .call() - .content(); - } - - @GetMapping("/getTime") - public String getTime(String text) { - return chatClient.prompt() - .functions("getCityTimeFunction") - .user(text) - .call() - .content(); + @GetMapping("/order-detail") + public String orderDetail() { + return chatClient.prompt() + .functions("getOrderFunction") + .user("帮我查询一下订单, 用户编号为1001, 订单编号为2001") + .call() + .content(); + } - @GetMapping("/dingTalk-custom-robot-send") - public String dingTalkCustomRobotSend(String input) { - return chatClient.prompt() - .functions("CustomRobotSendMessageFunction") - .user(String.format("帮我用自定义机器人发送'%s'", input)) - .call() - .content(); - } + @GetMapping("/getTime") + public String getTime(String text) { + return chatClient.prompt() + .functions("getCityTimeFunction") + .user(text) + .call() + .content(); + } + + @GetMapping("/dingTalk-custom-robot-send") + public String dingTalkCustomRobotSend(String input) { + return chatClient.prompt() + .functions("CustomRobotSendMessageFunction") + .user(String.format("帮我用自定义机器人发送'%s'", input)) + .call() + .content(); + } } From fa49a77ff07fefb67a674d5ce351369645ed2c8c Mon Sep 17 00:00:00 2001 From: YunLong Date: Thu, 21 Nov 2024 14:22:51 +0800 Subject: [PATCH 03/10] 1.add ding-talk properties --- .../java/com/alibaba/cloud/ai/Config.java | 21 -------- .../com/alibaba/cloud/ai/DingTalkConfig.java | 24 +++++++++ .../ai/properties/DingTalkProperties.java | 51 +++++++++++++++++++ .../CustomRobotSendMessageService.java | 19 +++++-- ...ot.autoconfigure.AutoConfiguration.imports | 2 +- .../src/main/resources/application.yml | 15 +++--- 6 files changed, 98 insertions(+), 34 deletions(-) delete mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java create mode 100644 community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java deleted file mode 100644 index 746ff2dd..00000000 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/Config.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.alibaba.cloud.ai; - -import com.alibaba.cloud.ai.service.CustomRobotSendMessageService; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Description; - -/** - * @author YunLong - */ -@AutoConfiguration -public class Config { - - @Bean - @ConditionalOnMissingBean - @Description("Send group chat messages using a custom robot") - public CustomRobotSendMessageService CustomRobotSendMessageFunction() { - return new CustomRobotSendMessageService(); - } -} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java new file mode 100644 index 00000000..4bff7c68 --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java @@ -0,0 +1,24 @@ +package com.alibaba.cloud.ai; + +import com.alibaba.cloud.ai.properties.DingTalkProperties; +import com.alibaba.cloud.ai.service.CustomRobotSendMessageService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Description; + +/** + * @author YunLong + */ +@EnableConfigurationProperties(DingTalkProperties.class) +@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.ding-talk", name = "enabled", havingValue = "true") +public class DingTalkConfig { + + @Bean + @ConditionalOnMissingBean + @Description("Send group chat messages using a custom robot") + public CustomRobotSendMessageService CustomRobotSendMessageFunction(DingTalkProperties dingTalkProperties) { + return new CustomRobotSendMessageService(dingTalkProperties); + } +} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java new file mode 100644 index 00000000..333fc915 --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java @@ -0,0 +1,51 @@ +package com.alibaba.cloud.ai.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * @author YunLong + */ +@ConfigurationProperties("spring.ai.alibaba.plugin.ding-talk") +public class DingTalkProperties { + + private CustomRobot customRobot; + + public DingTalkProperties() { + } + + public DingTalkProperties(CustomRobot customRobot) { + this.customRobot = customRobot; + } + + public CustomRobot getCustomRobot() { + return customRobot; + } + + public void setCustomRobot(CustomRobot customRobot) { + this.customRobot = customRobot; + } + + public static class CustomRobot { + + private String accessToken; + + private String signature; + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getSignature() { + return signature; + } + + public void setSignature(String signature) { + this.signature = signature; + } + } +} diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java index 2a0e169b..a88ddd49 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java @@ -1,5 +1,6 @@ package com.alibaba.cloud.ai.service; +import com.alibaba.cloud.ai.properties.DingTalkProperties; import com.alibaba.cloud.ai.utils.SignUtils; import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; @@ -8,7 +9,8 @@ import com.fasterxml.jackson.annotation.JsonClassDescription; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ObjectUtils; import java.util.function.Function; @@ -17,11 +19,11 @@ */ public class CustomRobotSendMessageService implements Function { - @Value("${plugins.dingTalk.customRobot.accessToken}") - private String accessToken; + private final DingTalkProperties dingTalkProperties; - @Value("${plugins.dingTalk.customRobot.signature}") - private String signature; + public CustomRobotSendMessageService(DingTalkProperties dingTalkProperties) { + this.dingTalkProperties = dingTalkProperties; + } /** * The old version of DingTalk SDK. Some interfaces have not been fully replaced yet. @@ -30,6 +32,13 @@ public class CustomRobotSendMessageService implements Function Date: Thu, 21 Nov 2024 14:24:28 +0800 Subject: [PATCH 04/10] 1.add ding-talk properties --- .../java/com/alibaba/cloud/ai/properties/DingTalkProperties.java | 1 - .../alibaba/cloud/ai/service/CustomRobotSendMessageService.java | 1 - 2 files changed, 2 deletions(-) diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java index 333fc915..29d65579 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java @@ -1,7 +1,6 @@ package com.alibaba.cloud.ai.properties; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; /** * @author YunLong diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java index a88ddd49..4f2aeea1 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java +++ b/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonClassDescription; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import java.util.function.Function; From 71dab54d556d94e90e9b817aa34d28b01895715a Mon Sep 17 00:00:00 2001 From: YunLong Date: Thu, 21 Nov 2024 16:25:11 +0800 Subject: [PATCH 05/10] 1.dingtalk rename --- .../pom.xml | 6 +++--- .../java/com/alibaba/cloud/ai/DingTalkConfig.java | 2 +- .../cloud/ai/properties/DingTalkProperties.java | 2 +- .../ai/service/CustomRobotSendMessageService.java | 0 .../java/com/alibaba/cloud/ai/utils/SignUtils.java | 0 ...work.boot.autoconfigure.AutoConfiguration.imports | 0 pom.xml | 2 +- .../function-calling-example/pom.xml | 12 ++++++------ .../src/main/resources/application.yml | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/pom.xml (92%) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java (89%) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java (94%) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java (100%) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java (100%) rename community/plugins/{spring-ai-alibaba-starter-ding-talk => spring-ai-alibaba-starter-dingtalk}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (100%) diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml b/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml similarity index 92% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml rename to community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml index 1d4bd741..91884d83 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml @@ -7,9 +7,9 @@ ${revision} ../../../pom.xml - spring-ai-alibaba-starter-ding-talk + spring-ai-alibaba-starter-dingtalk jar - Spring Ai Alibaba Starter Ding Talk + Spring Ai Alibaba Starter DingTalk https://github.com/alibaba/spring-ai-alibaba @@ -56,6 +56,6 @@ - ding-talk-plugin-starter + dingtalk-plugin-starter \ No newline at end of file diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java similarity index 89% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java rename to community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java index 4bff7c68..e8146c69 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java @@ -12,7 +12,7 @@ * @author YunLong */ @EnableConfigurationProperties(DingTalkProperties.class) -@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.ding-talk", name = "enabled", havingValue = "true") +@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.dingtalk", name = "enabled", havingValue = "true") public class DingTalkConfig { @Bean diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java similarity index 94% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java rename to community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java index 29d65579..bae7340d 100644 --- a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java @@ -5,7 +5,7 @@ /** * @author YunLong */ -@ConfigurationProperties("spring.ai.alibaba.plugin.ding-talk") +@ConfigurationProperties("spring.ai.alibaba.plugin.dingtalk") public class DingTalkProperties { private CustomRobot customRobot; diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java similarity index 100% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java rename to community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java similarity index 100% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java rename to community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java diff --git a/community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 100% rename from community/plugins/spring-ai-alibaba-starter-ding-talk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename to community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/pom.xml b/pom.xml index 74cb7992..7176b692 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ spring-ai-alibaba-starter spring-ai-alibaba-autoconfigure community/plugins/spring-ai-alibaba-starter-time - community/plugins/spring-ai-alibaba-starter-ding-talk + community/plugins/spring-ai-alibaba-starter-dingtalk diff --git a/spring-ai-alibaba-examples/function-calling-example/pom.xml b/spring-ai-alibaba-examples/function-calling-example/pom.xml index faa70848..5034fe1b 100644 --- a/spring-ai-alibaba-examples/function-calling-example/pom.xml +++ b/spring-ai-alibaba-examples/function-calling-example/pom.xml @@ -62,15 +62,15 @@ com.alibaba.cloud.ai - spring-ai-alibaba-starter-ding-talk + spring-ai-alibaba-starter-dingtalk 1.0.0-M3.2 - - com.alibaba.cloud.ai - baidu-search-plugin-starter - 0.0.1 - + + + + + diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml index d71b9b1f..2d90b8e2 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml @@ -7,7 +7,7 @@ spring: api-key: ${AI_DASHSCOPE_API_KEY} alibaba: plugin: - ding-talk: + dingtalk: enabled: true custom-robot: access-token: ${spring.ai.alibaba.plugin.ding-talk.custom-robot.access-token} # accessToken of custom robot From 5d23b5ac3669a9412c96ba20bff03c495c8e1e2a Mon Sep 17 00:00:00 2001 From: YunLong Date: Thu, 21 Nov 2024 16:28:05 +0800 Subject: [PATCH 06/10] 1.revert error remark --- .../function-calling-example/pom.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-ai-alibaba-examples/function-calling-example/pom.xml b/spring-ai-alibaba-examples/function-calling-example/pom.xml index 5034fe1b..9750f0b6 100644 --- a/spring-ai-alibaba-examples/function-calling-example/pom.xml +++ b/spring-ai-alibaba-examples/function-calling-example/pom.xml @@ -59,6 +59,12 @@ 1.0.0-M3.2 + + com.alibaba.cloud.ai + baidu-search-plugin-starter + 0.0.1 + + com.alibaba.cloud.ai @@ -66,11 +72,6 @@ 1.0.0-M3.2 - - - - - From c0f3f635b78c5596628ef064cb2511b962bfb78d Mon Sep 17 00:00:00 2001 From: YunLong Date: Sat, 23 Nov 2024 10:45:19 +0800 Subject: [PATCH 07/10] 1.add license header --- .../pom.xml | 18 ++++++ .../com/alibaba/cloud/ai/DingTalkConfig.java | 19 +++++- .../ai/properties/DingTalkProperties.java | 62 ++++++++++--------- .../CustomRobotSendMessageService.java | 23 +++++-- .../com/alibaba/cloud/ai/utils/SignUtils.java | 17 ++++- ...ot.autoconfigure.AutoConfiguration.imports | 2 +- .../FunctionCallingController.java | 2 +- 7 files changed, 104 insertions(+), 39 deletions(-) diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml b/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml index 91884d83..fdbc826e 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml @@ -1,3 +1,21 @@ + + + + 4.0.0 diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java index e8146c69..0db0b53d 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java @@ -1,5 +1,20 @@ package com.alibaba.cloud.ai; - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ import com.alibaba.cloud.ai.properties.DingTalkProperties; import com.alibaba.cloud.ai.service.CustomRobotSendMessageService; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -18,7 +33,7 @@ public class DingTalkConfig { @Bean @ConditionalOnMissingBean @Description("Send group chat messages using a custom robot") - public CustomRobotSendMessageService CustomRobotSendMessageFunction(DingTalkProperties dingTalkProperties) { + public CustomRobotSendMessageService customRobotSendMessageFunction(DingTalkProperties dingTalkProperties) { return new CustomRobotSendMessageService(dingTalkProperties); } } diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java index bae7340d..8843d595 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java @@ -1,5 +1,20 @@ package com.alibaba.cloud.ai.properties; - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -8,43 +23,30 @@ @ConfigurationProperties("spring.ai.alibaba.plugin.dingtalk") public class DingTalkProperties { - private CustomRobot customRobot; + private String customRobotAccessToken; - public DingTalkProperties() { - } + private String customRobotSignature; - public DingTalkProperties(CustomRobot customRobot) { - this.customRobot = customRobot; - } + public DingTalkProperties() {} - public CustomRobot getCustomRobot() { - return customRobot; + public DingTalkProperties(String customRobotAccessToken, String customRobotSignature) { + this.customRobotAccessToken = customRobotAccessToken; + this.customRobotSignature = customRobotSignature; } - public void setCustomRobot(CustomRobot customRobot) { - this.customRobot = customRobot; + public String getCustomRobotAccessToken() { + return customRobotAccessToken; } - public static class CustomRobot { - - private String accessToken; - - private String signature; - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + public void setCustomRobotAccessToken(String customRobotAccessToken) { + this.customRobotAccessToken = customRobotAccessToken; + } - public String getSignature() { - return signature; - } + public String getCustomRobotSignature() { + return customRobotSignature; + } - public void setSignature(String signature) { - this.signature = signature; - } + public void setCustomRobotSignature(String customRobotSignature) { + this.customRobotSignature = customRobotSignature; } } diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java index 4f2aeea1..ce2c978a 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java @@ -1,5 +1,20 @@ package com.alibaba.cloud.ai.service; - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ import com.alibaba.cloud.ai.properties.DingTalkProperties; import com.alibaba.cloud.ai.utils.SignUtils; import com.dingtalk.api.DefaultDingTalkClient; @@ -31,12 +46,12 @@ public CustomRobotSendMessageService(DingTalkProperties dingTalkProperties) { @Override public Response apply(Request request) { - if (ObjectUtils.isEmpty(dingTalkProperties.getCustomRobot().getAccessToken()) || ObjectUtils.isEmpty(dingTalkProperties.getCustomRobot().getSignature())) { + if (ObjectUtils.isEmpty(dingTalkProperties.getCustomRobotAccessToken()) || ObjectUtils.isEmpty(dingTalkProperties.getCustomRobotSignature())) { throw new IllegalArgumentException("current spring.ai.community.plugin.dingTalk.customRobot must not be null."); } - String accessToken = dingTalkProperties.getCustomRobot().getAccessToken(); - String signature = dingTalkProperties.getCustomRobot().getSignature(); + String accessToken = dingTalkProperties.getCustomRobotAccessToken(); + String signature = dingTalkProperties.getCustomRobotSignature(); // Request Body, please see the official document for more parameters. OapiRobotSendRequest req = new OapiRobotSendRequest(); diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java index 56414916..85c23bc6 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java @@ -1,5 +1,20 @@ package com.alibaba.cloud.ai.utils; - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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. + */ import org.apache.commons.codec.binary.Base64; import javax.crypto.Mac; diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index b8ed7781..8ee282be 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -com.alibaba.cloud.ai.DingTalkConfig \ No newline at end of file +com.alibaba.cloud.ai.DingTalkConfig diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java index 2f9d126d..db5bf651 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java @@ -72,7 +72,7 @@ public String getTime(String text) { @GetMapping("/dingTalk-custom-robot-send") public String dingTalkCustomRobotSend(String input) { return chatClient.prompt() - .functions("CustomRobotSendMessageFunction") + .functions("customRobotSendMessageFunction") .user(String.format("帮我用自定义机器人发送'%s'", input)) .call() .content(); From 0b18ab62bab17178fccfcfc15d6f0bdc041f1625 Mon Sep 17 00:00:00 2001 From: YunLong Date: Tue, 26 Nov 2024 15:40:12 +0800 Subject: [PATCH 08/10] 1.fix some problem 2.code format --- ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../pom.xml | 2 +- .../pom.xml | 2 +- .../ai/plugin/bing/BingSearchService.java | 4 -- ...ot.autoconfigure.AutoConfiguration.imports | 2 +- .../pom.xml | 42 +++++++++++++------ .../dingtalk/DingTalkConfiguration.java} | 18 ++++---- .../plugin/dingtalk}/DingTalkProperties.java | 5 ++- .../ai/plugin/dingtalk/DingTalkService.java} | 11 +++-- .../ai/plugin/dingtalk}/utils/SignUtils.java | 2 +- ...ot.autoconfigure.AutoConfiguration.imports | 1 + pom.xml | 1 + .../function-calling-example/pom.xml | 12 +++--- .../FunctionCallingController.java | 2 +- .../src/main/resources/application.yml | 5 +-- 15 files changed, 63 insertions(+), 47 deletions(-) delete mode 100644 community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename community/plugins/{spring-ai-alibaba-starter-dingtalk => spring-ai-alibaba-starter-plugin-dingtalk}/pom.xml (71%) rename community/plugins/{spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java => spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkConfiguration.java} (66%) rename community/plugins/{spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties => spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk}/DingTalkProperties.java (88%) rename community/plugins/{spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java => spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkService.java} (86%) rename community/plugins/{spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai => spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk}/utils/SignUtils.java (97%) create mode 100644 community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 8ee282be..00000000 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -com.alibaba.cloud.ai.DingTalkConfig diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-baidusearch/pom.xml b/community/plugins/spring-ai-alibaba-starter-plugin-baidusearch/pom.xml index e352df6d..9d4cda69 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-baidusearch/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-plugin-baidusearch/pom.xml @@ -27,7 +27,7 @@ spring-ai-alibaba-starter-plugin-baidusearch spring-ai-alibaba-starter-plugin-baidusearch - Baidu seartch tool for Spring AI Alibaba + Baidu search tool for Spring AI Alibaba UTF-8 diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/pom.xml b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/pom.xml index 07de51da..bbdcdbb7 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/pom.xml @@ -27,7 +27,7 @@ spring-ai-alibaba-starter-plugin-bingsearch spring-ai-alibaba-starter-plugin-bingsearch - Bing seartch tool for Spring AI Alibaba + Bing search tool for Spring AI Alibaba UTF-8 diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/java/com/alibaba/cloud/ai/plugin/bing/BingSearchService.java b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/java/com/alibaba/cloud/ai/plugin/bing/BingSearchService.java index 025e44fc..9126e6e6 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/java/com/alibaba/cloud/ai/plugin/bing/BingSearchService.java +++ b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/java/com/alibaba/cloud/ai/plugin/bing/BingSearchService.java @@ -20,10 +20,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 06181c15..bd142889 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -com.alibaba.cloud.plugin.BingSearchPluginConfiguration \ No newline at end of file +com.alibaba.cloud.ai.plugin.bing.BingSearchPluginConfiguration \ No newline at end of file diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml similarity index 71% rename from community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml rename to community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml index fdbc826e..d51b53f9 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml @@ -25,10 +25,9 @@ ${revision} ../../../pom.xml - spring-ai-alibaba-starter-dingtalk - jar - Spring Ai Alibaba Starter DingTalk - https://github.com/alibaba/spring-ai-alibaba + spring-ai-alibaba-starter-plugin-dingtalk + spring-ai-alibaba-starter-plugin-dingtalk + Ding Talk tool for Spring AI Alibaba 2.1.68 @@ -36,44 +35,63 @@ - com.fasterxml.jackson.core jackson-annotations - org.springframework.ai spring-ai-spring-boot-autoconfigure - org.springframework.boot spring-boot-configuration-processor true - commons-codec commons-codec - com.aliyun dingtalk ${dingtalk-sdk-version} - com.aliyun alibaba-dingtalk-service-sdk ${old-dingtalk-sdk-version} - + - dingtalk-plugin-starter + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + true + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + \ No newline at end of file diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkConfiguration.java similarity index 66% rename from community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java rename to community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkConfiguration.java index 0db0b53d..abce715b 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/DingTalkConfig.java +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkConfiguration.java @@ -1,4 +1,4 @@ -package com.alibaba.cloud.ai; +package com.alibaba.cloud.ai.plugin.dingtalk; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -15,25 +15,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import com.alibaba.cloud.ai.properties.DingTalkProperties; -import com.alibaba.cloud.ai.service.CustomRobotSendMessageService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Description; /** * @author YunLong */ +@Configuration +@ConditionalOnClass(DingTalkService.class) @EnableConfigurationProperties(DingTalkProperties.class) -@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.dingtalk", name = "enabled", havingValue = "true") -public class DingTalkConfig { +public class DingTalkConfiguration { @Bean @ConditionalOnMissingBean - @Description("Send group chat messages using a custom robot") - public CustomRobotSendMessageService customRobotSendMessageFunction(DingTalkProperties dingTalkProperties) { - return new CustomRobotSendMessageService(dingTalkProperties); + @Description("Send DingTalk group chat messages using a custom robot") + @ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.dingtalk", name = "enabled", havingValue = "true") + public DingTalkService dingTalkGroupSendMessageByCustomRobotFunction(DingTalkProperties dingTalkProperties) { + return new DingTalkService(dingTalkProperties); } } diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkProperties.java similarity index 88% rename from community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java rename to community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkProperties.java index 8843d595..b457f1c7 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/properties/DingTalkProperties.java +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkProperties.java @@ -1,4 +1,4 @@ -package com.alibaba.cloud.ai.properties; +package com.alibaba.cloud.ai.plugin.dingtalk; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -20,9 +20,10 @@ /** * @author YunLong */ -@ConfigurationProperties("spring.ai.alibaba.plugin.dingtalk") +@ConfigurationProperties(prefix = "spring.ai.alibaba.plugin.dingtalk") public class DingTalkProperties { + // Official Document Address:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages private String customRobotAccessToken; private String customRobotSignature; diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkService.java similarity index 86% rename from community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java rename to community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkService.java index ce2c978a..b6f6fbdc 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/service/CustomRobotSendMessageService.java +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/DingTalkService.java @@ -1,4 +1,4 @@ -package com.alibaba.cloud.ai.service; +package com.alibaba.cloud.ai.plugin.dingtalk; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -15,8 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import com.alibaba.cloud.ai.properties.DingTalkProperties; -import com.alibaba.cloud.ai.utils.SignUtils; +import com.alibaba.cloud.ai.plugin.dingtalk.utils.SignUtils; import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiRobotSendRequest; @@ -31,11 +30,11 @@ /** * @author YunLong */ -public class CustomRobotSendMessageService implements Function { +public class DingTalkService implements Function { private final DingTalkProperties dingTalkProperties; - public CustomRobotSendMessageService(DingTalkProperties dingTalkProperties) { + public DingTalkService(DingTalkProperties dingTalkProperties) { this.dingTalkProperties = dingTalkProperties; } @@ -47,7 +46,7 @@ public CustomRobotSendMessageService(DingTalkProperties dingTalkProperties) { public Response apply(Request request) { if (ObjectUtils.isEmpty(dingTalkProperties.getCustomRobotAccessToken()) || ObjectUtils.isEmpty(dingTalkProperties.getCustomRobotSignature())) { - throw new IllegalArgumentException("current spring.ai.community.plugin.dingTalk.customRobot must not be null."); + throw new IllegalArgumentException("spring.ai.alibaba.plugin.dingtalk.custom-robot must not be null."); } String accessToken = dingTalkProperties.getCustomRobotAccessToken(); diff --git a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/utils/SignUtils.java similarity index 97% rename from community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java rename to community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/utils/SignUtils.java index 85c23bc6..15fabcbb 100644 --- a/community/plugins/spring-ai-alibaba-starter-dingtalk/src/main/java/com/alibaba/cloud/ai/utils/SignUtils.java +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/java/com/alibaba/cloud/ai/plugin/dingtalk/utils/SignUtils.java @@ -1,4 +1,4 @@ -package com.alibaba.cloud.ai.utils; +package com.alibaba.cloud.ai.plugin.dingtalk.utils; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..9ed206df --- /dev/null +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.alibaba.cloud.ai.plugin.dingtalk.DingTalkConfiguration \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5517cbf0..97316284 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ community/plugins/spring-ai-alibaba-starter-plugin-time community/plugins/spring-ai-alibaba-starter-plugin-baidusearch community/plugins/spring-ai-alibaba-starter-plugin-bingsearch + community/plugins/spring-ai-alibaba-starter-plugin-dingtalk diff --git a/spring-ai-alibaba-examples/function-calling-example/pom.xml b/spring-ai-alibaba-examples/function-calling-example/pom.xml index 9750f0b6..b7c08f70 100644 --- a/spring-ai-alibaba-examples/function-calling-example/pom.xml +++ b/spring-ai-alibaba-examples/function-calling-example/pom.xml @@ -55,21 +55,21 @@ com.alibaba.cloud.ai - spring-ai-alibaba-starter-time - 1.0.0-M3.2 + spring-ai-alibaba-starter-plugin-baidusearch + ${spring-ai-alibaba.version} com.alibaba.cloud.ai - baidu-search-plugin-starter - 0.0.1 + spring-ai-alibaba-starter-plugin-bingsearch + ${spring-ai-alibaba.version} com.alibaba.cloud.ai - spring-ai-alibaba-starter-dingtalk - 1.0.0-M3.2 + spring-ai-alibaba-starter-plugin-dingtalk + ${spring-ai-alibaba.version} diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java index db5bf651..5396ee6e 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/java/com/alibaba/cloud/ai/example/functioncalling/FunctionCallingController.java @@ -72,7 +72,7 @@ public String getTime(String text) { @GetMapping("/dingTalk-custom-robot-send") public String dingTalkCustomRobotSend(String input) { return chatClient.prompt() - .functions("customRobotSendMessageFunction") + .functions("dingTalkGroupSendMessageByCustomRobotFunction") .user(String.format("帮我用自定义机器人发送'%s'", input)) .call() .content(); diff --git a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml index 2d90b8e2..91ae6226 100644 --- a/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml +++ b/spring-ai-alibaba-examples/function-calling-example/src/main/resources/application.yml @@ -9,7 +9,6 @@ spring: plugin: dingtalk: enabled: true - custom-robot: - access-token: ${spring.ai.alibaba.plugin.ding-talk.custom-robot.access-token} # accessToken of custom robot - signature: ${spring.ai.alibaba.plugin.ding-talk.custom-robot.signature} # sign of custom robot + custom-robot-access-token: ${spring.ai.alibaba.plugin.dingtalk.custom-robot-access-token} # accessToken of custom robot + custom-robot-signature: ${spring.ai.alibaba.plugin.dingtalk.custom-robot-signature} # sign of custom robot From a8e223be47380ec546c9aea0a65cc6ee1658be64 Mon Sep 17 00:00:00 2001 From: YunLong Date: Tue, 26 Nov 2024 15:42:18 +0800 Subject: [PATCH 09/10] 1.add new line --- .../plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml | 3 +-- ...pringframework.boot.autoconfigure.AutoConfiguration.imports | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml index d51b53f9..259e15b8 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/pom.xml @@ -93,5 +93,4 @@ - - \ No newline at end of file + diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 9ed206df..1b1e0434 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/community/plugins/spring-ai-alibaba-starter-plugin-dingtalk/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -com.alibaba.cloud.ai.plugin.dingtalk.DingTalkConfiguration \ No newline at end of file +com.alibaba.cloud.ai.plugin.dingtalk.DingTalkConfiguration From e7233c6940eb47f46388d67cebd479c4defa4312 Mon Sep 17 00:00:00 2001 From: YunLong Date: Tue, 26 Nov 2024 15:43:38 +0800 Subject: [PATCH 10/10] 1.add new line --- ...springframework.boot.autoconfigure.AutoConfiguration.imports | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index bd142889..95d09ebd 100644 --- a/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/community/plugins/spring-ai-alibaba-starter-plugin-bingsearch/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -com.alibaba.cloud.ai.plugin.bing.BingSearchPluginConfiguration \ No newline at end of file +com.alibaba.cloud.ai.plugin.bing.BingSearchPluginConfiguration