38 Commits

Author SHA1 Message Date
df6f1eb548 feat(web): 增加编辑侧边栏关闭时保存节点数据 2025-06-23 20:15:32 +08:00
73e6ff3c54 feat(web): 优化编辑界面 2025-06-21 10:31:11 +08:00
v-zhangjc9
ec37d04ae5 feat(web): 替换amis渲染,amis渲染太慢,导致卡顿 2025-06-21 00:08:38 +08:00
v-zhangjc9
172ef4c099 feat(web): 增加流程定义基本能力 2025-06-20 18:15:49 +08:00
v-zhangjc9
306c20aa7f fix(web): 修复删除按钮hover不是红色 2025-06-19 11:31:07 +08:00
v-zhangjc9
24d5d10ecb fix(web): 优化字号 2025-06-19 11:14:59 +08:00
v-zhangjc9
4a9a9ec238 fix(ai-web): 优化qa嵌入提示词 2025-06-19 11:10:14 +08:00
v-zhangjc9
08aa1d8382 fix(ai-web): 修复chartjs工具获取bean错误 2025-06-19 11:09:52 +08:00
v-zhangjc9
1b3045dfd4 feat(web): 统一字体展示 2025-06-19 11:09:05 +08:00
v-zhangjc9
0f5ae1c4d4 fix(ai-web): 修复超时时间设置过短导致反复重连 2025-06-18 16:09:37 +08:00
v-zhangjc9
48e42ee99a fix(ai-web): 升级部份依赖版本 2025-06-18 14:53:45 +08:00
v-zhangjc9
0914b458d3 fix(ai-web): 修复页面失去焦点的时候没有断开对话的连接 2025-06-18 10:34:56 +08:00
v-zhangjc9
368c30676e feat(ai-web): 尝试优化对话连接的稳定性 2025-06-18 10:33:44 +08:00
v-zhangjc9
60477f99f5 fix(ai-web): 修复错别字 2025-06-17 17:43:18 +08:00
v-zhangjc9
565c530dd5 feat(ai-web): 知识库增加描述 2025-06-17 17:19:04 +08:00
v-zhangjc9
5130885033 fix(ai-web): 改正包名 2025-06-17 16:18:38 +08:00
v-zhangjc9
8e6463845b feat(ai-web): 开启gzip 2025-06-17 16:16:01 +08:00
v-zhangjc9
e89bffe289 feat(ai-web): 增加Feedback详情展示和处理情况确认 2025-06-17 16:15:42 +08:00
v-zhangjc9
1dd00d329c refactor(ai-web): 优化流程编排 2025-06-17 10:35:39 +08:00
e470a87372 feat(web): 修复yarn页面查看资源队列错误 2025-06-16 23:51:36 +08:00
v-zhangjc9
45da452f18 fix(ai-web): 完成feedback AI流程 2025-06-16 20:37:14 +08:00
v-zhangjc9
e6a1bc5383 fix(ai-web): 修复取值错误 2025-06-16 17:13:16 +08:00
v-zhangjc9
c5916703cd fix(web): 修复base url错误 2025-06-16 16:12:39 +08:00
v-zhangjc9
807ddbe5cb feat(ai-web): 完成图片上传和显示 2025-06-16 13:38:42 +08:00
v-zhangjc9
13de694e37 fix(all): 修复配置错误 2025-06-16 12:13:42 +08:00
v-zhangjc9
1962dd586c feat(ai-web): 增加辅助插件 2025-06-16 11:07:56 +08:00
138ee140e1 feat(ai-web): 增加feedback 2025-06-15 23:42:26 +08:00
e2d69bc6e8 refactor(ai-web): 优化id的生成 2025-06-15 22:19:05 +08:00
b9d707dc8f refactor(gateway): 适配ai web的路由 2025-06-15 20:10:54 +08:00
44d1473c6b refactor(ai): 移除chat,合并chat和knowledge为web
以后有需要再拆分
2025-06-15 20:08:51 +08:00
9c658afbd7 refactor(ai): 迁移chat到知识库中 2025-06-15 19:59:35 +08:00
e3f86e6497 refactor(knowledge): 优化配置文件 2025-06-15 19:15:40 +08:00
256c8c6bd5 refactor(knowledge): 修改代码结构,增加多环境配置文件方便本地开发 2025-06-15 19:10:38 +08:00
b627c91acb refactor(knowledge): 重构大模型配置
Spring AI默认大模型配置不支持同时配置两个文本大模型,比如一个文本大模型和一个图像大模型,改用自定义的配置
2025-06-15 17:57:09 +08:00
7fb490778a refactor(knowledge): 优化接口结构,统一到一个路径下,为合并做准备 2025-06-15 17:02:53 +08:00
d4d5aede31 feat(ai): restClient和webClient提供给其他类使用 2025-06-14 17:45:56 +08:00
v-zhangjc9
f11f5e7656 feat(ai): 调整模型 2025-06-13 19:07:13 +08:00
v-zhangjc9
bc32a89fea fix(ai): 移除不支持的模型 2025-06-13 16:11:37 +08:00
92 changed files with 2741 additions and 3588 deletions

View File

@@ -1,14 +1,12 @@
import {cd, path} from 'zx'
import {trim} from "licia";
import {run_deploy, run_package, run_upload_normal} from '../../bin/library.js'
import {run_deploy} from '../../bin/library.js'
// 切换目录
cd(trim(path.dirname(import.meta.dirname)))
// 执行流程
try {
await run_deploy('service-ai-core')
await run_package('service-ai-chat')
await run_upload_normal('service-ai-chat')
} catch (e) {
console.error(e)
}

View File

@@ -1,14 +0,0 @@
import {cd, path} from 'zx'
import {trim} from "licia";
import {run_deploy, run_package, run_upload_normal} from '../../bin/library.js'
// 切换目录
cd(trim(path.dirname(import.meta.dirname)))
// 执行流程
try {
await run_deploy('service-ai-core')
await run_package('service-ai-knowledge')
await run_upload_normal('service-ai-knowledge')
} catch (e) {
console.error(e)
}

View File

@@ -0,0 +1,21 @@
import {
cd,
path,
} from 'zx'
import {trim} from "licia";
import {
run_deploy,
run_package,
run_upload_normal,
} from '../../bin/library.js'
// 切换目录
cd(trim(path.dirname(import.meta.dirname)))
// 执行流程
try {
await run_deploy('service-ai-core')
await run_package('service-ai-web')
await run_upload_normal('service-ai-web')
} catch (e) {
console.error(e)
}

View File

@@ -0,0 +1,11 @@
CREATE TABLE `service_ai_feedback`
(
`id` bigint NOT NULL,
`source` longtext NOT NULL,
`conclusion` longtext,
`analysis` longtext,
`pictures` longtext,
`status` varchar(50) NOT NULL DEFAULT 'ANALYSIS_PROCESSING',
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) DEFAULT CHARSET = utf8mb4;

View File

@@ -3,6 +3,7 @@ CREATE TABLE `service_ai_knowledge`
`id` bigint NOT NULL,
`vector_source_id` varchar(100) NOT NULL,
`name` varchar(100) NOT NULL,
`description` longtext NOT NULL,
`strategy` varchar(10) NOT NULL,
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

View File

@@ -11,8 +11,7 @@
<description>Hudi AI服务集合</description>
<modules>
<module>service-ai-core</module>
<module>service-ai-chat</module>
<module>service-ai-knowledge</module>
<module>service-ai-web</module>
<module>service-ai-cli</module>
</modules>
@@ -30,8 +29,21 @@
<eclipse-collections.version>11.1.0</eclipse-collections.version>
<curator.version>5.1.0</curator.version>
<hutool.version>5.8.27</hutool.version>
<mapstruct.version>1.6.3</mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- 当前项目依赖 -->
@@ -148,12 +160,22 @@
<artifactId>solon-ai-dialect-openai</artifactId>
<version>${solon-ai.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
@@ -162,7 +184,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>

View File

@@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lanyuanxiaoyao</groupId>
<artifactId>service-ai</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>service-ai-chat</artifactId>
<dependencies>
<dependency>
<groupId>com.lanyuanxiaoyao</groupId>
<artifactId>service-ai-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-deepseek</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-ai</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-ai-dialect-openai</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,44 +0,0 @@
package com.lanyuanxiaoyao.service.ai.chat.entity;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
public class MessageVO {
private String role;
private String content;
private String reason;
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Override
public String toString() {
return "MessageVO{" +
"role='" + role + '\'' +
", content='" + content + '\'' +
", reason='" + reason + '\'' +
'}';
}
}

View File

@@ -1,15 +0,0 @@
spring:
application:
name: service-ai-chat
profiles:
include: random-port,common,discovery,metrics,forest
ai:
deepseek:
base-url: http://132.121.206.65:10086/v1
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
chat:
options:
model: 'Qwen3-1.7-vllm'
mvc:
async:
request-timeout: 3600000

View File

@@ -1,16 +0,0 @@
package com.lanyuanxiaoyao.service.ai.chat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* @author lanyuanxiaoyao
* @version 20250606
*/
public class TestDatetimeFormat {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
public static void main(String[] args) {
System.out.println(LocalDate.parse("20250606", FORMATTER).format(FORMATTER));
}
}

View File

@@ -1,76 +0,0 @@
package com.lanyuanxiaoyao.service.ai.chat;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.chat.tools.TableTool;
import com.lanyuanxiaoyao.service.ai.chat.tools.YarnTool;
import java.net.http.HttpClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.reactive.JdkClientHttpConnector;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;
public class TestLlmPlan {
public static void main(String[] args) {
ChatClient client = ChatClient.builder(
DeepSeekChatModel.builder()
.deepSeekApi(
DeepSeekApi.builder()
.baseUrl("http://127.0.0.1:1234/v1")
.apiKey("nopassword")
.restClientBuilder(restClientBuilder())
.webClientBuilder(webClientBuilder())
.build()
)
.defaultOptions(
DeepSeekChatOptions.builder()
.model("qwen/qwen3-1.7b")
.build()
)
.build()
)
.defaultSystem(StrUtil.format(
"""
你是一名专业的AI运维助手专职负责“Hudi数据同步服务”的平台运维工作。你的核心职责是
1.友好解答:积极、专业地解答用户(通常是平台管理员或用户)关于该平台运维工作的疑问。
2.知识驱动:在解答时,应尽可能通过各种方式(知识库、上下文、外部工具等)全面获取准确知识和数据来支持回答。
3.诚实守界:
对于无法通过已有知识或数据确认的问题,必须明确告知用户你无法解答,切勿捏造信息或提供不确定的答案。
对于与该Hudi数据同步服务平台运维工作无关的问题需委婉拒绝用户并明确说明超出你的职责和能力范围。
对话语言:中文
{}
""",
Prompts.hudi
))
.defaultTools(
new TableTool(),
new YarnTool()
)
.build();
System.out.println(client.prompt("""
我需要大模型帮我检查系统整体运行状态,帮我设计详细的指导大模型具体操作的操作步骤
避免使用上下文中没有提到的外部工具
""").call().content());
}
private static HttpClient httpClient() {
return HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
}
private static RestClient.Builder restClientBuilder() {
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
}
private static WebClient.Builder webClientBuilder() {
return WebClient.builder()
.clientConnector(new JdkClientHttpConnector(httpClient()));
}
}

View File

@@ -1,170 +0,0 @@
package com.lanyuanxiaoyao.service.ai.chat;
import java.io.IOException;
import java.net.http.HttpClient;
import java.util.Arrays;
import java.util.List;
import org.noear.solon.ai.rag.Document;
import org.noear.solon.ai.reranking.RerankingModel;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.reactive.JdkClientHttpConnector;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author lanyuanxiaoyao
* @version 20250514
*/
public class TestSpringAIToolChat {
public static void main(String[] args) throws IOException {
testChatModel();
testVisualModel();
// testEmbeddingModel();
// testRerankingModel();
}
private static void testChatModel() {
for (String model : List.of(
"Qwen3/qwen3-0.6b",
"Qwen3/qwen3-1.7b",
"Qwen3/qwen3-4b",
"Qwen3/qwen3-4b-q4km",
"Qwen3/qwen3-8b-q4km"
)) {
ChatClient client = chatClient(model);
String content = client.prompt()
.user("你好")
.call()
.content();
System.out.println(content);
}
}
private static void testVisualModel() {
for (String model : List.of(
"Qwen2.5/qwen2.5-vl-7b",
"Qwen2.5/qwen2.5-vl-7b-q4km",
"Qwen2.5/qwen2.5-vl-3b-instruct",
"Qwen2.5/qwen2.5-vl-3b-instruct-awq",
"Qwen2.5/qwen2.5-vl-7b-instruct",
"Qwen2.5/qwen2.5-vl-7b-instruct-awq",
"MiniCPM/minicpm-o-2.6-7.6b",
"MiniCPM/minicpm-o-2.6-7.6b-q4km"
)) {
ChatClient client = chatClient(model);
String content = client.prompt()
.user(spec -> spec.text("图片中有什么").media(MimeTypeUtils.IMAGE_PNG, new FileSystemResource("/Users/lanyuanxiaoyao/Pictures/deepseek.png")))
.call()
.content();
System.out.println(content);
}
}
private static void testEmbeddingModel() {
for (String model : List.of(
"Qwen3/qwen3-embedding-0.6b",
"Qwen3/qwen3-embedding-4b",
"Qwen3/qwen3-embedding-4b-q4km",
"Qwen3/qwen3-embedding-8b-q4km",
"BGE/bge-m3",
"BGE/bge-m3-q4km",
"MiniCPM/minicpm-embedding",
"MiniCPM/minicpm-embedding-light"
)) {
EmbeddingModel embeddingModel = embeddingModel(model);
float[] worlds = embeddingModel.embed("Hello world");
System.out.println(Arrays.toString(worlds));
}
}
private static void testRerankingModel() throws IOException {
for (String model : List.of(
"BGE/beg-reranker-v2",
"MiniCPM/minicpm-reranker",
"MiniCPM/minicpm-reranker-light",
"BGE/beg-reranker-v2",
"BGE/beg-reranker-v2-q4km"
)) {
RerankingModel rerankingModel = rerankingModel(model);
List<Document> list = rerankingModel.rerank(
"你好",
List.of(
new Document("go go go滚犊子"),
new Document("我是tom你最近过得好吗"),
new Document("666你就是大聪明")
)
);
list.forEach(System.out::println);
}
}
private static ChatClient chatClient(String model) {
return ChatClient.builder(
OpenAiChatModel.builder()
.openAiApi(
OpenAiApi.builder()
.baseUrl("http://132.121.206.65:10086")
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
.restClientBuilder(restClientBuilder())
.webClientBuilder(webClientBuilder())
.build()
)
.defaultOptions(
OpenAiChatOptions.builder()
.model(model)
.build()
)
.build()
)
.build();
}
private static EmbeddingModel embeddingModel(String model) {
return new OpenAiEmbeddingModel(
OpenAiApi.builder()
.baseUrl("http://132.121.206.65:10086")
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
.restClientBuilder(restClientBuilder())
.webClientBuilder(webClientBuilder())
.build(),
MetadataMode.EMBED,
OpenAiEmbeddingOptions.builder()
.model(model)
.build()
);
}
private static RerankingModel rerankingModel(String model) {
return RerankingModel.of("http://132.121.206.65:10086/v1/rerank")
.model(model)
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
.build();
}
private static HttpClient httpClient() {
return HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
}
private static RestClient.Builder restClientBuilder() {
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
}
private static WebClient.Builder webClientBuilder() {
return WebClient.builder()
.clientConnector(new JdkClientHttpConnector(httpClient()));
}
}

View File

@@ -25,39 +25,32 @@ public class LlamaSwapTool extends GeneratorTool {
Map.of(
"models", List.of(
llamaCppEmbeddingCmd("BGE/bge-m3-q4km", "bge-m3-Q4_K_M.gguf", 20),
vllmEmbeddingCmd("BGE/bge-m3", "bge-m3", 20, 5),
vllmEmbeddingCmd("BGE/bge-m3", "bge-m3", 5),
llamaCppRerankerCmd("BGE/beg-reranker-v2-q4km", "bge-reranker-v2-m3-Q4_K_M.gguf", 20),
llamaCppRerankerCmd("BGE/beg-reranker-v2", "bge-reranker-v2-m3", 20),
vllmRerankerCmd("BGE/beg-reranker-v2", "bge-reranker-v2-m3", 5),
vllmCmd("Qwen3/qwen3-0.6b", "Qwen3-0.6B", 35, 5, true),
vllmCmd("Qwen3/qwen3-1.7b", "Qwen3-1.7B", 35, 5, true),
vllmCmd("Qwen3/qwen3-4b", "Qwen3-4B", 35, 8, true),
vllmCmd("Qwen3/qwen3-0.6b", "Qwen3-0.6B", 5, true),
vllmCmd("Qwen3/qwen3-1.7b", "Qwen3-1.7B", 5, true),
vllmCmd("Qwen3/qwen3-4b", "Qwen3-4B", 8, true),
llamaCppCmd("Qwen3/qwen3-4b-q4km", "Qwen3-4B-Q4_K_M.gguf", 35),
llamaCppCmd("Qwen3/qwen3-8b-q4km", "Qwen3-8B-Q4_K_M.gguf", 35),
vllmEmbeddingCmd("Qwen3/qwen3-embedding-0.6b", "Qwen3-Embedding-0.6B", 35, 5),
vllmEmbeddingCmd("Qwen3/qwen3-embedding-4b", "Qwen3-Embedding-4B", 35, 8),
vllmEmbeddingCmd("Qwen3/qwen3-embedding-0.6b", "Qwen3-Embedding-0.6B", 5),
vllmEmbeddingCmd("Qwen3/qwen3-embedding-4b", "Qwen3-Embedding-4B", 8),
llamaCppEmbeddingCmd("Qwen3/qwen3-embedding-4b-q4km", "Qwen3-Embedding-4B-Q4_K_M.gguf", 35),
llamaCppEmbeddingCmd("Qwen3/qwen3-embedding-8b-q4km", "Qwen3-Embedding-8B-Q4_K_M.gguf", 35),
vllmRerankerCmd("Qwen3/qwen3-reranker-0.6b", "Qwen3-Reranker-0.6B", 35, 5),
vllmRerankerCmd("Qwen3/qwen3-reranker-4b", "Qwen3-Reranker-4B", 35, 8),
// 0.9.1 vllm还未支持
// vllmRerankerCmd("Qwen3/qwen3-reranker-0.6b", "Qwen3-Reranker-0.6B", 5),
// vllmRerankerCmd("Qwen3/qwen3-reranker-4b", "Qwen3-Reranker-4B", 8),
llamaCppVisualCmd("Qwen2.5/qwen2.5-vl-7b", "Qwen2.5-VL-7B-Instruct-BF16.gguf", 35),
llamaCppVisualCmd("Qwen2.5/qwen2.5-vl-7b-q4km", "Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf", 35),
vllmCmd("Qwen2.5/qwen2.5-vl-7b-instruct", "Qwen2.5-VL-7B-Instruct", 35, 8, false),
vllmCmd("Qwen2.5/qwen2.5-vl-7b-instruct-awq", "Qwen2.5-VL-7B-Instruct-AWQ", 35, 8, false),
vllmCmd("Qwen2.5/qwen2.5-vl-3b-instruct", "Qwen2.5-VL-3B-Instruct", 35, 8, false),
vllmCmd("Qwen2.5/qwen2.5-vl-3b-instruct-awq", "Qwen2.5-VL-3B-Instruct-AWQ", 35, 8, false),
vllmCmd("Qwen2.5/qwen2.5-vl-3b-instruct", "Qwen2.5-VL-3B-Instruct", 8, false),
vllmCmd("Qwen2.5/qwen2.5-vl-7b-instruct", "Qwen2.5-VL-7B-Instruct", 8, false),
llamaCppVisualCmd("MiniCPM/minicpm-o-2.6-7.6b-q4km", "MiniCPM-o-2_6-7.6B-Q4_K_M.gguf", 35),
vllmCmd("MiniCPM/minicpm-o-2.6-7.6b", "MiniCPM-o-2_6", 35, 10, false),
vllmEmbeddingCmd("MiniCPM/minicpm-embedding", "MiniCPM-Embedding", 20, 8),
vllmEmbeddingCmd("MiniCPM/minicpm-embedding-light", "MiniCPM-Embedding-Light", 20, 5),
vllmEmbeddingCmd("MiniCPM/minicpm-reranker", "MiniCPM-Reranker", 20, 8),
vllmEmbeddingCmd("MiniCPM/minicpm-reranker-light", "MiniCPM-Reranker-Light", 20, 5)
vllmCmd("MiniCPM/minicpm-o-2.6-7.6b", "MiniCPM-o-2_6", 10, false)
)
),
"config.yaml"
@@ -114,23 +107,23 @@ public class LlamaSwapTool extends GeneratorTool {
);
}
private DockerCmd vllmCmd(String name, String model, Integer thread, Integer cache, Boolean isReasonable) {
return vllmCmd(name, model, thread, cache, false, false, isReasonable, false);
private DockerCmd vllmCmd(String name, String model, Integer cache, Boolean isReasonable) {
return vllmCmd(name, model, cache, false, false, isReasonable);
}
private DockerCmd vllmEmbeddingCmd(String name, String model, Integer thread, Integer cache) {
return vllmCmd(name, model, thread, cache, true, false, false, false);
private DockerCmd vllmEmbeddingCmd(String name, String model, Integer cache) {
return vllmCmd(name, model, cache, true, false, false);
}
private DockerCmd vllmRerankerCmd(String name, String model, Integer thread, Integer cache) {
return vllmCmd(name, model, thread, cache, false, true, false, false);
private DockerCmd vllmRerankerCmd(String name, String model, Integer cache) {
return vllmCmd(name, model, cache, false, true, false);
}
private DockerCmd vllmVisualCmd(String name, String model, Integer thread, Integer cache, Boolean isReasonable) {
return vllmCmd(name, model, thread, cache, false, false, isReasonable, true);
private DockerCmd vllmVisualCmd(String name, String model, Integer cache, Boolean isReasonable) {
return vllmCmd(name, model, cache, false, false, isReasonable);
}
private DockerCmd vllmCmd(String name, String model, Integer thread, Integer cache, Boolean isEmbedding, Boolean isReranker, Boolean isReasonable, Boolean isVisual) {
private DockerCmd vllmCmd(String name, String model, Integer cache, Boolean isEmbedding, Boolean isReranker, Boolean isReasonable) {
List<String> arguments = ListUtil.list(
false,
StrUtil.format("--model /models/{}", model),
@@ -138,11 +131,13 @@ public class LlamaSwapTool extends GeneratorTool {
"--port ${PORT}",
StrUtil.format("--api-key {}", API_KEY),
"--disable-log-requests",
"--uvicorn-log-level error"
"--uvicorn-log-level error",
"--trust-remote-code"
);
if (isEmbedding) {
arguments.add("--task embedding");
} else if (isReranker) {
arguments.add("--task score");
} else if (isReasonable) {
arguments.add("--enable-auto-tool-choice");
arguments.add("--tool-call-parser hermes");
@@ -150,7 +145,7 @@ public class LlamaSwapTool extends GeneratorTool {
arguments.add("--reasoning-parser deepseek_r1");
}
return new DockerCmd(
"vllm-server-cpu:0.9.1",
"vllm-server-cpu:0.8.5.post1",
name,
model,
StrUtil.format("http://vllm-{}:${PORT}", displayName(model)),
@@ -158,9 +153,7 @@ public class LlamaSwapTool extends GeneratorTool {
StrUtil.format("--name vllm-{}", displayName(model)),
"--privileged=true",
"--shm-size=4g",
StrUtil.format("-e VLLM_CPU_KVCACHE_SPACE={}", cache),
StrUtil.format("-e VLLM_CPU_OMP_THREADS_BIND=0-{}", thread - 1),
"-e VLLM_CPU_MOE_PREPACK=0"
StrUtil.format("-e VLLM_CPU_KVCACHE_SPACE={}", cache)
),
arguments
);

View File

@@ -1,4 +1,4 @@
healthCheckTimeout: 120
healthCheckTimeout: 600
logLevel: warn
models:
<#list models as model>

View File

@@ -0,0 +1,74 @@
package com.lanyuanxiaoyao.service.ai.core.configuration;
import java.time.Instant;
/**
* 使用雪花算法作为ID生成器
*
* @author lanyuanxiaoyao
* @date 2024-11-14
*/
public class SnowflakeId {
/**
* 起始的时间戳
*/
private final static long START_TIMESTAMP = 1;
/**
* 序列号占用的位数
*/
private final static long SEQUENCE_BIT = 11;
/**
* 序列号最大值
*/
private final static long MAX_SEQUENCE_BIT = ~(-1 << SEQUENCE_BIT);
/**
* 时间戳值向左位移
*/
private final static long TIMESTAMP_OFFSET = SEQUENCE_BIT;
/**
* 序列号
*/
private static long sequence = 0;
/**
* 上一次时间戳
*/
private static long lastTimestamp = -1;
public static synchronized long next() {
long currentTimestamp = nowTimestamp();
if (currentTimestamp < lastTimestamp) {
throw new RuntimeException("Clock have moved backwards.");
}
if (currentTimestamp == lastTimestamp) {
// 相同毫秒内, 序列号自增
sequence = (sequence + 1) & MAX_SEQUENCE_BIT;
// 同一毫秒的序列数已经达到最大
if (sequence == 0) {
currentTimestamp = nextTimestamp();
}
} else {
// 不同毫秒内, 序列号置为0
sequence = 0;
}
lastTimestamp = currentTimestamp;
return (currentTimestamp - START_TIMESTAMP) << TIMESTAMP_OFFSET | sequence;
}
private static long nextTimestamp() {
long milli = nowTimestamp();
while (milli <= lastTimestamp) {
milli = nowTimestamp();
}
return milli;
}
private static long nowTimestamp() {
return Instant.now().toEpochMilli();
}
}

View File

@@ -17,22 +17,30 @@ import org.springframework.web.reactive.function.client.WebClient;
*/
@Configuration
public class WebClientConfiguration {
private HttpClient httpClient() {
return HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
}
@Bean
@Primary
public RestClient.Builder restClientBuilder() {
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
return generateRestClientBuilder();
}
@Bean
@Primary
public WebClient.Builder webClientBuilder() {
return generateWebClientBuilder();
}
private static HttpClient httpClient() {
return HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
}
public static RestClient.Builder generateRestClientBuilder() {
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
}
public static WebClient.Builder generateWebClientBuilder() {
return WebClient.builder()
.clientConnector(new JdkClientHttpConnector(httpClient()));
}

View File

@@ -4,6 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -20,11 +21,15 @@ import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests(registry -> registry.anyRequest().authenticated())
return http.authorizeHttpRequests(
registry -> registry
.requestMatchers(HttpMethod.OPTIONS, "/**")
.permitAll()
.anyRequest()
.authenticated()
)
.httpBasic(Customizer.withDefaults())
.cors(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)

View File

@@ -1,31 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author lanyuanxiaoyao
* @version 20250515
*/
@SpringBootApplication(scanBasePackages = "com.lanyuanxiaoyao.service")
@EnableDiscoveryClient
@EnableConfigurationProperties
@EnableEncryptableProperties
@EnableRetry
@EnableScheduling
public class KnowledgeApplication implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(KnowledgeApplication.class, args);
}
@Override
public void run(ApplicationArguments args) {
}
}

View File

@@ -1,39 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
@Configuration
@ConfigurationProperties(prefix = "knowledge")
public class KnowledgeConfiguration {
private String downloadPrefix;
private String uploadPath;
public String getDownloadPrefix() {
return downloadPrefix;
}
public void setDownloadPrefix(String downloadPrefix) {
this.downloadPrefix = downloadPrefix;
}
public String getUploadPath() {
return uploadPath;
}
public void setUploadPath(String uploadPath) {
this.uploadPath = uploadPath;
}
@Override
public String toString() {
return "KnowledgeConfiguration{" +
"downloadPrefix='" + downloadPrefix + '\'' +
", uploadPath='" + uploadPath + '\'' +
'}';
}
}

View File

@@ -1,21 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.configuration;
import cn.hutool.core.util.StrUtil;
import org.noear.solon.ai.reranking.RerankingModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author lanyuanxiaoyao
* @version 20250604
*/
@Configuration
public class SolonConfiguration {
@Bean
public RerankingModel rerankingModel(SolonProperties solonProperties) {
return RerankingModel.of(StrUtil.format("{}{}", solonProperties.getBaseUrl(), solonProperties.getRerank().getEndpoint()))
.apiKey(solonProperties.getApiKey())
.model(solonProperties.getRerank().getModel())
.build();
}
}

View File

@@ -1,78 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author lanyuanxiaoyao
* @version 20250604
*/
@Configuration
@ConfigurationProperties(prefix = "solon")
public class SolonProperties {
private String baseUrl;
private String apiKey;
private Rerank rerank;
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public Rerank getRerank() {
return rerank;
}
public void setRerank(Rerank rerank) {
this.rerank = rerank;
}
@Override
public String toString() {
return "SolonProperties{" +
"baseUrl='" + baseUrl + '\'' +
", apiKey='" + apiKey + '\'' +
", rerank=" + rerank +
'}';
}
public static final class Rerank {
private String model;
private String endpoint;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
@Override
public String toString() {
return "Rerank{" +
"model='" + model + '\'' +
", endpoint='" + endpoint + '\'' +
'}';
}
}
}

View File

@@ -1,202 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity;
import java.util.List;
import java.util.Map;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.springframework.ai.document.Document;
/**
* @author lanyuanxiaoyao
* @version 20250523
*/
public class EmbeddingContext {
private Long vectorSourceId;
private Long groupId;
private Config config;
private String content;
private String file;
private String fileFormat;
private List<Document> documents = Lists.mutable.empty();
private Map<String, Object> metadata = Maps.mutable.empty();
private EmbeddingContext(Builder builder) {
setVectorSourceId(builder.vectorSourceId);
setGroupId(builder.groupId);
setConfig(builder.config);
setContent(builder.content);
setFile(builder.file);
setFileFormat(builder.fileFormat);
}
public static Builder builder() {
return new Builder();
}
public Long getGroupId() {
return groupId;
}
public void setGroupId(Long groupId) {
this.groupId = groupId;
}
public Long getVectorSourceId() {
return vectorSourceId;
}
public void setVectorSourceId(Long vectorSourceId) {
this.vectorSourceId = vectorSourceId;
}
public Config getConfig() {
return config;
}
public void setConfig(Config config) {
this.config = config;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getFileFormat() {
return fileFormat;
}
public void setFileFormat(String fileFormat) {
this.fileFormat = fileFormat;
}
public List<Document> getDocuments() {
return documents;
}
public void setDocuments(List<Document> documents) {
this.documents = documents;
}
public Map<String, Object> getMetadata() {
return metadata;
}
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}
@Override
public String toString() {
return "EmbeddingContext{" +
"vectorSourceId=" + vectorSourceId +
", groupId=" + groupId +
", config=" + config +
", content='" + content + '\'' +
", file='" + file + '\'' +
", fileFormat='" + fileFormat + '\'' +
", documents=" + documents +
", metadata=" + metadata +
'}';
}
public static final class Config {
private SplitStrategy splitStrategy = SplitStrategy.NORMAL;
private Config(Builder builder) {setSplitStrategy(builder.splitStrategy);}
public static Builder builder() {
return new Builder();
}
public SplitStrategy getSplitStrategy() {
return splitStrategy;
}
public void setSplitStrategy(SplitStrategy splitStrategy) {
this.splitStrategy = splitStrategy;
}
@Override
public String toString() {
return "Config{" +
"splitStrategy=" + splitStrategy +
'}';
}
public enum SplitStrategy {
NORMAL, LLM, QA
}
public static final class Builder {
private SplitStrategy splitStrategy;
private Builder() {}
public Builder splitStrategy(SplitStrategy val) {
splitStrategy = val;
return this;
}
public Config build() {
return new Config(this);
}
}
}
public static final class Builder {
private Long vectorSourceId;
private Long groupId;
private Config config;
private String content;
private String file;
private String fileFormat;
private Builder() {}
public Builder vectorSourceId(Long val) {
vectorSourceId = val;
return this;
}
public Builder groupId(Long val) {
groupId = val;
return this;
}
public Builder config(Config val) {
config = val;
return this;
}
public Builder content(String val) {
content = val;
return this;
}
public Builder file(String val) {
file = val;
return this;
}
public Builder fileFormat(String val) {
fileFormat = val;
return this;
}
public EmbeddingContext build() {
return new EmbeddingContext(this);
}
}
}

View File

@@ -1,64 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
public class Group {
private String id;
private String name;
private String status;
private Long createdTime;
private Long modifiedTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Long getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Long createdTime) {
this.createdTime = createdTime;
}
public Long getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Long modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "GroupVO{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", status='" + status + '\'' +
", createdTime=" + createdTime +
", modifiedTime=" + modifiedTime +
'}';
}
}

View File

@@ -1,74 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity;
/**
* @author lanyuanxiaoyao
* @version 20250522
*/
public class Knowledge {
private Long id;
private Long vectorSourceId;
private String name;
private String strategy;
private Long createdTime;
private Long modifiedTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getVectorSourceId() {
return vectorSourceId;
}
public void setVectorSourceId(Long vectorSourceId) {
this.vectorSourceId = vectorSourceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStrategy() {
return strategy;
}
public void setStrategy(String strategy) {
this.strategy = strategy;
}
public Long getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Long createdTime) {
this.createdTime = createdTime;
}
public Long getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Long modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "Knowledge{" +
"id=" + id +
", vectorSourceId=" + vectorSourceId +
", name='" + name + '\'' +
", strategy='" + strategy + '\'' +
", createdTime=" + createdTime +
", modifiedTime=" + modifiedTime +
'}';
}
}

View File

@@ -1,74 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity.vo;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
public class DataFileVO {
private String id;
private String filename;
private Long size;
private String md5;
private String path;
private String type;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "DataFile{" +
"id='" + id + '\'' +
", filename='" + filename + '\'' +
", size=" + size +
", md5='" + md5 + '\'' +
", path='" + path + '\'' +
", type='" + type + '\'' +
'}';
}
}

View File

@@ -1,114 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity.vo;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
public class KnowledgeVO {
private String id;
private String vectorSourceId;
private String name;
private String strategy;
private Long size;
private Long points;
private Long segments;
private String status;
private Long createdTime;
private Long modifiedTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getVectorSourceId() {
return vectorSourceId;
}
public void setVectorSourceId(String vectorSourceId) {
this.vectorSourceId = vectorSourceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStrategy() {
return strategy;
}
public void setStrategy(String strategy) {
this.strategy = strategy;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public Long getPoints() {
return points;
}
public void setPoints(Long points) {
this.points = points;
}
public Long getSegments() {
return segments;
}
public void setSegments(Long segments) {
this.segments = segments;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Long getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Long createdTime) {
this.createdTime = createdTime;
}
public Long getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Long modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "KnowledgeVO{" +
"id='" + id + '\'' +
", vectorSourceId='" + vectorSourceId + '\'' +
", name='" + name + '\'' +
", strategy='" + strategy + '\'' +
", size=" + size +
", points=" + points +
", segments=" + segments +
", status='" + status + '\'' +
", createdTime=" + createdTime +
", modifiedTime=" + modifiedTime +
'}';
}
}

View File

@@ -1,34 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge.entity.vo;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
public class SegmentVO {
private String id;
private String text;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public String toString() {
return "PointVO{" +
"id='" + id + '\'' +
", text='" + text + '\'' +
'}';
}
}

View File

@@ -1,30 +0,0 @@
spring:
application:
name: service-ai-knowledge
profiles:
include: random-port,common,discovery,metrics,forest
ai:
openai:
base-url: http://132.121.206.65:10086
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
chat:
options:
model: 'Qwen3-1.7-vllm'
embedding:
options:
model: 'Bge-m3-vllm'
vectorstore:
qdrant:
host: 132.121.206.65
port: 29463
api-key: ENC(0/0UkIKeAvyV17yNqSU3v04wmm8CdWKe4BYSSJa2FuBtK12TcZRJPdwk+ZpYnpISv+KmVTUrrmFBzAYrDR3ysA==)
liteflow:
rule-source: config/flow.xml
print-banner: false
check-node-exists: false
solon:
base-url: http://132.121.206.65:10086
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
rerank:
model: 'Bge-reranker-v2-vllm'
endpoint: '/v1/rerank'

View File

@@ -1,34 +0,0 @@
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<springProperty scope="context" name="LOKI_PUSH_URL" source="loki.url"/>
<springProperty scope="context" name="LOGGING_PARENT" source="logging.parent"/>
<springProperty scope="context" name="APP_NAME" source="spring.application.name"/>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr([${HOSTNAME}]){yellow} %clr([%t]){magenta} %clr(%logger{40}){cyan} #@# %m%n%wEx</pattern>
</encoder>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGGING_PARENT:-.}/${APP_NAME:-run}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGGING_PARENT:-.}/archive/${APP_NAME:-run}-%d{yyyy-MM-dd}.gz</fileNamePattern>
<MaxHistory>7</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [${HOSTNAME}] [%t] %logger #@# %m%n%wEx</pattern>
</encoder>
</appender>
<logger name="com.zaxxer.hikari" level="ERROR"/>
<logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
<root level="INFO">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
</root>
</configuration>

View File

@@ -1,116 +0,0 @@
package com.lanyuanxiaoyao.service.ai.knowledge;
import java.net.http.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.reactive.JdkClientHttpConnector;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author lanyuanxiaoyao
* @version 20250526
*/
public class TestLlm {
private static final Logger log = LoggerFactory.getLogger(TestLlm.class);
public static void main(String[] args) {
HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
ChatClient client = ChatClient.builder(
OpenAiChatModel.builder()
.openAiApi(
OpenAiApi.builder()
.baseUrl("http://132.121.206.65:10086")
.apiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4")
.webClientBuilder(WebClient.builder().clientConnector(new JdkClientHttpConnector(httpClient)))
.restClientBuilder(RestClient.builder().requestFactory(new JdkClientHttpRequestFactory(httpClient)))
.build()
)
.defaultOptions(
OpenAiChatOptions.builder()
.model("Qwen3-1.7-vllm")
.build()
)
.build()
)
.build();
String content = client.prompt()
.system("""
对用户输入的文本,生成多组高质量的问答对。请遵循以下指南:
1. 问题部分:
为同一个主题创建尽可能多的不同表述的问题,确保问题的多样性。
每个问题应考虑用户可能的多种问法,例如:
直接询问(如“什么是...?”)
请求确认(如“是否可以说...?”)
寻求解释(如“请解释一下...的含义。”)
假设性问题(如“如果...会怎样?”)
例子请求(如“能否举个例子说明...?”)
问题应涵盖文本中的关键信息、主要概念和细节,确保不遗漏重要内容。
2. 答案部分:
提供一个全面、信息丰富的答案,涵盖问题的所有可能角度,确保逻辑连贯。
答案应直接基于给定文本,确保准确性和一致性。
包含相关的细节,如日期、名称、职位等具体信息,必要时提供背景信息以增强理解。
3. 格式:
使用"问:"标记问题集合的开始,所有问题应在一个段落内,问题之间用空格分隔。
使用"答:"标记答案的开始,答案应清晰分段,便于阅读。
问答对之间用“---”分隔,以提高可读性。
4. 内容要求:
确保问答对紧密围绕文本主题,避免偏离主题。
避免添加文本中未提及的信息,确保信息的真实性。
一个问题搭配一个答案,避免一组问答对中同时涉及多个问题。
如果文本信息不足以回答某个方面,可以在答案中说明 "根据给定信息无法确定",并尽量提供相关的上下文。
""")
.user("""
Apache Hudi 是一款开源的数据湖管理框架,专注于高效处理大规模数据集的增量更新和实时操作。以下是其核心要点介绍:
核心功能与特性
增量数据处理支持插入Insert、更新Update、删除Delete操作并通过“Upsert”插入或更新机制高效处理变更数据避免重写整个数据集。
事务支持:提供 ACID 事务保证,确保数据一致性和可靠性,支持原子提交和回滚。
存储优化:自动合并小文件并维护文件最佳大小,减少存储碎片化问题,提升查询性能。
多查询类型:
快照查询:获取最新数据状态(对 MoR 表合并基础文件和增量文件)。
增量查询:捕获自某次提交后的变更数据流,适用于增量管道。
读取优化查询:针对 MoR 表展示最新压缩后的数据。
存储模型
写入时复制Copy-on-Write, CoW数据以列式格式如 Parquet存储每次更新生成新版本文件适合读多写少的场景。
读取时合并Merge-on-Read, MoR结合列式Parquet和行式Avro存储更新写入增量文件后异步合并适合写频繁的场景。
适用场景
合规性需求:支持 GDPR、CCPA 等法规要求的数据删除和更新。
实时数据流处理:如 IoT 设备数据、CDC变更数据捕获系统实现近实时分析。
数据湖管理:优化大规模数据集的存储和查询效率,支持时间旅行查询和历史版本回溯。
技术生态与兼容性
多引擎支持:与 Spark、Flink、Hive、Presto、Trino 等计算和查询引擎集成。
存储格式:基于 Parquet 和 Avro兼容 Hadoop 生态及云存储(如 Amazon S3
优势对比
相较于同类产品(如 Apache Iceberg、Delta LakeHudi 在实时更新和增量处理方面表现突出,尤其适合需要频繁数据变更的场景。其独特的 MoR 模型在写入性能上优于传统批处理方案。
总结
Apache Hudi 通过灵活的存储模型、高效的事务管理和广泛的生态系统集成,成为构建现代化数据湖的核心工具,适用于金融、物联网、实时分析等对数据新鲜度和操作效率要求高的领域。
""")
.call()
.content();
log.info(content);
}
}

View File

@@ -9,7 +9,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>service-ai-knowledge</artifactId>
<artifactId>service-ai-web</artifactId>
<dependencies>
<dependency>
@@ -26,6 +26,10 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-deepseek</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-vector-store-qdrant</artifactId>
@@ -66,6 +70,32 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Amapstruct.defaultComponentModel=spring</arg>
<arg>-Amapstruct.defaultInjectionStrategy=constructor</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

View File

@@ -1,7 +1,9 @@
package com.lanyuanxiaoyao.service.ai.chat;
package com.lanyuanxiaoyao.service.ai.web;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.beans.BeansException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -9,29 +11,39 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author lanyuanxiaoyao
* @version 20250514
* @version 20250515
*/
@SpringBootApplication(scanBasePackages = "com.lanyuanxiaoyao.service")
@EnableDiscoveryClient
@EnableConfigurationProperties
@EnableEncryptableProperties
@EnableRetry
public class AiChatApplication implements ApplicationContextAware {
@EnableScheduling
public class WebApplication implements ApplicationRunner, ApplicationContextAware {
private static ApplicationContext context;
public static void main(String[] args) {
SpringApplication.run(AiChatApplication.class, args);
SpringApplication.run(WebApplication.class, args);
}
public static <T> T getBean(Class<T> clazz) {
return context.getBean(clazz);
}
public static <T> T getBean(String name, Class<T> clazz) {
return context.getBean(name, clazz);
}
@Override
public void run(ApplicationArguments args) {
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
AiChatApplication.context = context;
WebApplication.context = context;
}
}

View File

@@ -0,0 +1,17 @@
package com.lanyuanxiaoyao.service.ai.web.configuration;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "file-store")
public class FileStoreProperties {
private String downloadPrefix;
private String uploadPath;
}

View File

@@ -0,0 +1,111 @@
package com.lanyuanxiaoyao.service.ai.web.configuration;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import java.time.Duration;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.ai.reranking.RerankingModel;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;
@Slf4j
@Configuration
public class LlmConfiguration {
@Bean("chat")
public ChatClient.Builder chatClientBuilder(LlmProperties llmProperties, WebClient.Builder webClientBuilder, RestClient.Builder restClientBuilder) {
Assert.notNull(llmProperties.getChat(), "chat properties is null");
DeepSeekApi.Builder apiBuilder = DeepSeekApi.builder()
.baseUrl(StrUtil.firstNonBlank(llmProperties.getChat().getBaseUrl(), llmProperties.getBaseUrl()))
.apiKey(StrUtil.firstNonBlank(llmProperties.getChat().getApiKey(), llmProperties.getApiKey()))
.webClientBuilder(webClientBuilder)
.restClientBuilder(restClientBuilder);
if (StrUtil.isNotBlank(llmProperties.getChat().getEndpoint())) {
apiBuilder.completionsPath(llmProperties.getChat().getEndpoint());
}
return ChatClient.builder(
DeepSeekChatModel.builder()
.deepSeekApi(apiBuilder.build())
.defaultOptions(
DeepSeekChatOptions.builder()
.model(llmProperties.getChat().getModel())
.build()
)
.build()
);
}
@Bean("visual")
public ChatClient.Builder visualClientBuilder(LlmProperties llmProperties, WebClient.Builder webClientBuilder, RestClient.Builder restClientBuilder) {
Assert.notNull(llmProperties.getVisual(), "visual properties is null");
OpenAiApi.Builder apiBuilder = OpenAiApi.builder()
.baseUrl(StrUtil.firstNonBlank(llmProperties.getVisual().getBaseUrl(), llmProperties.getBaseUrl()))
.apiKey(StrUtil.firstNonBlank(llmProperties.getVisual().getApiKey(), llmProperties.getApiKey()))
.webClientBuilder(webClientBuilder)
.restClientBuilder(restClientBuilder);
if (StrUtil.isNotBlank(llmProperties.getVisual().getEndpoint())) {
apiBuilder.completionsPath(llmProperties.getVisual().getEndpoint());
}
return ChatClient.builder(
OpenAiChatModel.builder()
.openAiApi(apiBuilder.build())
.defaultOptions(
OpenAiChatOptions.builder()
.model(llmProperties.getVisual().getModel())
.build()
)
.build()
);
}
@Bean
public EmbeddingModel embeddingModel(LlmProperties llmProperties, WebClient.Builder webClientBuilder, RestClient.Builder restClientBuilder) {
Assert.notNull(llmProperties.getEmbedding(), "embedding properties is null");
OpenAiApi.Builder apiBuilder = OpenAiApi.builder()
.baseUrl(StrUtil.firstNonBlank(llmProperties.getEmbedding().getBaseUrl(), llmProperties.getBaseUrl()))
.apiKey(StrUtil.firstNonBlank(llmProperties.getEmbedding().getApiKey(), llmProperties.getApiKey()))
.webClientBuilder(webClientBuilder)
.restClientBuilder(restClientBuilder);
if (StrUtil.isNotBlank(llmProperties.getEmbedding().getEndpoint())) {
apiBuilder.embeddingsPath(llmProperties.getEmbedding().getEndpoint());
}
return new OpenAiEmbeddingModel(
apiBuilder.build(),
MetadataMode.EMBED,
OpenAiEmbeddingOptions.builder()
.model(llmProperties.getEmbedding().getModel())
.build()
);
}
@Bean
public RerankingModel rerankingModel(LlmProperties llmProperties) {
Assert.notNull(llmProperties.getReranker(), "reranker properties is null");
String url = llmProperties.getBaseUrl();
if (StrUtil.isNotBlank(llmProperties.getReranker().getBaseUrl())) {
url = llmProperties.getReranker().getBaseUrl();
}
if (StrUtil.isNotBlank(llmProperties.getReranker().getEndpoint())) {
url += llmProperties.getReranker().getEndpoint();
} else {
url += "/v1/rerank";
}
return RerankingModel.of(url)
.apiKey(StrUtil.firstNonBlank(llmProperties.getReranker().getApiKey(), llmProperties.getApiKey()))
.model(llmProperties.getReranker().getModel())
.timeout(Duration.ofMinutes(10))
.build();
}
}

View File

@@ -0,0 +1,25 @@
package com.lanyuanxiaoyao.service.ai.web.configuration;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
@ConfigurationProperties(prefix = "spring.llm")
public class LlmProperties {
private String baseUrl;
private String apiKey;
private ChatProperties chat;
private ChatProperties visual;
private ChatProperties embedding;
private ChatProperties reranker;
@Data
public static class ChatProperties {
private String baseUrl;
private String apiKey;
private String model;
private String endpoint;
}
}

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.ai.chat;
package com.lanyuanxiaoyao.service.ai.web.configuration;
import cn.hutool.core.util.StrUtil;

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.ai.knowledge.controller;
package com.lanyuanxiaoyao.service.ai.web.controller;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
@@ -7,9 +7,9 @@ import cn.hutool.core.util.URLUtil;
import cn.hutool.crypto.SecureUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.knowledge.configuration.KnowledgeConfiguration;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.knowledge.service.DataFileService;
import com.lanyuanxiaoyao.service.ai.web.configuration.FileStoreProperties;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.web.service.DataFileService;
import jakarta.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -17,9 +17,11 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -35,22 +37,21 @@ import org.springframework.web.multipart.MultipartFile;
* @author lanyuanxiaoyao
* @date 2024-11-21
*/
@Slf4j
@RestController
@RequestMapping("/upload")
public class DataFileController {
private static final Logger log = LoggerFactory.getLogger(DataFileController.class);
private final KnowledgeConfiguration knowledgeConfiguration;
private final FileStoreProperties fileStoreProperties;
private final DataFileService dataFileService;
private final String uploadFolderPath;
private final String cacheFolderPath;
private final String sliceFolderPath;
public DataFileController(KnowledgeConfiguration knowledgeConfiguration, DataFileService dataFileService) {
this.knowledgeConfiguration = knowledgeConfiguration;
public DataFileController(FileStoreProperties fileStoreProperties, DataFileService dataFileService) {
this.fileStoreProperties = fileStoreProperties;
this.dataFileService = dataFileService;
this.uploadFolderPath = knowledgeConfiguration.getUploadPath();
this.uploadFolderPath = fileStoreProperties.getUploadPath();
this.cacheFolderPath = StrUtil.format("{}/cache", uploadFolderPath);
this.sliceFolderPath = StrUtil.format("{}/slice", uploadFolderPath);
}
@@ -59,7 +60,7 @@ public class DataFileController {
public AmisResponse<FinishResponse> upload(@RequestParam("file") MultipartFile file) throws IOException {
String filename = file.getOriginalFilename();
Long id = dataFileService.initialDataFile(filename);
String url = StrUtil.format("{}/upload/download/{}", knowledgeConfiguration.getDownloadPrefix(), id);
String url = StrUtil.format("{}/upload/download/{}", fileStoreProperties.getDownloadPrefix(), id);
byte[] bytes = file.getBytes();
String originMd5 = SecureUtil.md5(new ByteArrayInputStream(bytes));
File targetFile = new File(StrUtil.format("{}/{}", uploadFolderPath, originMd5));
@@ -79,7 +80,7 @@ public class DataFileController {
}
@GetMapping("/download/{id}")
public void download(@PathVariable Long id, HttpServletResponse response) throws IOException {
public void download(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
DataFileVO dataFile = dataFileService.downloadFile(id);
File targetFile = new File(dataFile.getPath());
response.setHeader("Content-Type", dataFile.getType());
@@ -156,7 +157,7 @@ public class DataFileController {
request.uploadId,
request.filename,
request.uploadId.toString(),
StrUtil.format("{}/upload/download/{}", knowledgeConfiguration.getDownloadPrefix(), request.uploadId)
StrUtil.format("{}/upload/download/{}", fileStoreProperties.getDownloadPrefix(), request.uploadId)
));
} else {
throw new RuntimeException("合并文件失败");
@@ -169,213 +170,48 @@ public class DataFileController {
}
}
@Data
public static final class StartRequest {
private String name;
private String filename;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
@Override
public String toString() {
return "StartRequest{" +
"name='" + name + '\'' +
", filename='" + filename + '\'' +
'}';
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static final class StartResponse {
private String uploadId;
public StartResponse() {
}
public StartResponse(String uploadId) {
this.uploadId = uploadId;
}
public String getUploadId() {
return uploadId;
}
public void setUploadId(String uploadId) {
this.uploadId = uploadId;
}
@Override
public String toString() {
return "StartResponse{" +
"uploadId='" + uploadId + '\'' +
'}';
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static final class SliceResponse {
@JsonProperty("eTag")
private String eTag;
public SliceResponse() {
}
public SliceResponse(String eTag) {
this.eTag = eTag;
}
public String geteTag() {
return eTag;
}
public void seteTag(String eTag) {
this.eTag = eTag;
}
@Override
public String toString() {
return "SliceResponse{" +
"eTag='" + eTag + '\'' +
'}';
}
}
@Data
public static final class FinishRequest {
private String filename;
private Long uploadId;
private ImmutableList<Part> partList;
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public Long getUploadId() {
return uploadId;
}
public void setUploadId(Long uploadId) {
this.uploadId = uploadId;
}
public ImmutableList<Part> getPartList() {
return partList;
}
public void setPartList(ImmutableList<Part> partList) {
this.partList = partList;
}
@Override
public String toString() {
return "FinishRequest{" +
"filename='" + filename + '\'' +
", uploadId=" + uploadId +
", partList=" + partList +
'}';
}
@Data
public static final class Part {
private Integer partNumber;
@JsonProperty("eTag")
private String eTag;
public Integer getPartNumber() {
return partNumber;
}
public void setPartNumber(Integer partNumber) {
this.partNumber = partNumber;
}
public String geteTag() {
return eTag;
}
public void seteTag(String eTag) {
this.eTag = eTag;
}
@Override
public String toString() {
return "Part{" +
"partNumber=" + partNumber +
", eTag='" + eTag + '\'' +
'}';
}
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static final class FinishResponse {
private Long id;
private String filename;
private String value;
private String url;
public FinishResponse() {
}
public FinishResponse(Long id, String filename, String value, String url) {
this.id = id;
this.filename = filename;
this.value = value;
this.url = url;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "FinishResponse{" +
"id=" + id +
", filename='" + filename + '\'' +
", value='" + value + '\'' +
", url='" + url + '\'' +
'}';
}
}
}

View File

@@ -1,17 +1,18 @@
package com.lanyuanxiaoyao.service.ai.chat.controller;
package com.lanyuanxiaoyao.service.ai.web.controller.chat;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.chat.Prompts;
import com.lanyuanxiaoyao.service.ai.chat.entity.MessageVO;
import com.lanyuanxiaoyao.service.ai.chat.tools.ChartTool;
import com.lanyuanxiaoyao.service.ai.chat.tools.KnowledgeTool;
import com.lanyuanxiaoyao.service.ai.chat.tools.TableTool;
import com.lanyuanxiaoyao.service.ai.chat.tools.YarnTool;
import com.lanyuanxiaoyao.service.ai.web.configuration.Prompts;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.MessageVO;
import com.lanyuanxiaoyao.service.ai.web.tools.ChartTool;
import com.lanyuanxiaoyao.service.ai.web.tools.TableTool;
import com.lanyuanxiaoyao.service.ai.web.tools.YarnTool;
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,11 +23,11 @@ import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;
import org.springframework.ai.deepseek.DeepSeekAssistantMessage;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@@ -46,11 +47,11 @@ public class ChatController {
private final ChatClient chatClient;
public ChatController(ChatClient.Builder builder) {
public ChatController(@Qualifier("chat") ChatClient.Builder builder) {
this.chatClient = builder.build();
}
private ChatClient.ChatClientRequestSpec buildRequest(Long knowledgeId, ImmutableList<MessageVO> messages) {
private ChatClient.ChatClientRequestSpec buildRequest(ImmutableList<MessageVO> messages) {
ChatClient.ChatClientRequestSpec spec = chatClient.prompt()
.system(
StrUtil.format("""
@@ -79,9 +80,6 @@ public class ChatController {
.collect(message -> (Message) message)
.toList()
);
if (ObjectUtil.isNotNull(knowledgeId)) {
spec.tools(new KnowledgeTool(knowledgeId));
}
spec.tools(
new TableTool(),
new YarnTool(),
@@ -93,10 +91,9 @@ public class ChatController {
@PostMapping("sync")
@ResponseBody
public MessageVO chatSync(
@RequestParam(value = "knowledge_id", required = false) Long knowledgeId,
@RequestBody ImmutableList<MessageVO> messages
) {
ChatResponse response = buildRequest(knowledgeId, messages)
ChatResponse response = buildRequest(messages)
.call()
.chatResponse();
return toMessage(response);
@@ -104,25 +101,34 @@ public class ChatController {
@PostMapping("async")
public SseEmitter chatAsync(
@RequestParam(value = "knowledge_id", required = false) Long knowledgeId,
@RequestBody ImmutableList<MessageVO> messages
@RequestBody ImmutableList<MessageVO> messages,
HttpServletResponse httpResponse
) {
SseEmitter emitter = new SseEmitter();
buildRequest(knowledgeId, messages)
.stream()
.chatResponse()
.subscribe(
response -> {
try {
emitter.send(toMessage(response));
} catch (IOException e) {
emitter.completeWithError(e);
throw new RuntimeException(e);
}
},
emitter::completeWithError,
emitter::complete
);
httpResponse.setHeader("X-Accel-Buffering", "no");
SseEmitter emitter = new SseEmitter(20 * 60 * 1000L);
ExecutorProvider.EXECUTORS.submit(() -> {
buildRequest(messages)
.stream()
.chatResponse()
.subscribe(
response -> {
try {
emitter.send(
SseEmitter.event()
.data(toMessage(response))
.reconnectTime(5 * 1000L)
.build()
);
} catch (IOException e) {
emitter.completeWithError(e);
}
},
emitter::completeWithError,
emitter::complete
);
});
emitter.onTimeout(() -> emitter.completeWithError(new TimeoutException("SseEmitter Timeout")));
return emitter;
}

View File

@@ -0,0 +1,89 @@
package com.lanyuanxiaoyao.service.ai.web.controller.feedback;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisCrudResponse;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.web.configuration.FileStoreProperties;
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
import com.lanyuanxiaoyao.service.ai.web.service.feedback.FeedbackService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("feedback")
public class FeedbackController {
private final FileStoreProperties fileStoreProperties;
private final FeedbackService feedbackService;
public FeedbackController(FileStoreProperties fileStoreProperties, FeedbackService feedbackService) {
this.fileStoreProperties = fileStoreProperties;
this.feedbackService = feedbackService;
}
@PostMapping("add")
public void add(@RequestBody CreateItem item) {
feedbackService.add(item.source, ObjectUtil.defaultIfNull(item.pictures, Lists.immutable.empty()));
}
@GetMapping("list")
public AmisCrudResponse list() {
return AmisResponse.responseCrudData(feedbackService.list().collect(feedback -> new ListItem(fileStoreProperties, feedback)));
}
@GetMapping("delete")
public void delete(@RequestParam("id") Long id) {
feedbackService.remove(id);
}
@GetMapping("reanalysis")
public void reanalysis(@RequestParam("id") Long id) {
feedbackService.reanalysis(id);
}
@PostMapping("conclude")
public void conclude(@RequestBody ConcludeItem item) {
feedbackService.updateConclusion(item.getId(), item.getConclusion());
}
@Data
public static final class CreateItem {
private String source;
private ImmutableList<Long> pictures;
}
@Data
public static final class ConcludeItem {
private Long id;
private String conclusion;
}
@Data
public static final class ListItem {
private Long id;
private String source;
private ImmutableList<String> pictures;
private Feedback.Status status;
private String analysis;
private String conclusion;
public ListItem(FileStoreProperties fileStoreProperties, Feedback feedback) {
this.id = feedback.getId();
this.source = feedback.getSource();
this.pictures = feedback.getPictureIds()
.collect(id -> StrUtil.format("{}/upload/download/{}", fileStoreProperties.getDownloadPrefix(), id));
this.status = feedback.getStatus();
this.analysis = feedback.getAnalysis();
this.conclusion = feedback.getConclusion();
}
}
}

View File

@@ -1,10 +1,9 @@
package com.lanyuanxiaoyao.service.ai.knowledge.controller;
package com.lanyuanxiaoyao.service.ai.web.controller.knowledge;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.knowledge.service.GroupService;
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.GroupService;
import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -14,11 +13,10 @@ import org.springframework.web.bind.annotation.RestController;
* @author lanyuanxiaoyao
* @version 20250528
*/
@Slf4j
@RestController
@RequestMapping("group")
@RequestMapping("knowledge/group")
public class GroupController {
private static final Logger logger = LoggerFactory.getLogger(GroupController.class);
private final GroupService groupService;
public GroupController(GroupService groupService) {

View File

@@ -1,17 +1,16 @@
package com.lanyuanxiaoyao.service.ai.knowledge.controller;
package com.lanyuanxiaoyao.service.ai.web.controller.knowledge;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisMapResponse;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.SegmentVO;
import com.lanyuanxiaoyao.service.ai.knowledge.service.EmbeddingService;
import com.lanyuanxiaoyao.service.ai.knowledge.service.KnowledgeBaseService;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.SegmentVO;
import com.lanyuanxiaoyao.service.ai.web.service.EmbeddingService;
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.KnowledgeBaseService;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -23,11 +22,10 @@ import org.springframework.web.bind.annotation.RestController;
* @author lanyuanxiaoyao
* @version 20250515
*/
@Slf4j
@RestController
@RequestMapping("knowledge")
public class KnowledgeBaseController {
private static final Logger logger = LoggerFactory.getLogger(KnowledgeBaseController.class);
private final KnowledgeBaseService knowledgeBaseService;
private final EmbeddingService embeddingService;
@@ -39,9 +37,18 @@ public class KnowledgeBaseController {
@PostMapping("add")
public void add(
@RequestParam("name") String name,
@RequestParam("description") String description,
@RequestParam("strategy") String strategy
) throws ExecutionException, InterruptedException {
knowledgeBaseService.add(name, strategy);
knowledgeBaseService.add(name, description, strategy);
}
@PostMapping("update_description")
public void updateDescription(
@RequestParam("id") Long id,
@RequestParam("description") String description
) {
knowledgeBaseService.updateDescription(id, description);
}
@GetMapping("name")

View File

@@ -1,10 +1,9 @@
package com.lanyuanxiaoyao.service.ai.knowledge.controller;
package com.lanyuanxiaoyao.service.ai.web.controller.knowledge;
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.knowledge.service.SegmentService;
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.SegmentService;
import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -14,11 +13,10 @@ import org.springframework.web.bind.annotation.RestController;
* @author lanyuanxiaoyao
* @version 20250528
*/
@Slf4j
@RestController
@RequestMapping("segment")
@RequestMapping("knowledge/segment")
public class SegmentController {
private static final Logger logger = LoggerFactory.getLogger(SegmentController.class);
private final SegmentService segmentService;
public SegmentController(SegmentService segmentService) {

View File

@@ -0,0 +1,22 @@
package com.lanyuanxiaoyao.service.ai.web.entity;
import lombok.Data;
import org.eclipse.collections.api.list.ImmutableList;
@Data
public class Feedback {
private Long id;
private String source;
private ImmutableList<Long> pictureIds;
private String analysis;
private String conclusion;
private Status status;
private Long createdTime;
private Long modifiedTime;
public enum Status {
ANALYSIS_PROCESSING,
ANALYSIS_SUCCESS,
FINISHED,
}
}

View File

@@ -0,0 +1,16 @@
package com.lanyuanxiaoyao.service.ai.web.entity;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
@Data
public class Group {
private Long id;
private String name;
private String status;
private Long createdTime;
private Long modifiedTime;
}

View File

@@ -0,0 +1,18 @@
package com.lanyuanxiaoyao.service.ai.web.entity;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250522
*/
@Data
public class Knowledge {
private Long id;
private Long vectorSourceId;
private String name;
private String description;
private String strategy;
private Long createdTime;
private Long modifiedTime;
}

View File

@@ -0,0 +1,39 @@
package com.lanyuanxiaoyao.service.ai.web.entity.context;
import java.util.List;
import java.util.Map;
import lombok.Builder;
import lombok.Data;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.springframework.ai.document.Document;
/**
* @author lanyuanxiaoyao
* @version 20250523
*/
@Data
@Builder
public class EmbeddingContext {
private Long vectorSourceId;
private Long groupId;
private Config config;
private String content;
private String file;
private String fileFormat;
@Builder.Default
private List<Document> documents = Lists.mutable.empty();
@Builder.Default
private Map<String, Object> metadata = Maps.mutable.empty();
@Data
@Builder
public static final class Config {
@Builder.Default
private SplitStrategy splitStrategy = SplitStrategy.NORMAL;
public enum SplitStrategy {
NORMAL, LLM, QA
}
}
}

View File

@@ -0,0 +1,17 @@
package com.lanyuanxiaoyao.service.ai.web.entity.context;
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
import java.util.List;
import lombok.Data;
import org.eclipse.collections.api.factory.Lists;
/**
* @author lanyuanxiaoyao
* @version 20250616
*/
@Data
public class FeedbackContext {
private Feedback feedback;
private String optimizedSource;
private List<String> pictureDescriptions = Lists.mutable.empty();
}

View File

@@ -0,0 +1,17 @@
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250527
*/
@Data
public class DataFileVO {
private String id;
private String filename;
private Long size;
private String md5;
private String path;
private String type;
}

View File

@@ -0,0 +1,22 @@
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
@Data
public class KnowledgeVO {
private Long id;
private Long vectorSourceId;
private String name;
private String description;
private String strategy;
private Long size;
private Long points;
private Long segments;
private String status;
private Long createdTime;
private Long modifiedTime;
}

View File

@@ -0,0 +1,14 @@
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
@Data
public class MessageVO {
private String role;
private String content;
private String reason;
}

View File

@@ -0,0 +1,13 @@
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
import lombok.Data;
/**
* @author lanyuanxiaoyao
* @version 20250516
*/
@Data
public class SegmentVO {
private String id;
private String text;
}

View File

@@ -1,11 +1,9 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service;
package com.lanyuanxiaoyao.service.ai.web.service;
import club.kingon.sql.builder.SqlBuilder;
import cn.hutool.core.util.IdUtil;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.core.configuration.SnowflakeId;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.common.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -16,7 +14,6 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Service
public class DataFileService {
private static final Logger log = LoggerFactory.getLogger(DataFileService.class);
private static final String DATA_FILE_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_file";
private final JdbcTemplate template;
@@ -47,7 +44,7 @@ public class DataFileService {
@Transactional(rollbackFor = Exception.class)
public Long initialDataFile(String filename) {
long id = IdUtil.getSnowflakeNextId();
long id = SnowflakeId.next();
template.update(
SqlBuilder.insertInto(DATA_FILE_TABLE_NAME, "id", "filename")
.values()

View File

@@ -1,12 +1,14 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service;
package com.lanyuanxiaoyao.service.ai.web.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.EmbeddingContext;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.web.entity.context.EmbeddingContext;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.GroupService;
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.KnowledgeBaseService;
import com.yomahub.liteflow.core.FlowExecutor;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
@@ -15,8 +17,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.stereotype.Service;
@@ -26,8 +26,6 @@ import org.springframework.stereotype.Service;
*/
@Service
public class EmbeddingService {
private static final Logger logger = LoggerFactory.getLogger(EmbeddingService.class);
private final DataFileService dataFileService;
private final FlowExecutor executor;
private final KnowledgeBaseService knowledgeBaseService;

View File

@@ -0,0 +1,160 @@
package com.lanyuanxiaoyao.service.ai.web.service.feedback;
import club.kingon.sql.builder.SqlBuilder;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.core.configuration.SnowflakeId;
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
import com.lanyuanxiaoyao.service.ai.web.entity.context.FeedbackContext;
import com.lanyuanxiaoyao.service.common.Constants;
import com.yomahub.liteflow.core.FlowExecutor;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
public class FeedbackService {
public static final String FEEDBACK_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_feedback";
public static final String[] FEEDBACK_COLUMNS = new String[]{"id", "source", "conclusion", "analysis", "pictures", "status", "created_time", "modified_time"};
private static final RowMapper<Feedback> feedbackMapper = (rs, row) -> {
Feedback feedback = new Feedback();
feedback.setId(rs.getLong(1));
feedback.setSource(rs.getString(2));
feedback.setConclusion(rs.getString(3));
feedback.setAnalysis(rs.getString(4));
feedback.setPictureIds(
StrUtil.isBlank(rs.getString(5))
? Lists.immutable.empty()
: Lists.immutable.ofAll(StrUtil.split(rs.getString(5), ",")).collect(Long::parseLong)
);
feedback.setStatus(EnumUtil.fromString(Feedback.Status.class, rs.getString(6)));
feedback.setCreatedTime(rs.getTimestamp(7).getTime());
feedback.setModifiedTime(rs.getTimestamp(8).getTime());
return feedback;
};
private final JdbcTemplate template;
private final FlowExecutor executor;
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public FeedbackService(JdbcTemplate template, FlowExecutor executor) {
this.template = template;
this.executor = executor;
}
@Scheduled(initialDelay = 1, fixedDelay = 1, timeUnit = TimeUnit.MINUTES)
public void analysis() {
List<Feedback> feedbacks = template.query(
SqlBuilder.select(FEEDBACK_COLUMNS)
.from(FEEDBACK_TABLE_NAME)
.whereEq("status", Feedback.Status.ANALYSIS_PROCESSING.name())
.build(),
feedbackMapper
);
for (Feedback feedback : feedbacks) {
FeedbackContext context = new FeedbackContext();
context.setFeedback(feedback);
executor.execute2Resp("feedback_analysis", null, context);
}
}
public Feedback get(Long id) {
return template.queryForObject(
SqlBuilder.select(FEEDBACK_COLUMNS)
.from(FEEDBACK_TABLE_NAME)
.whereEq("id", id)
.build(),
feedbackMapper
);
}
@Transactional(rollbackFor = Exception.class)
public void add(String source, ImmutableList<Long> pictureIds) {
template.update(
SqlBuilder.insertInto(FEEDBACK_TABLE_NAME, "id", "source", "pictures")
.values()
.addValue("?", "?", "?")
.precompileSql(),
SnowflakeId.next(),
source,
ObjectUtil.isEmpty(pictureIds) ? null : pictureIds.makeString(",")
);
}
@Transactional(rollbackFor = Exception.class)
public void updateAnalysis(Long id, String analysis) {
Assert.notNull(id, "ID cannot be null");
template.update(
SqlBuilder.update(FEEDBACK_TABLE_NAME)
.set("analysis", "?")
.whereEq("id", "?")
.precompileSql(),
analysis,
id
);
}
@Transactional(rollbackFor = Exception.class)
public void updateConclusion(Long id, String conclusion) {
Assert.notNull(id, "ID cannot be null");
template.update(
SqlBuilder.update(FEEDBACK_TABLE_NAME)
.set("conclusion", "?")
.whereEq("id", "?")
.precompileSql(),
conclusion,
id
);
updateStatus(id, Feedback.Status.FINISHED);
}
@Transactional(rollbackFor = Exception.class)
public void updateStatus(Long id, Feedback.Status status) {
Assert.notNull(id, "ID cannot be null");
template.update(
SqlBuilder.update(FEEDBACK_TABLE_NAME)
.set("status", "?")
.whereEq("id", "?")
.precompileSql(),
status.name(),
id
);
}
public ImmutableList<Feedback> list() {
return template.query(
SqlBuilder.select(FEEDBACK_COLUMNS)
.from(FEEDBACK_TABLE_NAME)
.orderByDesc("created_time")
.build(),
feedbackMapper
)
.stream()
.collect(Collectors.toCollection(Lists.mutable::empty))
.toImmutable();
}
@Transactional(rollbackFor = Exception.class)
public void remove(Long id) {
template.update(
SqlBuilder.delete(FEEDBACK_TABLE_NAME)
.whereEq("id", id)
.build()
);
}
@Transactional(rollbackFor = Exception.class)
public void reanalysis(Long id) {
updateStatus(id, Feedback.Status.ANALYSIS_PROCESSING);
}
}

View File

@@ -1,10 +1,10 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service;
package com.lanyuanxiaoyao.service.ai.web.service.knowledge;
import club.kingon.sql.builder.SqlBuilder;
import club.kingon.sql.builder.entry.Alias;
import club.kingon.sql.builder.entry.Column;
import cn.hutool.core.util.IdUtil;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.Group;
import com.lanyuanxiaoyao.service.ai.core.configuration.SnowflakeId;
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
import com.lanyuanxiaoyao.service.common.Constants;
import io.qdrant.client.ConditionFactory;
import io.qdrant.client.QdrantClient;
@@ -13,8 +13,6 @@ import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@@ -28,10 +26,9 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class GroupService {
public static final String GROUP_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_group";
private static final Logger logger = LoggerFactory.getLogger(GroupService.class);
private static final RowMapper<Group> groupMapper = (rs, row) -> {
Group vo = new Group();
vo.setId(String.valueOf(rs.getLong(1)));
vo.setId(rs.getLong(1));
vo.setName(rs.getString(2));
vo.setStatus(rs.getString(3));
vo.setCreatedTime(rs.getTimestamp(4).getTime());
@@ -60,7 +57,7 @@ public class GroupService {
@Transactional(rollbackFor = Exception.class)
public Long add(Long knowledgeId, String name) {
long id = IdUtil.getSnowflakeNextId();
long id = SnowflakeId.next();
template.update(
SqlBuilder.insertInto(GROUP_TABLE_NAME, "id", "knowledge_id", "name", "status")
.values()

View File

@@ -1,23 +1,19 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service;
package com.lanyuanxiaoyao.service.ai.web.service.knowledge;
import club.kingon.sql.builder.SqlBuilder;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.KnowledgeVO;
import com.lanyuanxiaoyao.service.ai.core.configuration.SnowflakeId;
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.KnowledgeVO;
import com.lanyuanxiaoyao.service.common.Constants;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.grpc.Collections;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.noear.solon.ai.reranking.RerankingModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SearchRequest;
@@ -35,34 +31,33 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class KnowledgeBaseService {
public static final String KNOWLEDGE_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_knowledge";
private static final Logger logger = LoggerFactory.getLogger(KnowledgeBaseService.class);
public static final String[] KNOWLEDGE_COLUMNS = new String[]{"id", "vector_source_id", "name", "description", "strategy", "created_time", "modified_time"};
private static final RowMapper<Knowledge> knowledgeMapper = (rs, row) -> {
Knowledge knowledge = new Knowledge();
knowledge.setId(rs.getLong(1));
knowledge.setVectorSourceId(rs.getLong(2));
knowledge.setName(rs.getString(3));
knowledge.setStrategy(rs.getString(4));
knowledge.setCreatedTime(rs.getTimestamp(5).getTime());
knowledge.setModifiedTime(rs.getTimestamp(6).getTime());
knowledge.setDescription(rs.getString(4));
knowledge.setStrategy(rs.getString(5));
knowledge.setCreatedTime(rs.getTimestamp(6).getTime());
knowledge.setModifiedTime(rs.getTimestamp(7).getTime());
return knowledge;
};
private final JdbcTemplate template;
private final EmbeddingModel model;
private final QdrantClient client;
private final GroupService groupService;
private final RerankingModel rerankingModel;
public KnowledgeBaseService(JdbcTemplate template, EmbeddingModel model, VectorStore vectorStore, GroupService groupService, RerankingModel rerankingModel) {
public KnowledgeBaseService(JdbcTemplate template, EmbeddingModel model, VectorStore vectorStore, GroupService groupService) {
this.template = template;
this.model = model;
this.client = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
this.groupService = groupService;
this.rerankingModel = rerankingModel;
}
public Knowledge get(Long id) {
return template.queryForObject(
SqlBuilder.select("id", "vector_source_id", "name", "strategy", "created_time", "modified_time")
SqlBuilder.select(KNOWLEDGE_COLUMNS)
.from(KNOWLEDGE_TABLE_NAME)
.whereEq("id", "?")
.precompileSql(),
@@ -72,7 +67,7 @@ public class KnowledgeBaseService {
}
@Transactional(rollbackFor = Exception.class)
public void add(String name, String strategy) throws ExecutionException, InterruptedException {
public void add(String name, String description, String strategy) throws ExecutionException, InterruptedException {
Integer count = template.queryForObject(
SqlBuilder.select("count(*)")
.from(KNOWLEDGE_TABLE_NAME)
@@ -85,16 +80,17 @@ public class KnowledgeBaseService {
throw new RuntimeException("名称已存在");
}
long id = IdUtil.getSnowflakeNextId();
long vectorSourceId = IdUtil.getSnowflakeNextId();
long id = SnowflakeId.next();
long vectorSourceId = SnowflakeId.next();
template.update(
SqlBuilder.insertInto(KNOWLEDGE_TABLE_NAME, "id", "vector_source_id", "name", "strategy")
SqlBuilder.insertInto(KNOWLEDGE_TABLE_NAME, "id", "vector_source_id", "name", "description", "strategy")
.values()
.addValue("?", "?", "?", "?")
.addValue("?", "?", "?", "?", "?")
.precompileSql(),
id,
vectorSourceId,
name,
description,
strategy
);
client.createCollectionAsync(
@@ -106,6 +102,18 @@ public class KnowledgeBaseService {
).get();
}
@Transactional(rollbackFor = Exception.class)
public void updateDescription(Long id, String description) {
template.update(
SqlBuilder.update(KNOWLEDGE_TABLE_NAME)
.set("description", "?")
.whereEq("id", "?")
.precompileSql(),
description,
id
);
}
public String getName(Long id) {
return template.queryForObject(
SqlBuilder.select("name")
@@ -119,7 +127,7 @@ public class KnowledgeBaseService {
public ImmutableList<KnowledgeVO> list() {
return template.query(
SqlBuilder.select("id", "vector_source_id", "name", "strategy", "created_time", "modified_time")
SqlBuilder.select(KNOWLEDGE_COLUMNS)
.from(KNOWLEDGE_TABLE_NAME)
.orderByDesc("created_time")
.build(),
@@ -130,9 +138,10 @@ public class KnowledgeBaseService {
try {
Collections.CollectionInfo info = client.getCollectionInfoAsync(String.valueOf(knowledge.getVectorSourceId())).get();
KnowledgeVO vo = new KnowledgeVO();
vo.setId(String.valueOf(knowledge.getId()));
vo.setVectorSourceId(String.valueOf(knowledge.getVectorSourceId()));
vo.setId(knowledge.getId());
vo.setVectorSourceId(knowledge.getVectorSourceId());
vo.setName(knowledge.getName());
vo.setDescription(knowledge.getDescription());
vo.setPoints(info.getPointsCount());
vo.setSegments(info.getSegmentsCount());
vo.setStatus(info.getStatus().name());
@@ -171,7 +180,7 @@ public class KnowledgeBaseService {
String text,
Integer limit,
Double threshold
) throws ExecutionException, InterruptedException, IOException {
) throws ExecutionException, InterruptedException {
Knowledge knowledge = get(id);
Boolean exists = client.collectionExistsAsync(String.valueOf(knowledge.getVectorSourceId())).get();
if (!exists) {
@@ -188,13 +197,6 @@ public class KnowledgeBaseService {
.similarityThreshold(threshold)
.build()
);
// 如果只是一个知识库的话似乎没有什么rerank的必要...
/* List<org.noear.solon.ai.rag.Document> rerankDocuments = rerankingModel.rerank(
text,
documents.stream()
.map(doc -> new org.noear.solon.ai.rag.Document(doc.getId(), doc.getText(), doc.getMetadata(), doc.getScore()))
.toList()
); */
return Lists.immutable.ofAll(documents)
.collect(Document::getText);
}

View File

@@ -1,7 +1,7 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service;
package com.lanyuanxiaoyao.service.ai.web.service.knowledge;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.vo.SegmentVO;
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.SegmentVO;
import io.qdrant.client.ConditionFactory;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.grpc.Points;
@@ -10,8 +10,6 @@ import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Service;
@@ -21,8 +19,6 @@ import org.springframework.stereotype.Service;
*/
@Service
public class SegmentService {
private static final Logger logger = LoggerFactory.getLogger(SegmentService.class);
private final KnowledgeBaseService knowledgeBaseService;
private final QdrantClient client;

View File

@@ -1,10 +1,10 @@
package com.lanyuanxiaoyao.service.ai.knowledge.service.node;
package com.lanyuanxiaoyao.service.ai.web.service.node;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.knowledge.entity.EmbeddingContext;
import com.lanyuanxiaoyao.service.ai.web.entity.context.EmbeddingContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
@@ -18,8 +18,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
@@ -31,22 +30,22 @@ import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.qdrant.QdrantVectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.PathResource;
/**
* @author lanyuanxiaoyao
* @version 20250523
*/
@Slf4j
@LiteflowComponent
public class EmbeddingNodes {
private static final Logger logger = LoggerFactory.getLogger(EmbeddingNodes.class);
private final ChatClient chatClient;
private final ChatClient.Builder chatClientBuilder;
private final QdrantClient qdrantClient;
private final EmbeddingModel embeddingModel;
public EmbeddingNodes(ChatClient.Builder builder, VectorStore vectorStore, EmbeddingModel embeddingModel) {
this.chatClient = builder.build();
public EmbeddingNodes(@Qualifier("chat") ChatClient.Builder builder, VectorStore vectorStore, EmbeddingModel embeddingModel) {
this.chatClientBuilder = builder;
this.qdrantClient = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
this.embeddingModel = embeddingModel;
}
@@ -151,9 +150,11 @@ public class EmbeddingNodes {
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "qa_split", nodeName = "使用Q/A格式分段", nodeType = NodeTypeEnum.COMMON)
public void qaSplit(NodeComponent node) {
EmbeddingContext context = node.getContextBean(EmbeddingContext.class);
// language=TEXT
context.getDocuments().addAll(llmSplit(
"""
对用户输入的文本生成多组高质量的问答对请遵循以下指南
1. 问题部分
为同一个主题创建尽可能多的不同表述的问题确保问题的多样性
每个问题应考虑用户可能的多种问法例如
@@ -168,7 +169,7 @@ public class EmbeddingNodes {
答案应直接基于给定文本确保准确性和一致性
包含相关的细节如日期名称职位等具体信息必要时提供背景信息以增强理解
3. 格式
使用"问:"标记问题集合的开始所有问题应在一个段落内问题之间用空格分隔
使用"问:"标记问题的开始问题文本应在一个段落内完成
使用"答:"标记答案的开始答案应清晰分段便于阅读
问答对之间用---分隔以提高可读性
4. 内容要求
@@ -176,6 +177,8 @@ public class EmbeddingNodes {
避免添加文本中未提及的信息确保信息的真实性
一个问题搭配一个答案避免一组问答对中同时涉及多个问题
如果文本信息不足以回答某个方面可以在答案中说明 "根据给定信息无法确定"并尽量提供相关的上下文
除了问答对本身避免输出任何与问答对无关的提示性引导性解释性的文本
格式样例
苹果通常是什么颜色的
红色
@@ -189,13 +192,13 @@ public class EmbeddingNodes {
}
private List<Document> llmSplit(String prompt, String content, Map<String, Object> metadata) {
String response = chatClient.prompt()
ChatClient client = chatClientBuilder.build();
String response = client.prompt()
.system(prompt)
.user(content)
.call()
.content();
Assert.notBlank(response, "LLM response is empty");
logger.info("LLM response: \n{}", response);
// noinspection DataFlowIssue
return Arrays.stream(StrUtil.trim(response).split("---"))
.map(text -> text.replaceAll("(?!^.+) +$", ""))

View File

@@ -0,0 +1,203 @@
package com.lanyuanxiaoyao.service.ai.web.service.node;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
import com.lanyuanxiaoyao.service.ai.web.entity.context.FeedbackContext;
import com.lanyuanxiaoyao.service.ai.web.entity.vo.DataFileVO;
import com.lanyuanxiaoyao.service.ai.web.service.DataFileService;
import com.lanyuanxiaoyao.service.ai.web.service.feedback.FeedbackService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.FileSystemResource;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@Slf4j
@LiteflowComponent
public class FeedbackNodes {
private final ChatClient.Builder chatClientBuilder;
private final ChatClient.Builder visualChatClientBuilder;
private final DataFileService dataFileService;
private final FeedbackService feedbackService;
public FeedbackNodes(
@Qualifier("chat") ChatClient.Builder chatClientBuilder,
@Qualifier("visual") ChatClient.Builder visualClientBuilder, DataFileService dataFileService, FeedbackService feedbackService
) {
this.chatClientBuilder = chatClientBuilder;
this.visualChatClientBuilder = visualClientBuilder;
this.dataFileService = dataFileService;
this.feedbackService = feedbackService;
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "feedback_check_if_picture_needed", nodeName = "判断有图片进行识别", nodeType = NodeTypeEnum.BOOLEAN)
public boolean checkIfPictureReadNeeded(NodeComponent node) {
FeedbackContext context = node.getContextBean(FeedbackContext.class);
Feedback feedback = context.getFeedback();
return ObjectUtil.isNotEmpty(feedback.getPictureIds());
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "image_read", nodeName = "读取图片", nodeType = NodeTypeEnum.COMMON)
public void imageRead(NodeComponent node) {
FeedbackContext context = node.getContextBean(FeedbackContext.class);
Feedback feedback = context.getFeedback();
ChatClient client = visualChatClientBuilder
// language=TEXT
.defaultSystem("""
你是一个专业的OCR解析助手。请严格按以下步骤处理用户上传的图片
1. 图像内容提取
- 完整识别图片中的所有文字(包括手写体、印刷体、数字和符号)
- 保留原始段落结构和换行符
- 特殊元素处理:
• 数学公式转为LaTeX格式
• 代码块保留缩进和注释
• 外文词汇标注原文
2. 表格解析优化
- 识别所有表格区域
- 转换为Markdown表格格式对齐表头与单元格
- 补充缺失的表格线
- 用▲标注合并单元格▲跨3列▲
3. 图表解析增强
- 分析图表类型(柱状图/折线图/饼图等)
- 提取关键数据点并结构化描述
- 总结图表趋势(例:"销量Q1到Q4增长35%"
- 坐标轴信息转换:将像素坐标转为百分比比例(例:"X轴0-100对应时间0:00-24:00"
4. 输出规范
- 按[文本][表格][图表]分区块输出
- 表格/图表区域标注原始位置(例:"[左上区域表格]"
- 模糊内容用[?]标注并给出备选(例:"年收[?]入(可能为'入'或'人'"
- 保持原始数据精度(不四舍五入)
立即开始处理用户图片,无需确认步骤。
""")
.build();
for (Long pictureId : feedback.getPictureIds()) {
DataFileVO file = dataFileService.downloadFile(pictureId);
log.info("Parse picture: {} {}", file.getFilename(), file.getPath());
MimeType type = switch (StrUtil.blankToDefault(file.getType(), "").toLowerCase()) {
case "jpg", "jpeg" -> MimeTypeUtils.IMAGE_JPEG;
default -> MimeTypeUtils.IMAGE_PNG;
};
String content = client.prompt()
.user(spec -> spec
.text("输出图片内容")
.media(type, new FileSystemResource(file.getPath())))
.call()
.content();
log.info("Picture: {}", content);
context.getPictureDescriptions().add(content);
}
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "optimize_source", nodeName = "报障信息优化", nodeType = NodeTypeEnum.COMMON)
public void optimizeSource(NodeComponent node) {
FeedbackContext context = node.getContextBean(FeedbackContext.class);
Feedback feedback = context.getFeedback();
String optimizedSource = chatClientBuilder.build()
.prompt()
// language=TEXT
.system("""
你是一名专业的IT系统运维工程师对于用户输入的关于系统的报障信息你会严格遵循以下步骤进行处理
1.输入
[故障描述]
(这里是用户遇到的系统故障的详细描述)
[相关截图]
(这里是用户遇到的系统故障相关的截图的文字描述,如果没有相关截图,这里会写“无”;如果有多张图片,图片和图片之间会使用“---”分隔)
2.处理逻辑
解析输入
读取并解析用户提供的故障描述和相关截图描述。
识别关键元素:包括故障类型(如硬件故障、软件错误)、受影响系统组件(如服务器、网络设备)、错误消息、发生时间、重现步骤、影响范围等。
如果截图描述存在,提取关键细节(如错误弹窗文本、系统状态截图),并将其作为辅助证据;如果无截图,则忽略此部分。
分析与重写故障描述
专业化改写使用标准IT术语替换非专业用语例如“电脑死机”改为“系统无响应”“连不上网”改为“网络连接中断”并确保描述符合行业规范。
排除歧义澄清模糊描述如添加具体时间戳、系统版本、IP地址或错误代码移除主观语言如“我觉得”或“可能”并添加必要上下文如操作系统环境、相关服务运行状态
结构化组织:将故障描述重写为逻辑段落,格式包括:
问题概述:简明总结故障本质(例如,“数据库服务异常导致应用无法访问”)。
详细症状描述具体现象包括错误消息、发生频率和影响范围如“影响用户登录功能错误代码500”
重现步骤列出可复现故障的操作序列如“1. 访问URL X2. 触发操作 Y”
相关环境添加系统细节如“运行在Linux Ubuntu 20.04, Java 11环境”
整合截图信息如果截图描述存在将其嵌入重写中作为证据例如“根据截图错误弹窗显示Connection timeout
质量校验
检查重写后的内容是否完整、一致且无歧义:确保所有用户输入细节都被涵盖,添加缺失信息(如建议的故障分类),并验证专业术语的准确性。
如果输入信息不足(如缺少时间戳或系统版本),在输出中添加注释提示用户补充。
3.输出
输出一个专业、结构化的故障报告,格式清晰,可直接用于运维团队诊断。
重写的故障描述,以结构化段落呈现,涵盖问题概述、详细症状、重现步骤和相关环境。
输出将使用中性、客观语言,避免任何个人意见或建议,以确保报告专注于事实描述。
""")
.user(StrUtil.format(
"""
[故障描述]
{}
[相关截图]
{}
""",
feedback.getSource(),
ObjectUtil.isEmpty(context.getPictureDescriptions()) ? "" : StrUtil.join(",", context.getPictureDescriptions())
))
.call()
.content();
if (StrUtil.isBlank(optimizedSource)) {
log.warn("Optimized source is blank");
}
context.setOptimizedSource(StrUtil.trim(optimizedSource));
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "feedback_suggest", nodeName = "大模型建议", nodeType = NodeTypeEnum.COMMON)
public void suggestFeedback(NodeComponent node) {
FeedbackContext context = node.getContextBean(FeedbackContext.class);
Feedback feedback = context.getFeedback();
ChatClient client = chatClientBuilder.build();
String analysis = client.prompt()
// language=TEXT
.system("""
你是一名专业的IT系统运维工程师。针对用户输入的报障信息严格遵循以下步骤
1. 提取关键要素: 精准识别报障信息中的关键要素(如系统/设备名称、故障现象、错误信息、时间地点、影响范围、用户操作步骤等)。
2. 分析诊断: 基于提取的要素,运用运维专业知识,分析潜在原因,并提出优先级高、可操作性强的排障建议或初步诊断方向。
3. 输出专业意见:
内容要求: 意见必须包含明确的行动步骤如检查XX日志、验证XX配置、重启XX服务、联系XX团队、潜在风险提示及预期效果。
表达要求: 使用清晰、简洁、专业的技术术语,避免使用推测性语言或不确定词汇(如“可能”、“大概”、“也许”)。
格式要求: 直接输出意见内容,避免添加引导语(如“我的建议是”、“根据报障信息”等)。
""")
.user(context.getOptimizedSource())
.call()
.content();
feedback.setAnalysis(StrUtil.trim(analysis));
Assert.notBlank(analysis, "Analysis cannot be blank");
String conclusion = client.prompt()
// language=TEXT
.system("""
你是一名专业的文字编辑。严格按以下要求处理用户输入:
核心逻辑: 用一段话精准总结输入内容的核心信息,确保涵盖所有关键点。禁止虚构、扩展或添加原文不存在的信息。
输出规范: 仅输出一段总结文本。禁止分点、分段、使用Markdown格式如着重、- 或 1. 等列表符号)或添加任何无关引导语(如“总结如下”、“该总结指出”、“本文总结”等)。直接给出总结文本。""")
.user(analysis)
.call()
.content();
feedback.setConclusion(StrUtil.trim(conclusion));
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "feedback_save", nodeName = "保存分析内容", nodeType = NodeTypeEnum.COMMON)
public void saveFeedback(NodeComponent node) {
FeedbackContext context = node.getContextBean(FeedbackContext.class);
Feedback feedback = context.getFeedback();
feedbackService.updateAnalysis(feedback.getId(), feedback.getAnalysis());
feedbackService.updateConclusion(feedback.getId(), feedback.getConclusion());
feedbackService.updateStatus(feedback.getId(), Feedback.Status.ANALYSIS_SUCCESS);
}
}

View File

@@ -1,8 +1,7 @@
package com.lanyuanxiaoyao.service.ai.chat.tools;
package com.lanyuanxiaoyao.service.ai.web.tools;
import com.lanyuanxiaoyao.service.ai.chat.AiChatApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
@@ -13,9 +12,8 @@ import org.springframework.ai.tool.annotation.ToolParam;
* @author lanyuanxiaoyao
* @version 20250611
*/
@Slf4j
public class ChartTool {
private static final Logger logger = LoggerFactory.getLogger(ChartTool.class);
@Tool(description = """
根据需求生成mermaid图表代码
""")
@@ -45,8 +43,8 @@ public class ChartTool {
其他箭头类型实线/虚线注释文本等
""") String request
) {
logger.info("Enter method: mermaid[request]. request:{}", request);
ChatClient.Builder builder = AiChatApplication.getBean(ChatClient.Builder.class);
log.info("Enter method: mermaid[request]. request:{}", request);
ChatClient.Builder builder = WebApplication.getBean("chat", ChatClient.Builder.class);
ChatClient client = builder.build();
return client.prompt()
// language=TEXT

View File

@@ -1,8 +1,8 @@
package com.lanyuanxiaoyao.service.ai.chat.tools;
package com.lanyuanxiaoyao.service.ai.web.tools;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.chat.AiChatApplication;
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
import com.lanyuanxiaoyao.service.forest.service.KnowledgeService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
@@ -27,7 +27,7 @@ public class KnowledgeTool {
""")
String query
) {
KnowledgeService knowledgeService = AiChatApplication.getBean(KnowledgeService.class);
KnowledgeService knowledgeService = WebApplication.getBean(KnowledgeService.class);
var documents = knowledgeService.query(knowledgeId, query, 10, 0.5);
if (ObjectUtil.isNotEmpty(documents)) {
return StrUtil.format("""

View File

@@ -1,13 +1,12 @@
package com.lanyuanxiaoyao.service.ai.chat.tools;
package com.lanyuanxiaoyao.service.ai.web.tools;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.chat.AiChatApplication;
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
import com.lanyuanxiaoyao.service.forest.service.InfoService;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
@@ -15,8 +14,8 @@ import org.springframework.ai.tool.annotation.ToolParam;
* @author lanyuanxiaoyao
* @version 20250605
*/
@Slf4j
public class TableTool {
private static final Logger logger = LoggerFactory.getLogger(TableTool.class);
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
@Tool(description = """
@@ -27,12 +26,12 @@ public class TableTool {
完整的MySQL查询语句禁止使用除select外的任何语句
""") String sql
) {
logger.info("Enter method: executeJdbc[sql]. sql:{}", sql);
InfoService infoService = AiChatApplication.getBean(InfoService.class);
log.info("Enter method: executeJdbc[sql]. sql:{}", sql);
InfoService infoService = WebApplication.getBean(InfoService.class);
String result = infoService.jdbc(sql)
.collect(map -> map.valuesView().makeString(","))
.makeString("\n");
logger.info("SQL result: \n{}", result);
log.info("SQL result: \n{}", result);
return result;
}
@@ -48,8 +47,8 @@ public class TableTool {
一次调用只能传一个类型不支持多个类型同时查询
""") String type
) {
logger.info("Enter method: tableCount[type]. type:{}", type);
var infoService = AiChatApplication.getBean(InfoService.class);
log.info("Enter method: tableCount[type]. type:{}", type);
var infoService = WebApplication.getBean(InfoService.class);
return switch (type) {
case "logic" -> StrUtil.format("""
逻辑表共{}其中重点表{}
@@ -83,8 +82,8 @@ public class TableTool {
""")
String type
) {
logger.info("Enter method: version[date, type]. date:{},type:{}", date, type);
InfoService infoService = AiChatApplication.getBean(InfoService.class);
log.info("Enter method: version[date, type]. date:{},type:{}", date, type);
InfoService infoService = WebApplication.getBean(InfoService.class);
String version = date;
if (StrUtil.isBlank(version)) {
version = LocalDateTime.now().minusDays(1).format(FORMATTER);

View File

@@ -1,14 +1,13 @@
package com.lanyuanxiaoyao.service.ai.chat.tools;
package com.lanyuanxiaoyao.service.ai.web.tools;
import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.ai.chat.AiChatApplication;
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
import com.lanyuanxiaoyao.service.forest.service.YarnService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.list.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
@@ -16,9 +15,8 @@ import org.springframework.ai.tool.annotation.ToolParam;
* @author lanyuanxiaoyao
* @version 20250606
*/
@Slf4j
public class YarnTool {
private static final Logger logger = LoggerFactory.getLogger(YarnTool.class);
@Tool(description = """
查询yarn集群整体资源情况返回值为资源占用率%
""")
@@ -28,8 +26,8 @@ public class YarnTool {
一次调用只能查询一个集群不支持多个集群同时查询
""") String cluster
) {
logger.info("Enter method: yarnStatus[cluster]. cluster:{}", cluster);
YarnService yarnService = AiChatApplication.getBean(YarnService.class);
log.info("Enter method: yarnStatus[cluster]. cluster:{}", cluster);
YarnService yarnService = WebApplication.getBean(YarnService.class);
YarnRootQueue status = yarnService.cluster(cluster);
return (status.getUsedCapacity() * 100.0) / status.getCapacity();
}
@@ -46,8 +44,8 @@ public class YarnTool {
yarn队列名称
""") String queue
) {
logger.info("Enter method: yarnQueueStatus[cluster, queue]. cluster:{},queue:{}", cluster, queue);
YarnService yarnService = AiChatApplication.getBean(YarnService.class);
log.info("Enter method: yarnQueueStatus[cluster, queue]. cluster:{},queue:{}", cluster, queue);
YarnService yarnService = WebApplication.getBean(YarnService.class);
YarnQueue status = yarnService.queueDetail(cluster, queue);
return (status.getAbsoluteCapacity() * 100.0) / status.getAbsoluteMaxCapacity();
}
@@ -67,8 +65,8 @@ public class YarnTool {
一次调用只能传一个类型不支持多个类型同时查询
""") String type
) {
logger.info("Enter method: yarnTaskStatus[cluster, type]. cluster:{},type:{}", cluster, type);
YarnService yarnService = AiChatApplication.getBean(YarnService.class);
log.info("Enter method: yarnTaskStatus[cluster, type]. cluster:{},type:{}", cluster, type);
YarnService yarnService = WebApplication.getBean(YarnService.class);
ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> StrUtil.isNotBlank(type) && StrUtil.contains(app.getName(), type));
return StrUtil.format(
"""

View File

@@ -0,0 +1,42 @@
server:
compression:
enabled: true
spring:
application:
name: service-ai-web
profiles:
include: random-port,common,discovery,metrics,forest
mvc:
async:
request-timeout: 3600000
autoconfigure:
exclude: |
org.springframework.ai.model.openai.autoconfigure.OpenAiChatAutoConfiguration,
org.springframework.ai.model.openai.autoconfigure.OpenAiAudioSpeechAutoConfiguration,
org.springframework.ai.model.openai.autoconfigure.OpenAiAudioTranscriptionAutoConfiguration,
org.springframework.ai.model.openai.autoconfigure.OpenAiImageAutoConfiguration,
org.springframework.ai.model.openai.autoconfigure.OpenAiEmbeddingAutoConfiguration,
org.springframework.ai.model.openai.autoconfigure.OpenAiModerationAutoConfiguration,
org.springframework.ai.model.deepseek.autoconfigure.DeepSeekChatAutoConfiguration
ai:
vectorstore:
qdrant:
host: 132.121.206.65
port: 29463
api-key: ENC(0/0UkIKeAvyV17yNqSU3v04wmm8CdWKe4BYSSJa2FuBtK12TcZRJPdwk+ZpYnpISv+KmVTUrrmFBzAYrDR3ysA==)
llm:
base-url: http://132.121.206.65:10086
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
chat:
base-url: ${spring.llm.base-url}/v1
model: 'Qwen3/qwen3-1.7b'
visual:
model: 'Qwen2.5/qwen2.5-vl-7b-q4km'
embedding:
model: 'Qwen3/qwen3-embedding-4b'
reranker:
model: 'BGE/beg-reranker-v2'
liteflow:
rule-source: liteflow.xml
print-banner: false
check-node-exists: false

View File

@@ -23,4 +23,15 @@
<chain id="embedding_submit_directly">
SER(import_vector_source)
</chain>
<chain id="feedback_analysis">
SER(
IF(
feedback_check_if_picture_needed,
image_read
),
optimize_source,
feedback_suggest,
feedback_save
)
</chain>
</flow>

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.ai.knowledge;
package com.lanyuanxiaoyao.service.ai.web;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;

View File

@@ -0,0 +1,70 @@
package com.lanyuanxiaoyao.service.ai.web;
import com.lanyuanxiaoyao.service.ai.core.configuration.WebClientConfiguration;
import com.lanyuanxiaoyao.service.ai.web.configuration.LlmConfiguration;
import com.lanyuanxiaoyao.service.ai.web.configuration.LlmProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.core.io.FileSystemResource;
import org.springframework.util.MimeTypeUtils;
/**
* @author lanyuanxiaoyao
* @version 20250526
*/
@Slf4j
public class TestLlm {
public static void main(String[] args) {
LlmConfiguration configuration = new LlmConfiguration();
LlmProperties properties = new LlmProperties();
LlmProperties.ChatProperties chatProperties = new LlmProperties.ChatProperties();
chatProperties.setBaseUrl("http://132.121.206.65:10086");
chatProperties.setApiKey("*XMySqV%>hR&v>>g*NwCs3tpQ5FVMFEF2VHVTj<MYQd$&@$sY7CgqNyea4giJi4");
chatProperties.setModel("Qwen2.5/qwen2.5-vl-7b");
properties.setVisual(chatProperties);
ChatClient client = configuration.visualClientBuilder(
properties,
WebClientConfiguration.generateWebClientBuilder(),
WebClientConfiguration.generateRestClientBuilder()
).build();
String content = client.prompt()
// language=TEXT
.system("""
你是一个专业的OCR解析助手。请严格按以下步骤处理用户上传的图片
1. 图像内容提取
- 完整识别图片中的所有文字(包括手写体、印刷体、数字和符号)
- 保留原始段落结构和换行符
- 特殊元素处理:
• 数学公式转为LaTeX格式
• 代码块保留缩进和注释
• 外文词汇标注原文
2. 表格解析优化
- 识别所有表格区域
- 转换为Markdown表格格式对齐表头与单元格
- 补充缺失的表格线
- 用▲标注合并单元格▲跨3列▲
3. 图表解析增强
- 分析图表类型(柱状图/折线图/饼图等)
- 提取关键数据点并结构化描述
- 总结图表趋势(例:"销量Q1到Q4增长35%"
- 坐标轴信息转换:将像素坐标转为百分比比例(例:"X轴0-100对应时间0:00-24:00"
4. 输出规范
- 按[文本][表格][图表]分区块输出
- 表格/图表区域标注原始位置(例:"[左上区域表格]"
- 模糊内容用[?]标注并给出备选(例:"年收[?]入(可能为'入'或'人'"
- 保持原始数据精度(不四舍五入)
立即开始处理用户图片,无需确认步骤。
""")
.user(spec -> spec
// language=TEXT
.text("输出图片内容")
.media(MimeTypeUtils.IMAGE_PNG, new FileSystemResource("/Users/lanyuanxiaoyao/Downloads/图片_002_07.png")))
.call()
.content();
log.info(content);
}
}

View File

@@ -1,4 +1,4 @@
package com.lanyuanxiaoyao.service.ai.knowledge;
package com.lanyuanxiaoyao.service.ai.web;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

View File

@@ -161,23 +161,16 @@ deploy:
- "service"
source-jar: service-monitor-1.0.0-SNAPSHOT.jar
replicas: 1
service-ai-chat:
service-ai-web:
order: 6
groups:
- "ai"
source-jar: service-ai-chat-1.0.0-SNAPSHOT.jar
jdk: "jdk17"
replicas: 1
service-ai-knowledge:
order: 6
groups:
- "ai"
source-jar: service-ai-knowledge-1.0.0-SNAPSHOT.jar
source-jar: service-ai-web-1.0.0-SNAPSHOT.jar
jdk: "jdk17"
replicas: 1
arguments:
"[knowledge.download-prefix]": 'http://132.126.207.130:35690/hudi_services/ai_knowledge'
"[knowledge.upload-path]": ${deploy.runtime.data-path}/knowledge
"[file-store.download-prefix]": 'http://132.126.207.130:35690/hudi_services/service_ai_web'
"[file-store.upload-path]": ${deploy.runtime.data-path}/knowledge
"[spring.datasource.url]": ${deploy.runtime.database.config.url}
"[spring.datasource.username]": ${deploy.runtime.database.config.username}
"[spring.datasource.password]": ${deploy.runtime.database.config.password}

View File

@@ -51,8 +51,7 @@ public class GatewayApplication {
.route("web", createRoute("/hudi_services/service_web", "lb://service-web"))
.route("services", createRoute("/hudi_services/service_cloud_query", "lb://service-cloud-query"))
.route("exporter", createRoute("/hudi_services/service_exporter", "lb://service-exporter"))
.route("ai-chat", createRoute("/hudi_services/ai_chat", "lb://service-ai-chat"))
.route("ai-knowledge", createRoute("/hudi_services/ai_knowledge", "lb://service-ai-knowledge"))
.route("ai-web", createRoute("/hudi_services/service_ai_web", "lb://service-ai-web"))
.build();
}
}

View File

@@ -1,3 +1,4 @@
<!--suppress CssUnknownTarget, HtmlUnknownTarget -->
<!doctype html>
<html lang="zh">
<head>
@@ -13,6 +14,15 @@
margin: 0;
padding: 0;
}
@font-face {
font-family: 'LXGWWenKai';
src: url('fonts/LXGWNeoXiHei.ttf') format('truetype');
}
*:not(.fa,.fas) {
font-family: LXGWWenKai, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji', serif !important;
}
</style>
</head>
<body>

View File

@@ -10,17 +10,18 @@
},
"dependencies": {
"@ant-design/icons": "^6.0.0",
"@ant-design/pro-components": "^2.8.7",
"@ant-design/pro-components": "^2.8.9",
"@ant-design/x": "^1.4.0",
"@echofly/fetch-event-source": "^3.0.2",
"@fortawesome/fontawesome-free": "^6.7.2",
"@lightenna/react-mermaid-diagram": "^1.0.20",
"@tinyflow-ai/react": "^0.1.10",
"@tinyflow-ai/react": "^0.2.1",
"@xyflow/react": "^12.7.0",
"ahooks": "^3.8.5",
"amis": "^6.12.0",
"antd": "^5.25.3",
"axios": "^1.9.0",
"chart.js": "^4.4.9",
"antd": "^5.26.1",
"axios": "^1.10.0",
"chart.js": "^4.5.0",
"echarts-for-react": "^3.0.2",
"licia": "^1.48.0",
"markdown-it": "^14.1.0",
@@ -29,18 +30,18 @@
"react-chartjs-2": "^5.3.0",
"react-dom": "^18.3.1",
"react-markdown": "^10.1.0",
"react-router": "^7.6.1",
"styled-components": "^6.1.18"
"react-router": "^7.6.2",
"styled-components": "^6.1.18",
"zustand": "^5.0.5"
},
"devDependencies": {
"@types/markdown-it": "^14.1.2",
"@types/react": "^18.3.23",
"@types/react-dom": "^18.3.7",
"@vitejs/plugin-react-swc": "^3.10.0",
"@vitejs/plugin-react-swc": "^3.10.2",
"globals": "^16.2.0",
"sass": "^1.89.0",
"sass": "^1.89.2",
"typescript": "~5.8.3",
"typescript-eslint": "^8.33.0",
"vite": "^6.3.5",
"vite-plugin-javascript-obfuscator": "^3.1.0"
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// 改写一些amis中控制不到的全局CSS
button.btn-deleted:hover {
color: #dc2626 !important;
}

View File

@@ -1,6 +1,6 @@
import {createRoot} from 'react-dom/client'
import {createHashRouter, RouterProvider} from 'react-router'
import './index.scss'
import './components/Registry.ts'
import {routes} from './route.tsx'

View File

@@ -2,6 +2,7 @@ import {ProLayout} from '@ant-design/pro-components'
import React from 'react'
import {Outlet, useLocation, useNavigate} from 'react-router'
import {menus} from '../route.tsx'
import {ConfigProvider} from 'antd'
const App: React.FC = () => {
const navigate = useNavigate()
@@ -34,7 +35,18 @@ const App: React.FC = () => {
style={{minHeight: '100vh'}}
contentStyle={{backgroundColor: 'white', padding: '10px 10px 10px 20px'}}
>
<Outlet/>
<ConfigProvider
theme={{
components: {
Card: {
bodyPadding: 0,
bodyPaddingSM: 0,
}
}
}}
>
<Outlet/>
</ConfigProvider>
</ProLayout>
)
}

View File

@@ -1,128 +1,486 @@
import MarkdownRender from '../util/Markdown.tsx'
import {useState} from 'react'
import {DeleteFilled, EditFilled, PlusCircleFilled, SaveFilled} from '@ant-design/icons'
import {
addEdge,
applyEdgeChanges,
applyNodeChanges,
Background,
BackgroundVariant,
Controls,
type Edge,
Handle,
MiniMap,
type Node,
type NodeProps,
type OnConnect,
type OnEdgesChange,
type OnNodesChange,
Position,
ReactFlow,
} from '@xyflow/react'
import {useMount} from 'ahooks'
import type {Schema} from 'amis'
import {Button, Card, Drawer, Dropdown, message, Space} from 'antd'
import {arrToMap, filter, find, findIdx, isEqual, isNil, randomId} from 'licia'
import {type JSX, useState} from 'react'
import styled from 'styled-components'
import '@xyflow/react/dist/style.css'
import {create} from 'zustand/react'
import {amisRender, commonInfo} from '../util/amis.tsx'
// language=Markdown
const markdownText = `### Hello
const FlowableDiv = styled.div`
height: 93vh;
world
tony
jenny
.toolbar {
z-index: 999;
position: absolute;
}
\`\`\`javascript
console.log('hello')
\`\`\`
.node-card {
cursor: grab;
\`\`\`mermaid
graph TD
a-->b;
\`\`\`
\`\`\`mermaid
graph TD
c-->d;
\`\`\`
\`\`\`chartjs
{
type: 'bar',
data: {
labels: ['苹果', '香蕉', '橙子', '葡萄', '菠萝'],
datasets: [{
label: '水果销量',
data: [43, 32, 56, 29, 38],
}]
},
options: {
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: '水果店周销量数据'
}
.card-container {
cursor: default;
}
}
}
\`\`\`
`
\`\`\`chartjs
{
type: 'bar',
data: {
labels: ['苹果', '香蕉', '橙子', '葡萄', '菠萝'],
datasets: [{
label: '水果销量',
data: [43, 32, 56, 29, 38],
}]
},
options: {
plugins: {
legend: {
position: 'top',
type AmisNodeType = 'normal' | 'start' | 'end'
const AmisNode = (
props: NodeProps,
type: AmisNodeType,
name: String,
description?: String,
columnSchema?: Schema[],
) => {
const {id, data} = props
const {getDataById, removeNode, editNode} = data
return (
<div className="p-1 w-64">
<Card
className="node-card"
title={name}
size="small"
hoverable
>
<Dropdown
className="card-container"
trigger={['contextMenu']}
menu={{
items: [
{
key: 'edit',
label: '编辑',
icon: <EditFilled className="text-gray-600 hover:text-blue-500"/>,
},
{
key: 'remove',
label: '删除',
icon: <DeleteFilled className="text-red-500 hover:text-red-500"/>,
},
],
onClick: menu => {
switch (menu.key) {
case 'edit':
// @ts-ignore
editNode(id, name, description, columnSchema)
break
case 'remove':
// @ts-ignore
removeNode(id)
break
}
},
title: {
display: true,
text: '水果店周销量数据'
}
}
}
}}
>
<div className="card-description p-2 text-secondary text-sm">
{description}
</div>
</Dropdown>
</Card>
{isEqual(type, 'start') || isEqual(type, 'normal')
? <Handle type="source" position={Position.Right}/> : undefined}
{isEqual(type, 'end') || isEqual(type, 'normal')
? <Handle type="target" position={Position.Left}/> : undefined}
</div>
)
}
\`\`\`
\`\`\`echart
{
grid: { top: 8, right: 8, bottom: 24, left: 36 },
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
smooth: true,
const StartAmisNode = (props: NodeProps) => AmisNode(
props,
'start',
'开始节点',
'定义输入变量',
[
{
type: 'input-kvs',
name: 'fields',
addButtonText: '新增入参',
draggable: false,
keyItem: {
label: '参数名称',
},
],
tooltip: {
trigger: 'axis',
valueItems: [
{
type: 'input-text',
name: 'description',
label: '参数描述',
},
{
type: 'select',
name: 'type',
label: '参数类型',
required: true,
selectFirst: true,
options: [
{
label: '文本',
value: 'text',
},
{
label: '数字',
value: 'number',
},
{
label: '文件',
value: 'files',
},
],
},
],
},
}
\`\`\`
],
)
const EndAmisNode = (props: NodeProps) => AmisNode(
props,
'end',
'结束节点',
'定义输出变量',
[
{
type: 'input-kvs',
name: 'fields',
addButtonText: '新增输出',
draggable: false,
keyItem: {
label: '参数名称',
},
valueItems: [
{
type: 'select',
name: 'type',
label: '参数',
required: true,
selectFirst: true,
options: [],
},
],
},
],
)
const LlmAmisNode = (props: NodeProps) => AmisNode(
props,
'normal',
'大模型节点',
'使用大模型对话',
[
{
type: 'select',
name: 'model',
label: '大模型',
required: true,
selectFirst: true,
options: [
{
label: 'Qwen3',
value: 'qwen3',
},
{
label: 'Deepseek',
value: 'deepseek',
},
],
},
{
type: 'textarea',
name: 'systemPrompt',
label: '系统提示词',
required: true,
},
],
)
\`\`\`echart
{
grid: { top: 8, right: 8, bottom: 24, left: 36 },
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
smooth: true,
},
],
tooltip: {
trigger: 'axis',
},
}
\`\`\``
const initialNodes: Node[] = [
{
id: 'BMFP3Eov94',
type: 'start-amis-node',
position: {x: 10, y: 100},
data: {},
},
{
id: 'PYK8LjduQ1',
type: 'end-amis-node',
position: {x: 500, y: 100},
data: {},
},
]
const initialEdges: Edge[] = []
const useStore = create<{
data: Record<string, any>,
getData: () => Record<string, any>,
setData: (data: Record<string, any>) => void,
getDataById: (id: string) => any,
setDataById: (id: string, data: any) => void,
}>((set, get) => ({
data: {},
getData: () => get().data,
setData: (data) => set(data),
getDataById: id => get().data[id],
setDataById: (id, data) => {
let updateData = get().data
updateData[id] = data
set({
data: updateData,
})
},
}))
const useFlowStore = create<{
nodes: Node[],
onNodesChange: OnNodesChange,
addNode: (node: Node) => void,
removeNode: (id: string) => void,
setNodes: (nodes: Node[]) => void,
edges: Edge[],
onEdgesChange: OnEdgesChange,
setEdges: (edges: Edge[]) => void,
onConnect: OnConnect,
}>((set, get) => ({
nodes: [],
onNodesChange: changes => {
set({
nodes: applyNodeChanges(changes, get().nodes),
})
},
addNode: node => set({nodes: get().nodes.concat(node)}),
removeNode: id => {
set({
nodes: filter(get().nodes, node => !isEqual(node.id, id)),
})
},
setNodes: nodes => set({nodes}),
edges: [],
onEdgesChange: changes => {
set({
edges: applyEdgeChanges(changes, get().edges),
})
},
setEdges: edges => set({edges}),
onConnect: connection => {
set({
edges: addEdge(connection, get().edges),
})
},
}))
function Test() {
const [value, setValue] = useState<string>(markdownText)
const [messageApi, contextHolder] = message.useMessage()
const [nodeDef] = useState<{
key: string,
name: string,
component: (props: NodeProps) => JSX.Element
}[]>([
{
key: 'start-amis-node',
name: '开始',
component: StartAmisNode,
},
{
key: 'end-amis-node',
name: '结束',
component: EndAmisNode,
},
{
key: 'llm-amis-node',
name: '大模型',
component: LlmAmisNode,
},
])
const [open, setOpen] = useState(false)
const {getData, getDataById, setDataById} = useStore()
const {
nodes,
addNode,
removeNode,
setNodes,
onNodesChange,
edges,
setEdges,
onEdgesChange,
onConnect,
} = useFlowStore()
const [currentNodeForm, setCurrentNodeForm] = useState<JSX.Element>()
const editNode = (id: string, name: string, description: string, columnSchema?: Schema[]) => {
if (!isNil(columnSchema)) {
setCurrentNodeForm(
amisRender(
{
type: 'wrapper',
size: 'none',
body: [
{
type: 'tpl',
className: 'text-secondary',
tpl: description,
},
{
debug: commonInfo.debug,
title: name,
type: 'form',
wrapWithPanel: false,
onEvent: {
submitSucc: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
setDataById(id, context.props.data)
setOpen(false)
},
},
],
},
},
body: [
...(columnSchema ?? []),
{
type: 'wrapper',
size: 'none',
className: 'space-x-1 float-right',
body: [
{
type: 'action',
label: '取消',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
setOpen(false)
},
},
],
},
},
},
{
type: 'submit',
label: '保存',
level: 'primary',
},
],
},
],
},
]
},
getDataById(id),
),
)
setOpen(true)
}
}
useMount(() => {
for (let node of initialNodes) {
node.data = {
getDataById,
setDataById,
removeNode,
editNode,
}
}
setNodes(initialNodes)
setEdges(initialEdges)
})
return (
<>
<button onClick={() => setValue('hahaha\n' + markdownText)}>Button</button>
<MarkdownRender content={value}/>
</>
<FlowableDiv>
{contextHolder}
<Space className="toolbar">
<Button type="primary" onClick={() => console.log(JSON.stringify(getData()))}>
<SaveFilled/>
</Button>
<Dropdown
menu={{
items: nodeDef.map(def => ({key: def.key, label: def.name})),
onClick: ({key}) => {
if (isEqual(key, 'start-amis-node') && findIdx(nodes, (node: Node) => isEqual(key, node.type)) > -1) {
messageApi.error('只能存在1个开始节点')
return
}
if (isEqual(key, 'end-amis-node') && findIdx(nodes, (node: Node) => isEqual(key, node.type)) > -1) {
messageApi.error('只能存在1个结束节点')
return
}
addNode({
id: randomId(10),
type: key,
position: {x: 100, y: 100},
data: {
getDataById,
setDataById,
removeNode,
editNode,
},
})
},
}}
>
<Button type="dashed">
<PlusCircleFilled/>
</Button>
</Dropdown>
</Space>
<Drawer
title="节点编辑"
open={open}
closeIcon={false}
maskClosable={false}
destroyOnHidden
>
{currentNodeForm}
</Drawer>
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
// @ts-ignore
nodeTypes={arrToMap(
nodeDef.map(def => def.key),
key => find(nodeDef, def => isEqual(key, def.key))!.component)
}
>
<Controls/>
<MiniMap/>
<Background variant={BackgroundVariant.Cross} gap={20} size={3}/>
</ReactFlow>
</FlowableDiv>
)
}

View File

@@ -1,9 +1,9 @@
import {ClearOutlined, FileOutlined, UserOutlined} from '@ant-design/icons'
import {ClearOutlined, UserOutlined} from '@ant-design/icons'
import {Bubble, Sender, useXAgent, useXChat, Welcome} from '@ant-design/x'
import {fetchEventSource} from '@echofly/fetch-event-source'
import {useMount} from 'ahooks'
import {Button, Collapse, Flex, Popover, Radio, Typography} from 'antd'
import {isEqual, isStrBlank, trim} from 'licia'
import {useUnmount} from 'ahooks'
import {Button, Collapse, Flex, Typography} from 'antd'
import {isStrBlank, trim} from 'licia'
import {useRef, useState} from 'react'
import styled from 'styled-components'
import {commonInfo} from '../../util/amis.tsx'
@@ -40,24 +40,15 @@ type ChatMessage = { role: string, content?: string, reason?: string }
function Conversation() {
const abortController = useRef<AbortController | null>(null)
const [input, setInput] = useState<string>('')
const [knowledge, setKnowledge] = useState<string>('0')
const [knowledgeList, setKnowledgeList] = useState<{ id: string, name: string }[]>([])
useMount(async () => {
let response = await fetch(`${commonInfo.baseAiKnowledgeUrl}/knowledge/list`, {
headers: commonInfo.authorizationHeaders,
})
let items = (await response.json()).data.items
setKnowledgeList(items.map((item: { id: string, name: string }) => ({id: item.id, name: item.name})))
useUnmount(() => {
console.log('Page Unmount')
abortController.current?.abort()
})
const [agent] = useXAgent<ChatMessage>({
request: async (info, callbacks) => {
let requestUrl = `${commonInfo.baseAiChatUrl}/chat/async`
if (!isEqual('0', info.knowledge)) {
requestUrl = `${requestUrl}?knowledge_id=${info.knowledge}`
}
await fetchEventSource(requestUrl, {
await fetchEventSource(`${commonInfo.baseAiUrl}/chat/async`, {
method: 'POST',
headers: commonInfo.authorizationHeaders,
body: JSON.stringify(info.messages),
@@ -70,6 +61,7 @@ function Conversation() {
})
},
onclose: () => callbacks.onSuccess([]),
onerror: error => callbacks.onError(error),
})
},
})
@@ -180,7 +172,6 @@ function Conversation() {
content: message,
},
stream: true,
knowledge: knowledge,
})
setInput('')
}}
@@ -190,32 +181,6 @@ function Conversation() {
return (
<Flex justify="space-between" align="center">
<Flex gap="small" align="center">
<Popover
title="选择知识库"
trigger="hover"
content={<Radio.Group
style={{
display: 'flex',
flexDirection: 'column',
gap: 10,
}}
disabled={agent.isRequesting()}
value={knowledge}
onChange={event => setKnowledge(event.target.value)}
options={[
{value: '0', label: '无'},
...knowledgeList.map(k => ({label: k.name, value: k.id})),
]}
/>}
>
<Button
icon={<FileOutlined/>}
type="text"
size="small"
>
</Button>
</Popover>
<Button
icon={<ClearOutlined/>}
type="text"

View File

@@ -0,0 +1,245 @@
import React from 'react'
import styled from 'styled-components'
import {amisRender, commonInfo, crudCommonOptions, mappingField, mappingItem} from '../../../util/amis.tsx'
const FeedbackDiv = styled.div`
.feedback-list-images {
margin-top: 10px;
.antd-Img-container {
width: 32px;
height: 32px;
}
}
`
const statusMapping = [
mappingItem('分析中', 'ANALYSIS_PROCESSING', 'label-warning'),
mappingItem('分析完成', 'ANALYSIS_SUCCESS', 'label-primary'),
mappingItem('处理完成', 'FINISHED', 'label-success'),
]
const Feedback: React.FC = () => {
return (
<FeedbackDiv className="feedback">
{amisRender(
{
type: 'page',
title: '报障清单',
body: [
{
type: 'crud',
api: `${commonInfo.baseAiUrl}/feedback/list`,
...crudCommonOptions(),
headerToolbar: [
'reload',
{
type: 'action',
label: '',
icon: 'fa fa-plus',
tooltip: '新增',
tooltipPlacement: 'top',
actionType: 'dialog',
dialog: {
title: '新增报账单',
size: 'md',
body: {
debug: commonInfo.debug,
type: 'form',
api: `${commonInfo.baseAiUrl}/feedback/add`,
body: [
{
type: 'editor',
required: true,
label: '故障描述',
name: 'source',
language: 'plaintext',
options: {
lineNumbers: 'off',
wordWrap: 'bounded',
},
},
{
type: 'input-image',
name: 'pictures',
label: '相关截图',
autoUpload: false,
multiple: true,
joinValues: false,
extractValue: true,
// 5MB 5242880
// 100MB 104857600
// 500MB 524288000
// 1GB 1073741824
maxSize: 5242880,
receiver: `${commonInfo.baseAiUrl}/upload`,
},
],
},
},
},
],
columns: [
{
name: 'id',
label: '编号',
width: 150,
},
{
label: '故障描述',
type: 'flex',
direction: 'column',
items: [
{
type: 'tpl',
className: 'white-space-pre',
tpl: '${source}',
},
{
className: 'feedback-list-images',
type: 'images',
enlargeAble: true,
enlargeWithGallary: true,
source: '${pictures}',
showToolbar: true,
},
],
},
{
label: '状态',
width: 80,
align: 'center',
...mappingField('status', statusMapping),
},
{
type: 'operation',
label: '操作',
width: 200,
buttons: [
{
visibleOn: '${status === \'ANALYSIS_SUCCESS\'}',
type: 'action',
label: '重新分析',
level: 'link',
size: 'sm',
actionType: 'ajax',
api: {
method: 'get',
url: `${commonInfo.baseAiUrl}/feedback/reanalysis`,
data: {
id: '${id}',
},
},
confirmText: '确认执行重新分析?',
confirmTitle: '重新分析',
},
{
disabledOn: '${status === \'ANALYSIS_PROCESSING\'}',
type: 'action',
label: '详情',
level: 'link',
size: 'sm',
actionType: 'dialog',
dialog: {
title: '报障详情',
size: 'lg',
closeOnOutside: true,
actions: [
{
visibleOn: '${status !== \'FINISHED\'}',
type: 'action',
actionType: 'close',
label: '取消',
},
{
visibleOn: '${status !== \'FINISHED\'}',
type: 'submit',
label: '确认',
level: 'primary',
},
],
body: {
debug: commonInfo.debug,
type: 'form',
mode: 'normal',
api: {
method: 'post',
url: `${commonInfo.baseAiUrl}/feedback/conclude`,
data: {
id: '${id}',
conclusion: '${conclusion|default:undefined}',
},
},
body: [
{
type: 'textarea',
name: 'source',
label: '报障描述',
static: true,
},
{
type: 'control',
name: 'pictures',
label: '相关截图',
body: {
type: 'images',
enlargeAble: true,
enlargeWithGallary: true,
showToolbar: true,
},
},
{
type: 'control',
name: 'analysis',
label: 'AI辅助分析',
body: {
type: 'markdown',
},
},
{
visibleOn: '${status !== \'FINISHED\'}',
type: 'textarea',
name: 'conclusion',
label: '结论',
},
{
visibleOn: '${status === \'FINISHED\'}',
type: 'textarea',
name: 'conclusion',
label: '结论',
static: true,
},
],
},
},
},
{
disabledOn: '${status === \'ANALYSIS_PROCESSING\'}',
type: 'action',
label: '删除',
className: 'text-danger btn-deleted',
level: 'link',
size: 'sm',
actionType: 'ajax',
api: {
method: 'get',
url: `${commonInfo.baseAiUrl}/feedback/delete`,
data: {
id: '${id}',
},
},
confirmTitle: '删除',
confirmText: '删除后将无法恢复,确认删除?',
},
],
},
],
},
],
},
)}
</FeedbackDiv>
)
}
export default Feedback

View File

@@ -24,7 +24,7 @@ const DataDetail: React.FC = () => {
{
type: 'service',
className: 'inline',
api: `${commonInfo.baseAiKnowledgeUrl}/knowledge/name?id=${knowledge_id}`,
api: `${commonInfo.baseAiUrl}/knowledge/name?id=${knowledge_id}`,
body: {
type: 'tpl',
tpl: '${name}',
@@ -38,7 +38,7 @@ const DataDetail: React.FC = () => {
body: [
{
type: 'crud',
api: `${commonInfo.baseAiKnowledgeUrl}/group/list?knowledge_id=${knowledge_id}`,
api: `${commonInfo.baseAiUrl}/knowledge/group/list?knowledge_id=${knowledge_id}`,
...crudCommonOptions(),
headerToolbar: [
'reload',
@@ -142,11 +142,11 @@ const DataDetail: React.FC = () => {
{
type: 'action',
label: '删除',
className: 'text-danger hover:text-red-600',
className: 'text-danger btn-deleted',
level: 'link',
size: 'sm',
actionType: 'ajax',
api: `get:${commonInfo.baseAiKnowledgeUrl}/group/delete?id=\${id}`,
api: `get:${commonInfo.baseAiUrl}/knowledge/group/delete?id=\${id}`,
confirmText: '确认删除',
confirmTitle: '删除',
},

View File

@@ -23,7 +23,7 @@ const DataImport: React.FC = () => {
{
type: 'service',
className: 'inline',
api: `${commonInfo.baseAiKnowledgeUrl}/knowledge/name?id=${knowledge_id}`,
api: `${commonInfo.baseAiUrl}/knowledge/name?id=${knowledge_id}`,
body: {
type: 'tpl',
tpl: '${name}',
@@ -109,7 +109,7 @@ const DataImport: React.FC = () => {
// 500MB 524288000
// 1GB 1073741824
maxSize: 104857600,
receiver: `${commonInfo.baseAiKnowledgeUrl}/upload`
receiver: `${commonInfo.baseAiUrl}/upload`
// useChunk: true,
// startChunkApi: `post:${commonInfo.baseAiKnowledgeUrl}/upload/start`,
// chunkApi: `post:${commonInfo.baseAiKnowledgeUrl}/upload/slice`,
@@ -130,7 +130,7 @@ const DataImport: React.FC = () => {
level: 'secondary',
api: {
method: 'post',
url: `${commonInfo.baseAiKnowledgeUrl}/knowledge/preview_text`,
url: `${commonInfo.baseAiUrl}/knowledge/preview_text`,
dataType: 'form',
data: {
mode: '${mode|default:undefined}',
@@ -148,7 +148,7 @@ const DataImport: React.FC = () => {
actionType: 'ajax',
api: {
method: 'post',
url: `${commonInfo.baseAiKnowledgeUrl}/knowledge/submit_text`,
url: `${commonInfo.baseAiUrl}/knowledge/submit_text`,
dataType: 'form',
data: {
id: knowledge_id,

View File

@@ -18,7 +18,7 @@ const DataDetail: React.FC = () => {
{
type: 'service',
className: 'inline',
api: `${commonInfo.baseAiKnowledgeUrl}/knowledge/name?id=${knowledge_id}`,
api: `${commonInfo.baseAiUrl}/knowledge/name?id=${knowledge_id}`,
body: {
type: 'tpl',
tpl: '${name}',
@@ -32,7 +32,7 @@ const DataDetail: React.FC = () => {
body: [
{
type: 'crud',
api: `${commonInfo.baseAiKnowledgeUrl}/segment/list?knowledge_id=${knowledge_id}&group_id=${group_id}`,
api: `${commonInfo.baseAiUrl}/knowledge/segment/list?knowledge_id=${knowledge_id}&group_id=${group_id}`,
...crudCommonOptions(),
headerToolbar: [
'reload',
@@ -87,7 +87,7 @@ const DataDetail: React.FC = () => {
{
type: 'action',
label: '删除',
className: 'text-danger hover:text-red-600',
className: 'text-danger btn-deleted',
level: 'link',
size: 'sm',
actionType: 'ajax',

View File

@@ -25,7 +25,7 @@ const Knowledge: React.FC = () => {
body: [
{
type: 'crud',
api: `${commonInfo.baseAiKnowledgeUrl}/knowledge/list`,
api: `${commonInfo.baseAiUrl}/knowledge/list`,
...crudCommonOptions(),
headerToolbar: [
'reload',
@@ -42,7 +42,7 @@ const Knowledge: React.FC = () => {
body: {
type: 'form',
api: {
url: `${commonInfo.baseAiKnowledgeUrl}/knowledge/add`,
url: `${commonInfo.baseAiUrl}/knowledge/add`,
dataType: 'form',
},
body: [
@@ -50,12 +50,20 @@ const Knowledge: React.FC = () => {
type: 'input-text',
name: 'name',
label: '名称',
required: true,
},
{
type: 'textarea',
name: 'description',
label: '描述',
required: true,
},
{
type: 'select',
name: 'strategy',
label: '类型',
value: 'Cosine',
required: true,
options: [
{
label: '文本',
@@ -77,6 +85,11 @@ const Knowledge: React.FC = () => {
{
name: 'name',
label: '名称',
width: 200,
},
{
name: 'description',
label: '描述',
},
{
label: '类型',
@@ -99,8 +112,41 @@ const Knowledge: React.FC = () => {
{
type: 'operation',
label: '操作',
width: 150,
width: 200,
buttons: [
{
type: 'action',
label: '更新',
level: 'link',
size: 'sm',
actionType: 'dialog',
dialog: {
title: '更新描述',
body: {
debug: commonInfo.debug,
type: 'form',
api: {
method: 'post',
url: `${commonInfo.baseAiUrl}/knowledge/update_description`,
dataType: 'form',
},
mode: 'normal',
body: [
{
type: 'hidden',
name: "id",
// value: '${id}',
},
{
type: 'textarea',
name: 'description',
label: '描述',
required: true,
}
]
}
}
},
{
type: 'action',
label: '详情',
@@ -142,13 +188,13 @@ const Knowledge: React.FC = () => {
{
type: 'action',
label: '删除',
className: 'text-danger hover:text-red-600',
className: 'text-danger btn-deleted',
level: 'link',
size: 'sm',
actionType: 'ajax',
api: {
method: 'get',
url: `${commonInfo.baseAiKnowledgeUrl}/knowledge/delete`,
url: `${commonInfo.baseAiUrl}/knowledge/delete`,
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
},

View File

@@ -169,7 +169,7 @@ const tableDetailDialog = (variable: string, targetList: any) => {
const overviewYarnJob = (cluster: string, search: string, queue: string | undefined, yarnQueue: string) => {
return {
className: 'text-base leading-none',
className: 'text-sm leading-none',
type: 'table-view',
border: false,
padding: '0 10px 0 15px',

View File

@@ -91,7 +91,7 @@ function Table() {
columns: [
{
label: 'Flink job id',
width: 195,
width: 200,
fixed: 'left',
type: 'wrapper',
size: 'none',

View File

@@ -99,7 +99,7 @@ function Version() {
columns: [
{
label: 'Flink job id',
width: 195,
width: 200,
fixed: 'left',
type: 'wrapper',
size: 'none',

View File

@@ -1,16 +1,16 @@
import React from 'react'
import {useLocation, useParams} from 'react-router'
import {
amisRender,
commonInfo,
crudCommonOptions,
paginationCommonOptions,
yarnCrudColumns,
yarnQueueCrud,
amisRender,
commonInfo,
crudCommonOptions,
paginationCommonOptions,
yarnCrudColumns,
yarnQueueCrud,
} from '../../util/amis.tsx'
const Yarn: React.FC = () => {
const {clusters, queue, search} = useParams()
const {clusters, queues, search} = useParams()
const location = useLocation()
return (
<div key={location.key} className="hudi-yarn">
@@ -27,7 +27,7 @@ const Yarn: React.FC = () => {
type: 'tpl',
tpl: '<span class="font-bold text-xl">集群资源</span>',
},
yarnQueueCrud(clusters, queue),
yarnQueueCrud(clusters, queues),
{
type: 'tpl',
tpl: '<span class="font-bold text-xl">集群任务</span>',

View File

@@ -12,9 +12,10 @@ import {
TableOutlined,
ToolOutlined,
} from '@ant-design/icons'
import {values} from 'licia'
import {Navigate, type RouteObject} from 'react-router'
import Conversation from './pages/ai/Conversation.tsx'
import Inspection from './pages/ai/Inspection.tsx'
import Feedback from './pages/ai/feedback/Feedback.tsx'
import DataDetail from './pages/ai/knowledge/DataDetail.tsx'
import DataImport from './pages/ai/knowledge/DataImport.tsx'
import DataSegment from './pages/ai/knowledge/DataSegment.tsx'
@@ -29,8 +30,8 @@ import Tool from './pages/overview/Tool.tsx'
import Version from './pages/overview/Version.tsx'
import Yarn from './pages/overview/Yarn.tsx'
import YarnCluster from './pages/overview/YarnCluster.tsx'
import {commonInfo} from './util/amis.tsx'
import Test from './pages/Test.tsx'
import {commonInfo} from './util/amis.tsx'
export const routes: RouteObject[] = [
{
@@ -58,7 +59,7 @@ export const routes: RouteObject[] = [
Component: Version,
},
{
path: 'yarn/:clusters/:queue/:search?',
path: 'yarn/:clusters/:queues/:search?',
Component: Yarn,
},
{
@@ -84,14 +85,14 @@ export const routes: RouteObject[] = [
index: true,
element: <Navigate to="/ai/conversation" replace/>,
},
{
path: 'inspection',
Component: Inspection,
},
{
path: 'conversation',
Component: Conversation,
},
{
path: 'feedback',
Component: Feedback,
},
{
path: 'knowledge',
Component: Knowledge,
@@ -146,12 +147,12 @@ export const menus = {
icon: <SunOutlined/>,
},
{
path: `/yarn/${commonInfo.clusters.sync_names()}/root/Sync`,
path: `/yarn/${commonInfo.clusters.sync_names()}/default/Sync`,
name: '同步集群',
icon: <SyncOutlined/>,
},
{
path: `/yarn/${commonInfo.clusters.compaction_names()}/default/Compaction`,
path: `/yarn/${commonInfo.clusters.compaction_names()}/${values(commonInfo.clusters.compaction).join(",")}/Compaction`,
name: '压缩集群',
icon: <SyncOutlined/>,
},
@@ -201,8 +202,8 @@ export const menus = {
icon: <QuestionOutlined/>,
},
{
path: '/ai/inspection',
name: '智能巡检',
path: '/ai/feedback',
name: '智慧报障',
icon: <CheckSquareOutlined/>,
},
{

View File

@@ -10,9 +10,8 @@ import {isEqual} from 'licia'
export const commonInfo = {
debug: isEqual(import.meta.env.MODE, 'development'),
baseUrl: 'http://132.126.207.130:35690/hudi_services/service_web',
baseAiChatUrl: 'http://132.126.207.130:35690/hudi_services/ai_chat',
baseAiKnowledgeUrl: 'http://132.126.207.130:35690/hudi_services/ai_knowledge',
// baseUrl: '/hudi_services/service_web',
baseAiUrl: 'http://132.126.207.130:35690/hudi_services/service_ai_web',
// baseAiUrl: 'http://localhost:8080',
authorizationHeaders: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
'Content-Type': 'application/json',
@@ -282,6 +281,7 @@ export function crudCommonOptions() {
resizable: false,
syncLocation: false,
silentPolling: true,
columnsTogglable: false,
}
}
@@ -904,7 +904,7 @@ export function simpleYarnDialog(cluster: string, title: string, filterField: st
type: 'crud',
api: {
method: 'get',
url: `\${base}/yarn/job_list`,
url: `${commonInfo.baseUrl}/yarn/job_list`,
data: {
clusters: `${cluster}`,
page: '${page|default:undefined}',

View File

@@ -1,5 +1,7 @@
server:
port: 0
compression:
enabled: true
spring:
application:
name: service-web