Skip to content

Commit

Permalink
[improve] : Delete Chinese comments, modify word errors, add Operatio… (
Browse files Browse the repository at this point in the history
#2236)

Co-authored-by: Logic <[email protected]>
  • Loading branch information
Yanshuming1 and zqr10159 authored Jul 8, 2024
1 parent da05b6a commit 9a3a2f0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -54,8 +59,11 @@ public class AiController {
* @return AI response
*/
@GetMapping(path = "/get", produces = {TEXT_EVENT_STREAM_VALUE})
public Flux<String> 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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


Expand Down Expand Up @@ -113,6 +115,6 @@ public Flux<String> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}


Expand Down
2 changes: 1 addition & 1 deletion manager/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ scheduler:
port: 1158

#AI config
aiConfig:
ai:
#AI Type:zhiPu
type: zhiPu
#Model name:glm-4
Expand Down
4 changes: 2 additions & 2 deletions manager/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9a3a2f0

Please sign in to comment.