Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve] : Optimize refactoring code, and supplement documentation #2239

Merged
merged 10 commits into from
Jul 8, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ interface ZhiPuConstants {
String REQUEST_ROLE = "user";

/**
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 1024
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 3072
*/
Integer MAX_TOKENS = 1024;
Integer MAX_TOKENS = 3072;

/**
* The sampling temperature, which controls the randomness of the output, must be positive
* The value ranges from 0.0 to 1.0, and cannot be equal to 0. The default value is 0.95. The larger the value,
* the more random and creative the output will be. The smaller the value, the more stable or certain the output will be
* You are advised to adjust top_p or temperature parameters based on application scenarios, but do not adjust the two parameters at the same time
*/
double TEMPERATURE = 0.95;
float TEMPERATURE = 0.7f;

}

Expand All @@ -68,17 +68,17 @@ interface AliAiConstants {
String REQUEST_ROLE = "user";

/**
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 1024
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 3072
*/
Integer MAX_TOKENS = 1024;
Integer MAX_TOKENS = 3072;

/**
* The sampling temperature, which controls the randomness of the output, must be positive
* The value ranges from 0.0 to 1.0, and cannot be equal to 0. The default value is 0.95. The larger the value,
* the more random and creative the output will be. The smaller the value, the more stable or certain the output will be
* You are advised to adjust top_p or temperature parameters based on application scenarios, but do not adjust the two parameters at the same time
*/
float TEMPERATURE = 0.9f;
float TEMPERATURE = 0.7f;


}
Expand All @@ -99,17 +99,17 @@ interface KimiAiConstants {
String REQUEST_ROLE = "user";

/**
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 1024
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 3072
*/
Integer MAX_TOKENS = 1024;
Integer MAX_TOKENS = 3072;

/**
* The sampling temperature, which controls the randomness of the output, must be positive
* The value ranges from 0.0 to 1.0, and cannot be equal to 0. The default value is 0.95. The larger the value,
* the more random and creative the output will be. The smaller the value, the more stable or certain the output will be
* You are advised to adjust top_p or temperature parameters based on application scenarios, but do not adjust the two parameters at the same time
*/
float TEMPERATURE = 0.9f;
float TEMPERATURE = 0.7f;


}
Expand All @@ -129,17 +129,17 @@ interface SparkDeskConstants {
String REQUEST_ROLE = "user";

/**
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 1024
* The model outputs the maximum tokens, with a maximum output of 8192 and a default value of 3072
*/
Integer MAX_TOKENS = 1024;
Integer MAX_TOKENS = 3072;

/**
* The sampling temperature, which controls the randomness of the output, must be positive
* The value ranges from 0.0 to 1.0, and cannot be equal to 0. The default value is 0.95. The larger the value,
* the more random and creative the output will be. The smaller the value, the more stable or certain the output will be
* You are advised to adjust top_p or temperature parameters based on application scenarios, but do not adjust the two parameters at the same time
*/
float TEMPERATURE = 0.95f;
float TEMPERATURE = 0.7f;

}

Expand Down
17 changes: 17 additions & 0 deletions home/docs/help/ai_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ keywords: [AI]
| model | moonshot-v1-8k、moonshot-v1-32k、moonshot-v1-128k | |
| api-key | xxxxxxxxxxx |https://platform.moonshot.cn/console/api-keys|

#### sparkDesk AI
QuickStart: https://www.xfyun.cn/doc/platform/quickguide.html

| Name of the parameter | Example | Link |
|--------------|-------------------------------------------------|---------------------------------------------------------------|
| type | sparkDesk (must be exactly the same as example) | |
| model | general、generalv2、generalv3、generalv3.5、4.0Ultra | |
| api-key | xxxxxxxxxxx |https://console.xfyun.cn/services/cbm|
| api-secret | xxxxxxxxxxx |https://console.xfyun.cn/services/cbm|

| sparkDesk version | model |
|-------------------|-----------------------------------------------|
| Spark4.0 Ultra | 4.0Ultra |
| Spark Max |generalv3.5 |
| Spark Pro | generalv3 |
| Spark V2.0 |generalv2 |
| Spark Lite(free) |general |
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ keywords: [人工智能 AI]
| model | moonshot-v1-8k、moonshot-v1-32k、moonshot-v1-128k | 无 |
| api-key | xxxxxxxxxxx | https://platform.moonshot.cn/console/api-keys |

#### 科大讯飞AI
快速入门:https://www.xfyun.cn/doc/platform/quickguide.html

| 参数名称 | 示例 | 链接 |
|--------------|-------------------------------------------------|---------------------------------------------------------------|
| type | sparkDesk (must be exactly the same as example) | |
| model | general、generalv2、generalv3、generalv3.5、4.0Ultra | |
| api-key | xxxxxxxxxxx |https://console.xfyun.cn/services/cbm|
| api-secret | xxxxxxxxxxx |https://console.xfyun.cn/services/cbm|

| 模型版本 | 模型类型(application.yml的model参数) |
|-----------------|-------------------------------|
| Spark4.0 Ultra | 4.0Ultra |
| Spark Max | generalv3.5 |
| Spark Pro | generalv3 |
| Spark V2.0 | generalv2 |
| Spark Lite(免费版) | general |
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hertzbeat.manager.service.impl.AiServiceFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class AiController {
@GetMapping(path = "/get", produces = {TEXT_EVENT_STREAM_VALUE})
@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,
public Flux<ServerSentEvent<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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import lombok.NoArgsConstructor;

/**
* Kimi Request param
* openAi Request param
*/

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class KimiAiRequestParamDTO {
public class OpenAiRequestParamDTO {

/**
* ai version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@

package org.apache.hertzbeat.manager.pojo.dto;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.codec.ServerSentEvent;

/**
* Kimi AiResponse
* openAi Response
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KimiAiResponse {
@Slf4j
public class OpenAiResponse {

/**
* Task order number generated by the AI open platform. Use this order number when invoking the request result interface
Expand Down Expand Up @@ -89,5 +94,22 @@ public class Tokens {
private Integer totalTokens;
}

public static ServerSentEvent<String> convertToResponse(String aiRes) {
try {
OpenAiResponse openAiResponse = JSON.parseObject(aiRes, OpenAiResponse.class);
if (Objects.nonNull(openAiResponse)) {
OpenAiResponse.Choice choice = openAiResponse.getChoices().get(0);
String content = choice.getDelta().getContent();
return ServerSentEvent.<String>builder()
.data(content)
.build();
}
} catch (Exception e) {
log.info("convertToResponse Exception:{}", e.toString());
throw e;
}

return ServerSentEvent.<String>builder().build();
}
}

This file was deleted.

This file was deleted.

Loading
Loading