diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/controller/AiController.java b/manager/src/main/java/org/apache/hertzbeat/manager/controller/AiController.java index 0e456260892..da7c967375e 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/controller/AiController.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/controller/AiController.java @@ -18,6 +18,8 @@ package org.apache.hertzbeat.manager.controller; import static org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.hertzbeat.manager.service.AiService; import org.apache.hertzbeat.manager.service.impl.AiServiceFactoryImpl; @@ -44,7 +46,10 @@ public class AiController { @Autowired private AiServiceFactoryImpl aiServiceFactory; - @Value("${aiConfig.type:0}") + /** + * Types of artificial intelligence + */ + @Value("${ai.type:zhiPu}") private String type; /** @@ -54,8 +59,11 @@ public class AiController { * @return AI response */ @GetMapping(path = "/get", produces = {TEXT_EVENT_STREAM_VALUE}) - public Flux requestAi(@RequestParam("text") String text, - @RequestParam(value = "type", required = false) String currentlyDisabledType) { + @Operation(summary = "Artificial intelligence questions and Answers", + description = "Artificial intelligence questions and Answers") + public Flux requestAi(@Parameter(description = "Request text", example = "Who are you") @RequestParam("text") String text, + @Parameter(description = "Types of artificial intelligence", example = "zhiPu") @RequestParam(value = "type", required = false) String currentlyDisabledType) { + AiService aiServiceImplBean = aiServiceFactory.getAiServiceImplBean(type); return aiServiceImplBean.requestAi(text); diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/AlibabaAiServiceImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/AlibabaAiServiceImpl.java index 06e79a9925e..6b2bd65006a 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/AlibabaAiServiceImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/AlibabaAiServiceImpl.java @@ -28,6 +28,7 @@ import org.apache.hertzbeat.manager.pojo.dto.AliAiResponse; import org.apache.hertzbeat.manager.service.AiService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -43,12 +44,13 @@ * alibaba Ai */ @Service("AlibabaAiServiceImpl") +@ConditionalOnProperty(prefix = "ai", name = "api-key", matchIfMissing = false) @Slf4j public class AlibabaAiServiceImpl implements AiService { - @Value("${aiConfig.model:qwen-turbo}") + @Value("${ai.model:qwen-turbo}") private String model; - @Value("${aiConfig.api-key}") + @Value("${ai.api-key}") private String apiKey; @@ -113,6 +115,6 @@ public Flux requestAi(String text) { private void checkParam(String param, String apiKey) { Assert.notNull(param, "text is null"); - Assert.notNull(apiKey, "aiConfig.api-key is null"); + Assert.notNull(apiKey, "ai.api-key is null"); } } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/KimiAiServiceImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/KimiAiServiceImpl.java index a9fc8746fa7..6ace14282a5 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/KimiAiServiceImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/KimiAiServiceImpl.java @@ -29,6 +29,7 @@ import org.apache.hertzbeat.manager.pojo.dto.KimiAiResponse; import org.apache.hertzbeat.manager.service.AiService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -42,13 +43,14 @@ * Kimi Ai */ @Service("KimiAiServiceImpl") +@ConditionalOnProperty(prefix = "ai", name = "api-key", matchIfMissing = false) @Slf4j public class KimiAiServiceImpl implements AiService { - @Value("${aiConfig.model:moonshot-v1-8k}") + @Value("${ai.model:moonshot-v1-8k}") private String model; - @Value("${aiConfig.api-key}") + @Value("${ai.api-key}") private String apiKey; private WebClient webClient; @@ -108,6 +110,6 @@ private String convertToResponse(String aiRes) { private void checkParam(String param, String apiKey) { Assert.notNull(param, "text is null"); - Assert.notNull(apiKey, "aiConfig.api-key is null"); + Assert.notNull(apiKey, "ai.api-key is null"); } } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/SparkDeskAiServiceImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/SparkDeskAiServiceImpl.java index 88a240884d3..cdb4350d152 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/SparkDeskAiServiceImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/SparkDeskAiServiceImpl.java @@ -29,6 +29,7 @@ import org.apache.hertzbeat.manager.pojo.dto.SparkDeskResponse; import org.apache.hertzbeat.manager.service.AiService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -43,15 +44,16 @@ * sparkDesk AI */ @Service("SparkDeskAiServiceImpl") +@ConditionalOnProperty(prefix = "ai", name = {"api-key", "api-secret"}, matchIfMissing = false) @Slf4j public class SparkDeskAiServiceImpl implements AiService { - @Value("${aiConfig.model:generalv3.5}") + @Value("${ai.model:generalv3.5}") private String model; - @Value("${aiConfig.api-key}") + @Value("${ai.api-key}") private String apiKey; - @Value("${aiConfig.api-secret}") + @Value("${ai.api-secret}") private String apiSecret; private WebClient webClient; @@ -118,6 +120,6 @@ private String convertToResponse(String aiRes) { private void checkParam(String param, String apiKey) { Assert.notNull(param, "text is null"); - Assert.notNull(apiKey, "aiConfig.api-key is null"); + Assert.notNull(apiKey, "ai.api-key is null"); } } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/ZhiPuServiceImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/ZhiPuServiceImpl.java index d56fdb071b5..04c95992b44 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/ZhiPuServiceImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/ZhiPuServiceImpl.java @@ -29,6 +29,7 @@ import org.apache.hertzbeat.manager.pojo.dto.ZhiPuRequestParamDTO; import org.apache.hertzbeat.manager.service.AiService; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -43,11 +44,12 @@ * ZhiPu AI */ @Service("ZhiPuServiceImpl") +@ConditionalOnProperty(prefix = "ai", name = "api-key", matchIfMissing = false) @Slf4j public class ZhiPuServiceImpl implements AiService { - @Value("${aiConfig.model:glm-4}") + @Value("${ai.model:glm-4}") private String model; - @Value("${aiConfig.api-key}") + @Value("${ai.api-key}") private String apiKey; private WebClient webClient; @@ -110,7 +112,7 @@ private String convertToResponse(String aiRes) { private void checkParam(String param, String model, String apiKey) { Assert.notNull(param, "text is null"); - Assert.notNull(apiKey, "aiConfig.api-key is null"); + Assert.notNull(apiKey, "ai.api-key is null"); } diff --git a/manager/src/main/resources/application-test.yml b/manager/src/main/resources/application-test.yml index c30152d0219..9ba86b7c57d 100644 --- a/manager/src/main/resources/application-test.yml +++ b/manager/src/main/resources/application-test.yml @@ -87,7 +87,7 @@ scheduler: port: 1158 #AI config -aiConfig: +ai: #AI Type:zhiPu type: zhiPu #Model name:glm-4 diff --git a/manager/src/main/resources/application.yml b/manager/src/main/resources/application.yml index 6feb9575dc4..494d30d84dc 100644 --- a/manager/src/main/resources/application.yml +++ b/manager/src/main/resources/application.yml @@ -186,7 +186,7 @@ alerter: telegram-webhook-url: https://api.telegram.org/bot%s/sendMessage # discord discord-webhook-url: https://discord.com/api/v9/channels/%s/messages - # server酱 + # serverChan server-chan-webhook-url: https://sctapi.ftqq.com/%s.send # gotify gotify-webhook-url: http://127.0.0.1/message?token=%s @@ -198,7 +198,7 @@ scheduler: # AI config # See the documentation for details : https://hertzbeat.apache.org/zh-cn/docs/help/aiConfig -aiConfig: +ai: # AI Type:zhiPu、alibabaAi、kimiAi、sparkDesk type: # Model name:glm-4、qwen-turboo、moonshot-v1-8k、generalv3.5