Compare commits
129 Commits
138ee140e1
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2a8c39145 | ||
|
|
82ad3e7854 | ||
| 1e3e14c590 | |||
| 267eecbf45 | |||
| a5282762ed | |||
|
|
77a09472aa | ||
|
|
4cfa110f2f | ||
|
|
ad9dade6a1 | ||
|
|
3a61da054e | ||
| fbc6144d82 | |||
| 72a9d58f4c | |||
|
|
a3c2250285 | ||
| 91e6f49342 | |||
|
|
35c5150a1f | ||
|
|
a7b245a670 | ||
|
|
df8270676a | ||
|
|
b0e4f5853e | ||
| 0efb041c71 | |||
| fa06207af8 | |||
| c7e0b56850 | |||
|
|
04bc9a2c16 | ||
|
|
c77395fec4 | ||
| 21f02660e9 | |||
| f6e9c9bc70 | |||
|
|
e798332828 | ||
|
|
b0d41e0d88 | ||
|
|
02b2d44ccc | ||
|
|
47de3cc376 | ||
|
|
5b9920449d | ||
|
|
60f6b79167 | ||
|
|
528e66c497 | ||
|
|
707f538213 | ||
|
|
eae0d8dacd | ||
|
|
bf37c163fb | ||
|
|
ac2b6b1611 | ||
|
|
863638deaa | ||
|
|
fad190567b | ||
|
|
333da7ef88 | ||
|
|
d0ca36e9d7 | ||
|
|
f70b3b2a32 | ||
|
|
f707a0d2b5 | ||
|
|
5e763637da | ||
|
|
898e20d5d7 | ||
| 605cfb7182 | |||
|
|
3afdff0a05 | ||
|
|
f523fc7638 | ||
| 03d0d9d85b | |||
| 187c565da4 | |||
| f3dfff5075 | |||
| 69420094ec | |||
|
|
051b3dbad2 | ||
|
|
64ef5514b4 | ||
|
|
4f1dc84405 | ||
| d979b3941d | |||
| abdbb5ed03 | |||
|
|
8ebaf5de8e | ||
|
|
5f7eeb3596 | ||
|
|
064443f740 | ||
|
|
6809750cfa | ||
|
|
49cb62b287 | ||
|
|
5cbda28594 | ||
|
|
11c5481287 | ||
|
|
67e0cada00 | ||
|
|
cdf51cc85f | ||
|
|
9277d1690c | ||
|
|
24ac681cb3 | ||
|
|
c46da52942 | ||
|
|
7209b52e3d | ||
|
|
959d6fb5c7 | ||
|
|
c5c62ab713 | ||
| e59e89a5ad | |||
| b7626180c1 | |||
|
|
68e54d5110 | ||
|
|
5f133fbfc3 | ||
|
|
d28fbbbba8 | ||
|
|
67f41c08a0 | ||
| 111ca49815 | |||
| 779fd0eb18 | |||
| 8884495a89 | |||
| d08a6babbe | |||
| 9a3375bd03 | |||
|
|
2c808a5bc9 | ||
|
|
6e667c45e1 | ||
|
|
635c6537ed | ||
|
|
d6b70b1750 | ||
|
|
c92a374591 | ||
|
|
a2aba82b6e | ||
| 873c1a1d20 | |||
|
|
f6bd7e52e1 | ||
|
|
6f7f7cea67 | ||
|
|
33df256863 | ||
|
|
3a51d1e33f | ||
|
|
d3c7457889 | ||
| 2d2eaafcd4 | |||
|
|
566dfef208 | ||
| 1cba0f4422 | |||
| ab56385c8a | |||
| b58c34443f | |||
| 53638a8a6d | |||
| dc55605c99 | |||
| 7345774258 | |||
| fcf5f8ad18 | |||
|
|
b53ee57dc3 | ||
|
|
b916acb1c3 | ||
|
|
c9616eb63a | ||
|
|
5b3c27ea48 | ||
| e48d7e8649 | |||
|
|
306c20aa7f | ||
|
|
24d5d10ecb | ||
|
|
4a9a9ec238 | ||
|
|
08aa1d8382 | ||
|
|
1b3045dfd4 | ||
|
|
0f5ae1c4d4 | ||
|
|
48e42ee99a | ||
|
|
0914b458d3 | ||
|
|
368c30676e | ||
|
|
60477f99f5 | ||
|
|
565c530dd5 | ||
|
|
5130885033 | ||
|
|
8e6463845b | ||
|
|
e89bffe289 | ||
|
|
1dd00d329c | ||
| e470a87372 | |||
|
|
45da452f18 | ||
|
|
e6a1bc5383 | ||
|
|
c5916703cd | ||
|
|
807ddbe5cb | ||
|
|
13de694e37 | ||
|
|
1962dd586c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -110,3 +110,4 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
**/temp/
|
||||
.build
|
||||
@@ -1,5 +1,5 @@
|
||||
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
|
||||
import {isEqual, trim, fileSize} from "licia";
|
||||
import {fileSize, isEqual, trim} from "licia";
|
||||
import md5file from 'md5-file'
|
||||
|
||||
syncProcessCwd(true)
|
||||
@@ -41,20 +41,70 @@ const millisecondToString = (timestamp) => {
|
||||
return parts.join('')
|
||||
}
|
||||
|
||||
const dotBuildPath = () => `.build`
|
||||
const modifiedDataPath = () => `${dotBuildPath()}/modified_time.json`
|
||||
|
||||
const readModifiedTimeData = async () => {
|
||||
if (!fs.existsSync(dotBuildPath())) {
|
||||
fs.mkdirSync(dotBuildPath(), {recursive: true})
|
||||
}
|
||||
if (!(await fs.exists(modifiedDataPath()))) {
|
||||
fs.writeFileSync(modifiedDataPath(), '{}')
|
||||
}
|
||||
return JSON.parse(await fs.readFile(modifiedDataPath(), 'utf-8'))
|
||||
}
|
||||
|
||||
const updateModifiedTimeData = (data) => {
|
||||
fs.writeFileSync(modifiedDataPath(), JSON.stringify(data, null, 2))
|
||||
}
|
||||
|
||||
const isModified = async (target) => {
|
||||
if (!target || !(await fs.exists(target))) {
|
||||
throw new Error("Target 不存在")
|
||||
}
|
||||
let stat = fs.statSync(target)
|
||||
let currentModifiedTime = stat.mtimeMs
|
||||
|
||||
let lastModifiedTime = (await readModifiedTimeData())[target]
|
||||
return !(lastModifiedTime && isEqual(currentModifiedTime, lastModifiedTime));
|
||||
|
||||
}
|
||||
|
||||
const updateModifiedTime = async (target) => {
|
||||
if (!target || !(await fs.exists(target))) {
|
||||
throw new Error("Target 不存在")
|
||||
}
|
||||
let stat = fs.statSync(target)
|
||||
let currentModifiedTime = stat.mtimeMs
|
||||
let modifiedTimeData = await readModifiedTimeData()
|
||||
modifiedTimeData[target] = currentModifiedTime
|
||||
updateModifiedTimeData(modifiedTimeData)
|
||||
}
|
||||
|
||||
export const run_deploy = async (project) => {
|
||||
if (!(await isModified(project))) {
|
||||
console.log(`✅ Skip deploy ${project}`)
|
||||
return
|
||||
}
|
||||
let output = await spinner(
|
||||
`Deploying project ${project}`,
|
||||
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
|
||||
)
|
||||
console.log(`✅ Finished deploy ${project} (${millisecondToString(output['duration'])})`)
|
||||
await updateModifiedTime(project)
|
||||
}
|
||||
|
||||
export const run_deploy_root = async () => {
|
||||
if (!(await isModified('pom.xml'))) {
|
||||
console.log(`✅ Skip deploy root`)
|
||||
return
|
||||
}
|
||||
let output = await spinner(
|
||||
`Deploying root`,
|
||||
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
|
||||
)
|
||||
console.log(`✅ Finished deploy root (${millisecondToString(output['duration'])})`)
|
||||
await updateModifiedTime('pom.xml')
|
||||
}
|
||||
|
||||
export const run_deploy_batch = async (projects) => {
|
||||
|
||||
3
bin/test.js
Normal file
3
bin/test.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import {isModified} from './library.js'
|
||||
|
||||
console.log(await isModified('/Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/pom.xml'))
|
||||
86
service-ai/database/20250702.sql
Normal file
86
service-ai/database/20250702.sql
Normal file
@@ -0,0 +1,86 @@
|
||||
create table hudi_collect_build_b12.service_ai_feedback
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
analysis longtext comment 'AI的分析结果',
|
||||
conclusion longtext comment 'AI的解决方案',
|
||||
source longtext not null comment '原始报障说明',
|
||||
status enum ('ANALYSIS_PROCESSING','ANALYSIS_SUCCESS','FINISHED') not null comment '报障处理状态',
|
||||
primary key (id)
|
||||
) comment ='报障信息记录' charset = utf8mb4;
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_feedback_pictures
|
||||
(
|
||||
feedback_id bigint not null,
|
||||
pictures_id bigint not null,
|
||||
primary key (feedback_id, pictures_id)
|
||||
) comment ='报障相关截图' charset = utf8mb4;
|
||||
|
||||
alter table hudi_collect_build_b12.service_ai_feedback_pictures
|
||||
add constraint UK3npjcyjyqfbdlf2v5tj64j2g3 unique (pictures_id);
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_file
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
filename varchar(255) comment '文件名称',
|
||||
md5 varchar(255) comment '文件的md5编码,用于校验文件的完整性',
|
||||
path varchar(255) comment '文件在主机上存储的实际路径',
|
||||
size bigint comment '文件大小,单位是byte',
|
||||
type varchar(255) comment '文件类型,通常记录的是文件的后缀名',
|
||||
primary key (id)
|
||||
) comment ='记录上传的文件存储信息' charset = utf8mb4;
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_flow_task
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
comment text comment '任务注释,用于额外说明',
|
||||
error longtext comment '任务运行产生的报错',
|
||||
input longtext comment '任务输入',
|
||||
result longtext comment '任务运行结果',
|
||||
status enum ('ERROR','FINISHED','RUNNING') not null comment '任务运行状态',
|
||||
template_description varchar(255) comment '任务对应的模板功能、内容说明',
|
||||
template_flow_graph longtext not null comment '任务对应的模板前端流程图数据',
|
||||
template_input_schema longtext comment '任务对应的模板入参Schema',
|
||||
template_name varchar(255) not null comment '任务对应的模板名称',
|
||||
primary key (id)
|
||||
) comment ='流程任务记录' charset = utf8mb4;
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_flow_task_template
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
description varchar(255) comment '模板功能、内容说明',
|
||||
flow_graph longtext not null comment '前端流程图数据',
|
||||
input_schema longtext comment '模板入参Schema',
|
||||
name varchar(255) not null comment '模板名称',
|
||||
primary key (id)
|
||||
) comment ='流程任务模板' charset = utf8mb4;
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_group
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
name varchar(255) not null comment '分组名称',
|
||||
status enum ('FINISHED','RUNNING') not null comment '分组处理状态',
|
||||
knowledge_id bigint not null,
|
||||
primary key (id)
|
||||
) comment ='知识库下包含的分组' charset = utf8mb4;
|
||||
|
||||
create table hudi_collect_build_b12.service_ai_knowledge
|
||||
(
|
||||
id bigint not null comment '记录唯一标记',
|
||||
created_time datetime(6) comment '记录创建时间',
|
||||
modified_time datetime(6) comment '记录更新时间',
|
||||
description longtext not null comment '知识库说明',
|
||||
name varchar(255) not null comment '知识库名称',
|
||||
strategy enum ('Cosine','Euclid') not null comment '知识库策略',
|
||||
vector_source_id bigint not null comment '知识库对应的向量库名',
|
||||
primary key (id)
|
||||
) comment ='知识库' charset = utf8mb4;
|
||||
@@ -1,11 +0,0 @@
|
||||
CREATE TABLE `service_ai_feedback`
|
||||
(
|
||||
`id` bigint NOT NULL,
|
||||
`source` longtext NOT NULL,
|
||||
`analysis_short` 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;
|
||||
@@ -1,11 +0,0 @@
|
||||
CREATE TABLE `service_ai_file`
|
||||
(
|
||||
`id` bigint NOT NULL,
|
||||
`filename` varchar(500) DEFAULT NULL,
|
||||
`size` bigint DEFAULT NULL,
|
||||
`md5` varchar(100) DEFAULT NULL,
|
||||
`path` varchar(500) DEFAULT NULL,
|
||||
`type` varchar(50) DEFAULT NULL,
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARSET = utf8mb4;
|
||||
@@ -1,9 +0,0 @@
|
||||
CREATE TABLE `service_ai_group`
|
||||
(
|
||||
`id` bigint NOT NULL,
|
||||
`knowledge_id` bigint NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`status` varchar(10) NOT NULL DEFAULT 'RUNNING',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) DEFAULT CHARSET = utf8mb4;
|
||||
@@ -1,10 +0,0 @@
|
||||
CREATE TABLE `service_ai_knowledge`
|
||||
(
|
||||
`id` bigint NOT NULL,
|
||||
`vector_source_id` varchar(100) NOT NULL,
|
||||
`name` varchar(100) 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,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARSET = utf8mb4;
|
||||
@@ -29,12 +29,19 @@
|
||||
<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>
|
||||
<liteflow.version>2.13.2</liteflow.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>
|
||||
|
||||
@@ -104,6 +111,11 @@
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blinkfox</groupId>
|
||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志相关 -->
|
||||
<dependency>
|
||||
@@ -142,7 +154,27 @@
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
<version>2.13.2</version>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-el-builder</artifactId>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-graaljs</artifactId>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-python</artifactId>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-lua</artifactId>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
@@ -154,12 +186,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>
|
||||
@@ -168,7 +210,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>
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.lanyuanxiaoyao.service.configuration;
|
||||
|
||||
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;
|
||||
@@ -13,6 +11,9 @@ import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
@@ -21,17 +22,30 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig {
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowCredentials(true);
|
||||
configuration.addAllowedOriginPattern("*");
|
||||
configuration.addAllowedHeader("*");
|
||||
configuration.addAllowedMethod("*");
|
||||
configuration.setMaxAge(7200L);
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
return http.authorizeHttpRequests(
|
||||
registry -> registry
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
registry -> registry
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
)
|
||||
.httpBasic(Customizer.withDefaults())
|
||||
.cors(AbstractHttpConfigurer::disable)
|
||||
.cors(Customizer.withDefaults())
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.formLogin(AbstractHttpConfigurer::disable)
|
||||
.build();
|
||||
|
||||
@@ -20,8 +20,16 @@
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jetty</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||
@@ -40,7 +48,15 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blinkfox</groupId>
|
||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
@@ -50,6 +66,10 @@
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-el-builder</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||
@@ -66,10 +86,56 @@
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon-ai-dialect-openai</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-graaljs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-script-python</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-ant</artifactId>
|
||||
<version>6.6.8.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
<path>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||
<version>6.6.8.Final</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>
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web;
|
||||
|
||||
import com.blinkfox.fenix.EnableFenix;
|
||||
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;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
import org.springframework.retry.annotation.EnableRetry;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@@ -23,23 +22,17 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@EnableEncryptableProperties
|
||||
@EnableRetry
|
||||
@EnableScheduling
|
||||
public class WebApplication implements ApplicationRunner, ApplicationContextAware {
|
||||
private static ApplicationContext context;
|
||||
@EnableFenix
|
||||
@EnableJpaAuditing
|
||||
public class WebApplication implements ApplicationRunner {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebApplication.class, args);
|
||||
}
|
||||
System.setProperty("polyglot.engine.WarnInterpreterOnly", "false");
|
||||
|
||||
public static <T> T getBean(Class<T> clazz) {
|
||||
return context.getBean(clazz);
|
||||
SpringApplication.run(WebApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||
WebApplication.context = context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface DetailController<DETAIL_ITEM> {
|
||||
String DETAIL = "/detail/{id}";
|
||||
|
||||
AmisResponse<DETAIL_ITEM> detail(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisCrudResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.query.Query;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface ListController {
|
||||
String LIST = "/list";
|
||||
|
||||
AmisCrudResponse list() throws Exception;
|
||||
|
||||
AmisCrudResponse list(Query query) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface RemoveController {
|
||||
String REMOVE = "/remove/{id}";
|
||||
|
||||
AmisResponse<Object> remove(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SaveController<SAVE_ITEM> {
|
||||
String SAVE = "/save";
|
||||
|
||||
AmisResponse<Long> save(SAVE_ITEM item) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, ListController, DetailController<DETAIL_ITEM>, RemoveController {
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisCrudResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.query.Query;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> implements SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
protected final SimpleServiceSupport<ENTITY> service;
|
||||
|
||||
public SimpleControllerSupport(SimpleServiceSupport<ENTITY> service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping(SAVE)
|
||||
@Override
|
||||
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||
SaveItemMapper<ENTITY, SAVE_ITEM> mapper = saveItemMapper();
|
||||
return AmisResponse.responseSuccess(service.save(mapper.from(item)));
|
||||
}
|
||||
|
||||
@GetMapping(LIST)
|
||||
@Override
|
||||
public AmisCrudResponse list() throws Exception {
|
||||
ListItemMapper<ENTITY, LIST_ITEM> mapper = listItemMapper();
|
||||
return AmisCrudResponse.responseCrudData(
|
||||
service.list()
|
||||
.collect(entity -> {
|
||||
try {
|
||||
return mapper.from(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping(LIST)
|
||||
@Override
|
||||
public AmisCrudResponse list(@RequestBody Query query) throws Exception {
|
||||
if (ObjectUtil.isNull(query)) {
|
||||
return AmisCrudResponse.responseCrudData(List.of(), 0);
|
||||
}
|
||||
ListItemMapper<ENTITY, LIST_ITEM> mapper = listItemMapper();
|
||||
Page<ENTITY> result = service.list(query);
|
||||
return AmisCrudResponse.responseCrudData(
|
||||
result.get()
|
||||
.map(entity -> {
|
||||
try {
|
||||
return mapper.from(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.toList(),
|
||||
result.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
@Override
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable("id") Long id) throws Exception {
|
||||
DetailItemMapper<ENTITY, DETAIL_ITEM> mapper = detailItemMapper();
|
||||
return AmisResponse.responseSuccess(mapper.from(service.detailOrThrow(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
@Override
|
||||
public AmisResponse<Object> remove(@PathVariable("id") Long id) throws Exception {
|
||||
service.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
protected abstract SaveItemMapper<ENTITY, SAVE_ITEM> saveItemMapper();
|
||||
|
||||
protected abstract ListItemMapper<ENTITY, LIST_ITEM> listItemMapper();
|
||||
|
||||
protected abstract DetailItemMapper<ENTITY, DETAIL_ITEM> detailItemMapper();
|
||||
|
||||
public interface SaveItemMapper<ENTITY, SAVE_ITEM> {
|
||||
ENTITY from(SAVE_ITEM item) throws Exception;
|
||||
}
|
||||
|
||||
public interface ListItemMapper<ENTITY, LIST_ITEM> {
|
||||
LIST_ITEM from(ENTITY entity) throws Exception;
|
||||
}
|
||||
|
||||
public interface DetailItemMapper<ENTITY, DETAIL_ITEM> {
|
||||
DETAIL_ITEM from(ENTITY entity) throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.controller.query;
|
||||
|
||||
import lombok.Data;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 统一查询
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-12-03
|
||||
*/
|
||||
@Data
|
||||
public class Query {
|
||||
private Queryable query;
|
||||
private ImmutableList<Sortable> sort;
|
||||
private Pageable page;
|
||||
|
||||
@Data
|
||||
public static class Queryable {
|
||||
private ImmutableList<String> nullEqual;
|
||||
private ImmutableList<String> notNullEqual;
|
||||
private ImmutableList<String> empty;
|
||||
private ImmutableList<String> notEmpty;
|
||||
private ImmutableMap<String, ?> equal;
|
||||
private ImmutableMap<String, ?> notEqual;
|
||||
private ImmutableMap<String, String> like;
|
||||
private ImmutableMap<String, String> notLike;
|
||||
private ImmutableMap<String, ?> great;
|
||||
private ImmutableMap<String, ?> less;
|
||||
private ImmutableMap<String, ?> greatEqual;
|
||||
private ImmutableMap<String, ?> lessEqual;
|
||||
private ImmutableMap<String, ImmutableList<?>> in;
|
||||
private ImmutableMap<String, ImmutableList<?>> notIn;
|
||||
private ImmutableMap<String, Between> between;
|
||||
private ImmutableMap<String, Between> notBetween;
|
||||
|
||||
@Data
|
||||
public static class Between {
|
||||
private String start;
|
||||
private String end;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Sortable {
|
||||
private String column;
|
||||
private Direction direction;
|
||||
|
||||
public enum Direction {
|
||||
ASC,
|
||||
DESC,
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Pageable {
|
||||
private Integer index;
|
||||
private Integer size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.entity;
|
||||
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class IdOnlyEntity {
|
||||
@Comment("记录唯一标记")
|
||||
@Id
|
||||
@GeneratedValue(generator = "snowflake")
|
||||
@GenericGenerator(name = "snowflake", strategy = "com.lanyuanxiaoyao.service.ai.web.configuration.SnowflakeIdGenerator")
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.entity;
|
||||
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class SimpleEntity extends IdOnlyEntity {
|
||||
@Comment("记录创建时间")
|
||||
@CreatedDate
|
||||
private LocalDateTime createdTime;
|
||||
@Comment("记录更新时间")
|
||||
@LastModifiedDate
|
||||
private LocalDateTime modifiedTime;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public class SimpleItem {
|
||||
private Long id;
|
||||
private LocalDateTime createdTime;
|
||||
private LocalDateTime modifiedTime;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
|
||||
/**
|
||||
* 整合一下
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface SimpleRepository<E, ID> extends FenixJpaRepository<E, ID>, FenixJpaSpecificationExecutor<E>, QueryByExampleExecutor<E> {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.service;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.query.Query;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SimpleService<ENTITY extends SimpleEntity> {
|
||||
Long save(ENTITY entity) throws Exception;
|
||||
|
||||
Long count() throws Exception;
|
||||
|
||||
ImmutableList<ENTITY> list() throws Exception;
|
||||
|
||||
ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
|
||||
|
||||
Page<ENTITY> list(Query query) throws Exception;
|
||||
|
||||
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||
|
||||
ENTITY detail(Long id) throws Exception;
|
||||
|
||||
ENTITY detailOrThrow(Long id) throws Exception;
|
||||
|
||||
ENTITY detailOrNull(Long id) throws Exception;
|
||||
|
||||
void remove(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.base.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.EnumUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.query.Query;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.IdOnlyEntity_;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity_;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implements SimpleService<ENTITY> {
|
||||
private static final Integer DEFAULT_PAGE_INDEX = 1;
|
||||
private static final Integer DEFAULT_PAGE_SIZE = 10;
|
||||
protected final SimpleRepository<ENTITY, Long> repository;
|
||||
|
||||
public SimpleServiceSupport(SimpleRepository<ENTITY, Long> repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public Long save(ENTITY entity) {
|
||||
if (ObjectUtil.isNotNull(entity.getId())) {
|
||||
Long id = entity.getId();
|
||||
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
|
||||
BeanUtil.copyProperties(
|
||||
entity,
|
||||
targetEntity,
|
||||
CopyOptions.create()
|
||||
.setIgnoreProperties(
|
||||
IdOnlyEntity_.ID,
|
||||
SimpleEntity_.CREATED_TIME,
|
||||
SimpleEntity_.MODIFIED_TIME
|
||||
)
|
||||
);
|
||||
entity = targetEntity;
|
||||
}
|
||||
entity = repository.save(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count() {
|
||||
return repository.count(
|
||||
(root, query, builder) ->
|
||||
builder.and(
|
||||
listPredicate(root, query, builder)
|
||||
.reject(ObjectUtil::isNull)
|
||||
.toArray(new Predicate[]{})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list() {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) ->
|
||||
builder.and(
|
||||
listPredicate(root, query, builder)
|
||||
.reject(ObjectUtil::isNull)
|
||||
.toArray(new Predicate[]{})
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
predicates.add(builder.in(root.get("id")).value(ids));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
private <Y> Path<Y> column(Root<ENTITY> root, String column) {
|
||||
String[] columns = StrUtil.splitToArray(column, "/");
|
||||
Path<Y> path = root.get(columns[0]);
|
||||
for (int i = 1; i < columns.length; i++) {
|
||||
path = path.get(columns[i]);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private <Y> Object value(Path<Y> column, Object value) {
|
||||
Class<?> javaType = column.getJavaType();
|
||||
if (EnumUtil.isEnum(javaType)) {
|
||||
return EnumUtil.fromString((Class<Enum>) javaType, (String) value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ImmutableList<Predicate> queryPredicates(Query.Queryable queryable, Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
MutableList<Predicate> predicates = Lists.mutable.empty();
|
||||
if (ObjectUtil.isEmpty(queryable)) {
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNullEqual())) {
|
||||
queryable.getNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotNullEqual())) {
|
||||
queryable.getNotNullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEmpty())) {
|
||||
queryable.getEmpty().forEach(column -> predicates.add(builder.isEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEmpty())) {
|
||||
queryable.getNotEmpty().forEach(column -> predicates.add(builder.isNotEmpty(column(root, column))));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.equal(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotEqual())) {
|
||||
queryable.getEqual().forEachKeyValue((column, value) -> {
|
||||
Path<Object> path = column(root, column);
|
||||
predicates.add(builder.notEqual(path, value(path, value)));
|
||||
});
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLike())) {
|
||||
queryable.getLike().forEachKeyValue((column, value) -> predicates.add(builder.like(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotLike())) {
|
||||
queryable.getNotLike().forEachKeyValue((column, value) -> predicates.add(builder.notLike(column(root, column), value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreat())) {
|
||||
queryable.getGreat().forEachKeyValue((column, value) -> predicates.add(builder.greaterThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLess())) {
|
||||
queryable.getLess().forEachKeyValue((column, value) -> predicates.add(builder.lessThan(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getGreatEqual())) {
|
||||
queryable.getGreatEqual().forEachKeyValue((column, value) -> predicates.add(builder.greaterThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getLessEqual())) {
|
||||
queryable.getLessEqual().forEachKeyValue((column, value) -> predicates.add(builder.lessThanOrEqualTo(column(root, column), (Comparable<Object>) value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getIn())) {
|
||||
queryable.getIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value)));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotIn())) {
|
||||
queryable.getNotIn().forEachKeyValue((column, value) -> predicates.add(builder.in(column(root, column)).value(value).not()));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getBetween())) {
|
||||
queryable.getBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(queryable.getNotBetween())) {
|
||||
queryable.getNotBetween().forEachKeyValue((column, value) -> predicates.add(builder.between(column(root, column), value.getStart(), value.getEnd())));
|
||||
}
|
||||
return predicates.toImmutable();
|
||||
}
|
||||
|
||||
protected ImmutableList<Predicate> listPredicate(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ENTITY> list(Query listQuery) {
|
||||
PageRequest pageRequest = PageRequest.of(DEFAULT_PAGE_INDEX - 1, DEFAULT_PAGE_SIZE, Sort.by(SimpleEntity_.CREATED_TIME).descending());
|
||||
if (ObjectUtil.isNotNull(listQuery.getPage())) {
|
||||
pageRequest = PageRequest.of(
|
||||
ObjectUtil.defaultIfNull(listQuery.getPage().getIndex(), DEFAULT_PAGE_INDEX) - 1,
|
||||
ObjectUtil.defaultIfNull(listQuery.getPage().getSize(), DEFAULT_PAGE_SIZE),
|
||||
Sort.by(SimpleEntity_.CREATED_TIME).descending()
|
||||
);
|
||||
}
|
||||
return repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
predicates.addAllIterable(queryPredicates(listQuery.getQuery(), root, query, builder));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
pageRequest
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return repository.findOne(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.ofAll(listPredicate(root, query, builder));
|
||||
predicates.add(builder.equal(root.get(IdOnlyEntity_.id), id));
|
||||
return builder.and(predicates.reject(ObjectUtil::isNull).toArray(new Predicate[predicates.size()]));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detail(Long id) {
|
||||
return detailOrNull(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrThrow(Long id) {
|
||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrNull(Long id) {
|
||||
return detailOptional(id).orElse(null);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
if (ObjectUtil.isNotNull(id)) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdNotFoundException extends RuntimeException {
|
||||
public IdNotFoundException() {
|
||||
super("资源不存在");
|
||||
}
|
||||
|
||||
public IdNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的资源不存在", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "file-store")
|
||||
public class FileStoreConfiguration {
|
||||
public class FileStoreProperties {
|
||||
private String downloadPrefix;
|
||||
private String uploadPath;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class LlmConfiguration {
|
||||
.openAiApi(apiBuilder.build())
|
||||
.defaultOptions(
|
||||
OpenAiChatOptions.builder()
|
||||
.model(llmProperties.getChat().getModel())
|
||||
.model(llmProperties.getVisual().getModel())
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.configuration;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
|
||||
/**
|
||||
* 使用雪花算法作为ID生成器
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-14
|
||||
*/
|
||||
@Slf4j
|
||||
public class SnowflakeIdGenerator implements IdentifierGenerator {
|
||||
|
||||
@Override
|
||||
public Serializable generate(SharedSessionContractImplementor session, Object object) {
|
||||
try {
|
||||
return Snowflake.next();
|
||||
} catch (Exception e) {
|
||||
log.error("Generate snowflake id failed", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Snowflake {
|
||||
/**
|
||||
* 起始的时间戳
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.configuration;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringBeanGetter implements ApplicationContextAware {
|
||||
private static ApplicationContext context;
|
||||
|
||||
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 setApplicationContext(ApplicationContext context) throws BeansException {
|
||||
SpringBeanGetter.context = context;
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ 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.web.configuration.FileStoreConfiguration;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.vo.DataFileVO;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.FileStoreProperties;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.DataFile;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.DataFileService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -21,7 +21,10 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -41,26 +44,46 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
@RestController
|
||||
@RequestMapping("/upload")
|
||||
public class DataFileController {
|
||||
private final FileStoreConfiguration fileStoreConfiguration;
|
||||
private final FileStoreProperties fileStoreProperties;
|
||||
private final DataFileService dataFileService;
|
||||
private final String uploadFolderPath;
|
||||
private final String cacheFolderPath;
|
||||
private final String sliceFolderPath;
|
||||
|
||||
public DataFileController(FileStoreConfiguration fileStoreConfiguration, DataFileService dataFileService) {
|
||||
this.fileStoreConfiguration = fileStoreConfiguration;
|
||||
public DataFileController(FileStoreProperties fileStoreProperties, DataFileService dataFileService) {
|
||||
this.fileStoreProperties = fileStoreProperties;
|
||||
this.dataFileService = dataFileService;
|
||||
|
||||
this.uploadFolderPath = fileStoreConfiguration.getUploadPath();
|
||||
this.uploadFolderPath = fileStoreProperties.getUploadPath();
|
||||
this.cacheFolderPath = StrUtil.format("{}/cache", uploadFolderPath);
|
||||
this.sliceFolderPath = StrUtil.format("{}/slice", uploadFolderPath);
|
||||
}
|
||||
|
||||
@PostMapping("/detail")
|
||||
public AmisResponse<?> detail(@RequestBody DetailRequest request) {
|
||||
var mapper = Mappers.getMapper(DetailResponse.Mapper.class);
|
||||
return AmisResponse.responseCrudData(dataFileService.downloadFile(request.ids).collect(mapper::from));
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
public AmisResponse<?> detail(@RequestParam("ids") String ids) {
|
||||
if (StrUtil.isBlank(ids)) {
|
||||
return AmisResponse.responseCrudData(Sets.immutable.empty());
|
||||
}
|
||||
var mapper = Mappers.getMapper(DetailResponse.Mapper.class);
|
||||
return AmisResponse.responseCrudData(
|
||||
dataFileService.downloadFile(
|
||||
Sets.immutable.ofAll(StrUtil.split(ids, ","))
|
||||
.collect(Long::parseLong)
|
||||
).collect(mapper::from)
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("")
|
||||
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/{}", fileStoreConfiguration.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));
|
||||
@@ -80,8 +103,8 @@ public class DataFileController {
|
||||
}
|
||||
|
||||
@GetMapping("/download/{id}")
|
||||
public void download(@PathVariable Long id, HttpServletResponse response) throws IOException {
|
||||
DataFileVO dataFile = dataFileService.downloadFile(id);
|
||||
public void download(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
|
||||
DataFile dataFile = dataFileService.downloadFile(id);
|
||||
File targetFile = new File(dataFile.getPath());
|
||||
response.setHeader("Content-Type", dataFile.getType());
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
@@ -157,7 +180,7 @@ public class DataFileController {
|
||||
request.uploadId,
|
||||
request.filename,
|
||||
request.uploadId.toString(),
|
||||
StrUtil.format("{}/upload/download/{}", fileStoreConfiguration.getDownloadPrefix(), request.uploadId)
|
||||
StrUtil.format("{}/upload/download/{}", fileStoreProperties.getDownloadPrefix(), request.uploadId)
|
||||
));
|
||||
} else {
|
||||
throw new RuntimeException("合并文件失败");
|
||||
@@ -170,6 +193,24 @@ public class DataFileController {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DetailRequest {
|
||||
private ImmutableSet<Long> ids;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DetailResponse {
|
||||
private Long id;
|
||||
private String filename;
|
||||
private Long size;
|
||||
private String md5;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper {
|
||||
DetailResponse from(DataFile file);
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class StartRequest {
|
||||
private String name;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.caht;
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.chat;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.Prompts;
|
||||
@@ -6,10 +6,13 @@ 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;
|
||||
@@ -98,24 +101,34 @@ public class ChatController {
|
||||
|
||||
@PostMapping("async")
|
||||
public SseEmitter chatAsync(
|
||||
@RequestBody ImmutableList<MessageVO> messages
|
||||
@RequestBody ImmutableList<MessageVO> messages,
|
||||
HttpServletResponse httpResponse
|
||||
) {
|
||||
SseEmitter emitter = new SseEmitter();
|
||||
buildRequest(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;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,100 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.feedback;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.IdOnlyEntity;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.DataFileService;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.feedback.FeedbackService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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 {
|
||||
public class FeedbackController extends SimpleControllerSupport<Feedback, FeedbackController.SaveItem, FeedbackController.ListItem, FeedbackController.ListItem> {
|
||||
private final FeedbackService feedbackService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public FeedbackController(FeedbackService feedbackService) {
|
||||
public FeedbackController(FeedbackService feedbackService, DataFileService dataFileService) {
|
||||
super(feedbackService);
|
||||
this.feedbackService = feedbackService;
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
public void add(
|
||||
@RequestParam("source") String source,
|
||||
@RequestParam(value = "pictures", required = false) ImmutableList<Long> pictures
|
||||
) {
|
||||
feedbackService.add(source, ObjectUtil.defaultIfNull(pictures, Lists.immutable.empty()));
|
||||
@GetMapping("reanalysis/{id}")
|
||||
public void reanalysis(@PathVariable("id") Long id) {
|
||||
feedbackService.reanalysis(id);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public AmisResponse<?> list() {
|
||||
return AmisResponse.responseCrudData(feedbackService.list());
|
||||
@PostMapping("conclude")
|
||||
public void conclude(@RequestBody ConcludeItem item) {
|
||||
feedbackService.updateConclusion(item.getId(), item.getConclusion());
|
||||
}
|
||||
|
||||
@GetMapping("delete")
|
||||
public void delete(@RequestParam("id") Long id) {
|
||||
feedbackService.remove(id);
|
||||
@Override
|
||||
protected SaveItemMapper<Feedback, SaveItem> saveItemMapper() {
|
||||
return item -> {
|
||||
Feedback feedback = new Feedback();
|
||||
feedback.setSource(item.getSource());
|
||||
feedback.setPictures(dataFileService.downloadFile(item.getPictures()).toSet());
|
||||
return feedback;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItemMapper<Feedback, ListItem> listItemMapper() {
|
||||
return Mappers.getMapper(ListItem.Mapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<Feedback, ListItem> detailItemMapper() {
|
||||
ListItemMapper<Feedback, ListItem> mapper = listItemMapper();
|
||||
return mapper::from;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SaveItem {
|
||||
private String source;
|
||||
private ImmutableSet<Long> pictures;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class ConcludeItem {
|
||||
private Long id;
|
||||
private String conclusion;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleItem {
|
||||
private String source;
|
||||
private ImmutableSet<Long> pictures;
|
||||
private String analysis;
|
||||
private String conclusion;
|
||||
private Feedback.Status status;
|
||||
|
||||
@org.mapstruct.Mapper(
|
||||
imports = {
|
||||
IdOnlyEntity.class,
|
||||
Sets.class
|
||||
}
|
||||
)
|
||||
public interface Mapper extends ListItemMapper<Feedback, ListItem> {
|
||||
@Mapping(target = "pictures", expression = "java(Sets.immutable.ofAll(feedback.getPictures()).collect(IdOnlyEntity::getId))")
|
||||
@Override
|
||||
ListItem from(Feedback feedback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.knowledge;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.GroupService;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.knowledge.KnowledgeBaseService;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -16,21 +19,49 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("knowledge/group")
|
||||
public class GroupController {
|
||||
private final GroupService groupService;
|
||||
public class GroupController extends SimpleControllerSupport<Group, GroupController.SaveItem, GroupController.ListItem, GroupController.ListItem> {
|
||||
private final KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
public GroupController(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
public GroupController(GroupService groupService, KnowledgeBaseService knowledgeBaseService) {
|
||||
super(groupService);
|
||||
this.knowledgeBaseService = knowledgeBaseService;
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public AmisResponse<?> list(@RequestParam("knowledge_id") Long knowledgeId) {
|
||||
return AmisResponse.responseCrudData(groupService.list(knowledgeId));
|
||||
@Override
|
||||
protected SaveItemMapper<Group, SaveItem> saveItemMapper() {
|
||||
return item -> {
|
||||
Group group = new Group();
|
||||
group.setName(item.getName());
|
||||
group.setKnowledge(knowledgeBaseService.detailOrThrow(item.getKnowledgeId()));
|
||||
return group;
|
||||
};
|
||||
}
|
||||
|
||||
@GetMapping("delete")
|
||||
public AmisResponse<?> delete(@RequestParam("id") Long id) throws ExecutionException, InterruptedException {
|
||||
groupService.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
@Override
|
||||
protected ListItemMapper<Group, ListItem> listItemMapper() {
|
||||
return Mappers.getMapper(ListItem.Mapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<Group, ListItem> detailItemMapper() {
|
||||
ListItemMapper<Group, ListItem> mapper = listItemMapper();
|
||||
return mapper::from;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SaveItem {
|
||||
private String name;
|
||||
private Long knowledgeId;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class ListItem extends SimpleItem {
|
||||
private String name;
|
||||
private Group.Status status;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper extends ListItemMapper<Group, ListItem> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,24 @@ 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.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
|
||||
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 io.qdrant.client.grpc.Collections;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -25,49 +34,52 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("knowledge")
|
||||
public class KnowledgeBaseController {
|
||||
public class KnowledgeBaseController extends SimpleControllerSupport<Knowledge, KnowledgeBaseController.SaveItem, KnowledgeBaseController.ListItem, KnowledgeBaseController.ListItem> {
|
||||
private final KnowledgeBaseService knowledgeBaseService;
|
||||
private final EmbeddingService embeddingService;
|
||||
|
||||
public KnowledgeBaseController(KnowledgeBaseService knowledgeBaseService, EmbeddingService embeddingService) {
|
||||
super(knowledgeBaseService);
|
||||
this.knowledgeBaseService = knowledgeBaseService;
|
||||
this.embeddingService = embeddingService;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
public void add(
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("strategy") String strategy
|
||||
) throws ExecutionException, InterruptedException {
|
||||
knowledgeBaseService.add(name, strategy);
|
||||
@Override
|
||||
protected SaveItemMapper<Knowledge, SaveItem> saveItemMapper() {
|
||||
return Mappers.getMapper(SaveItem.Mapper.class);
|
||||
}
|
||||
|
||||
@GetMapping("name")
|
||||
public AmisMapResponse name(@RequestParam("id") Long id) {
|
||||
@Override
|
||||
protected ListItemMapper<Knowledge, ListItem> listItemMapper() {
|
||||
ListItem.Mapper mapper = Mappers.getMapper(ListItem.Mapper.class);
|
||||
return knowledge -> mapper.from(knowledge, knowledgeBaseService.collectionInfo(knowledge.getVectorSourceId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<Knowledge, ListItem> detailItemMapper() {
|
||||
ListItem.Mapper mapper = Mappers.getMapper(ListItem.Mapper.class);
|
||||
return knowledge -> mapper.from(knowledge, knowledgeBaseService.collectionInfo(knowledge.getVectorSourceId()));
|
||||
}
|
||||
|
||||
@GetMapping("{id}/name")
|
||||
public AmisMapResponse name(@PathVariable("id") Long id) {
|
||||
return AmisResponse.responseMapData()
|
||||
.setData("name", knowledgeBaseService.getName(id));
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public AmisResponse<?> list() {
|
||||
return AmisResponse.responseCrudData(knowledgeBaseService.list());
|
||||
}
|
||||
|
||||
@GetMapping("delete")
|
||||
public void delete(@RequestParam("id") Long id) throws ExecutionException, InterruptedException {
|
||||
knowledgeBaseService.remove(id);
|
||||
@PostMapping("update_description")
|
||||
public void updateDescription(
|
||||
@RequestParam("id") Long id,
|
||||
@RequestParam("description") String description
|
||||
) throws Exception {
|
||||
knowledgeBaseService.updateDescription(id, description);
|
||||
}
|
||||
|
||||
@PostMapping("preview_text")
|
||||
public AmisResponse<?> previewText(
|
||||
@RequestParam(value = "mode", defaultValue = "NORMAL") String mode,
|
||||
@RequestParam(value = "type", defaultValue = "text") String type,
|
||||
@RequestParam(value = "content", required = false) String content,
|
||||
@RequestParam(value = "files", required = false) String files
|
||||
) {
|
||||
if (StrUtil.equals("text", type)) {
|
||||
public AmisResponse<?> previewText(@RequestBody SubmitItem item) {
|
||||
if (StrUtil.equals("text", item.getType())) {
|
||||
return AmisResponse.responseCrudData(
|
||||
embeddingService.preview(mode, content)
|
||||
embeddingService.preview(item.getMode(), item.getContent())
|
||||
.collect(doc -> {
|
||||
SegmentVO vo = new SegmentVO();
|
||||
vo.setId(doc.getId());
|
||||
@@ -75,9 +87,9 @@ public class KnowledgeBaseController {
|
||||
return vo;
|
||||
})
|
||||
);
|
||||
} else if (StrUtil.equals("file", type)) {
|
||||
} else if (StrUtil.equals("file", item.getType())) {
|
||||
return AmisResponse.responseCrudData(
|
||||
embeddingService.preview(mode, Lists.immutable.of(files.split(",")))
|
||||
embeddingService.preview(item.getMode(), item.getFiles())
|
||||
.collect(doc -> {
|
||||
SegmentVO vo = new SegmentVO();
|
||||
vo.setId(doc.getId());
|
||||
@@ -86,44 +98,87 @@ public class KnowledgeBaseController {
|
||||
})
|
||||
);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported type: " + type);
|
||||
throw new IllegalArgumentException("Unsupported type: " + item.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("submit_text")
|
||||
public void submitText(
|
||||
@RequestParam("id") Long id,
|
||||
@RequestParam(value = "mode", defaultValue = "NORMAL") String mode,
|
||||
@RequestParam(value = "type", defaultValue = "text") String type,
|
||||
@RequestParam(value = "content", required = false) String content,
|
||||
@RequestParam(value = "files", required = false) String files
|
||||
) {
|
||||
if (StrUtil.equals("text", type)) {
|
||||
embeddingService.submit(id, mode, content);
|
||||
} else if (StrUtil.equals("file", type)) {
|
||||
embeddingService.submit(id, mode, Lists.immutable.of(files.split(",")));
|
||||
public void submitText(@RequestBody SubmitItem item) {
|
||||
if (StrUtil.equals("text", item.getMode())) {
|
||||
embeddingService.submit(item.getId(), item.getMode(), item.getContent());
|
||||
} else if (StrUtil.equals("file", item.getType())) {
|
||||
embeddingService.submit(item.getId(), item.getMode(), item.getFiles());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported type: " + type);
|
||||
throw new IllegalArgumentException("Unsupported type: " + item.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("submit_text_directly")
|
||||
public void submitDirectly(
|
||||
@RequestParam("id") Long id,
|
||||
@RequestParam(value = "name", required = false) String name,
|
||||
@RequestParam(value = "split_key", defaultValue = "\n\n") String splitKey,
|
||||
@RequestBody String content
|
||||
) {
|
||||
embeddingService.submitDirectly(id, name, Lists.immutable.of(content.split(splitKey)));
|
||||
public void submitDirectly(@RequestBody SubmitDirectlyItem item) {
|
||||
embeddingService.submitDirectly(item.getId(), item.getName(), Lists.immutable.ofAll(StrUtil.split(item.getContent(), item.getSplitKey())));
|
||||
}
|
||||
|
||||
@PostMapping("query")
|
||||
public ImmutableList<String> query(
|
||||
@RequestParam("id") Long id,
|
||||
@RequestParam(value = "limit", defaultValue = "5") Integer limit,
|
||||
@RequestParam(value = "threshold", defaultValue = "0.6") Double threshold,
|
||||
@RequestBody String text
|
||||
) throws ExecutionException, InterruptedException, IOException {
|
||||
return knowledgeBaseService.query(id, text, limit, threshold);
|
||||
public ImmutableList<String> query(@RequestBody QueryItem item) throws ExecutionException, InterruptedException, IOException {
|
||||
return knowledgeBaseService.query(item.getId(), item.getText(), item.getLimit(), item.getThreshold());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SaveItem {
|
||||
private String name;
|
||||
private String strategy;
|
||||
private String description;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper extends SaveItemMapper<Knowledge, SaveItem> {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class ListItem extends SimpleItem {
|
||||
private Long vectorSourceId;
|
||||
private String name;
|
||||
private String description;
|
||||
private String strategy;
|
||||
private Long size;
|
||||
private Long points;
|
||||
private Long segments;
|
||||
private String status;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper extends ListItemMapper<Knowledge, ListItem> {
|
||||
@Mapping(source = "info.config.params.vectorsConfig.params.distance", target = "strategy")
|
||||
@Mapping(source = "info.config.params.vectorsConfig.params.size", target = "size")
|
||||
@Mapping(source = "info.pointsCount", target = "points")
|
||||
@Mapping(source = "info.segmentsCount", target = "segments")
|
||||
@Mapping(source = "info.status", target = "status")
|
||||
ListItem from(Knowledge knowledge, Collections.CollectionInfo info);
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SubmitItem {
|
||||
private Long id;
|
||||
private String mode;
|
||||
private String type;
|
||||
private String content;
|
||||
private ImmutableList<Long> files;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SubmitDirectlyItem {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String splitKey = "\n\n";
|
||||
private String content;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class QueryItem {
|
||||
private Long id;
|
||||
private Integer limit = 5;
|
||||
private Double threshold = 0.6;
|
||||
private String text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskService;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("flow_task")
|
||||
public class TaskController extends SimpleControllerSupport<FlowTask, TaskController.SaveItem, TaskController.ListItem, TaskController.DetailItem> {
|
||||
private final FlowTaskService flowTaskService;
|
||||
private final FlowTaskTemplateService flowTaskTemplateService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public TaskController(FlowTaskService flowTaskService, FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(flowTaskService);
|
||||
this.flowTaskService = flowTaskService;
|
||||
this.flowTaskTemplateService = flowTaskTemplateService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("input_data/{id}")
|
||||
public AmisResponse<?> getInputData(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var task = flowTaskService.detailOrThrow(id);
|
||||
if (ObjectUtil.isEmpty(task.getInput())) {
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
return AmisResponse.responseSuccess(mapper.readValue(task.getInput(), Map.class));
|
||||
}
|
||||
|
||||
@GetMapping("input_schema/{id}")
|
||||
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var task = flowTaskService.detailOrThrow(id);
|
||||
if (ObjectUtil.isEmpty(task.getTemplateInputSchema())) {
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
return AmisResponse.responseSuccess(mapper.readValue(task.getTemplateInputSchema(), Map.class));
|
||||
}
|
||||
|
||||
@GetMapping("execute/{id}")
|
||||
public AmisResponse<?> execute(@PathVariable("id") Long id) throws JsonProcessingException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
flowTaskService.execute(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SaveItemMapper<FlowTask, SaveItem> saveItemMapper() {
|
||||
return item -> {
|
||||
FlowTask task = new FlowTask();
|
||||
FlowTaskTemplate template = flowTaskTemplateService.detailOrThrow(item.getTemplateId());
|
||||
task.setTemplateName(template.getName());
|
||||
task.setTemplateDescription(template.getDescription());
|
||||
task.setTemplateInputSchema(template.getInputSchema());
|
||||
task.setTemplateFlowGraph(template.getFlowGraph());
|
||||
task.setInput(ObjectUtil.isEmpty(item.getInput()) ? null : mapper.writeValueAsString(item.getInput()));
|
||||
return task;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItemMapper<FlowTask, ListItem> listItemMapper() {
|
||||
ListItem.Mapper map = Mappers.getMapper(ListItem.Mapper.class);
|
||||
return map::from;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<FlowTask, DetailItem> detailItemMapper() {
|
||||
DetailItem.Mapper map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||
return map::from;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SaveItem {
|
||||
private Long templateId;
|
||||
private Object input;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleItem {
|
||||
private String templateName;
|
||||
private FlowTask.Status status;
|
||||
private Boolean hasInput;
|
||||
|
||||
@org.mapstruct.Mapper(imports = {
|
||||
StrUtil.class
|
||||
})
|
||||
public static abstract class Mapper {
|
||||
@Mapping(target = "hasInput", expression = "java(StrUtil.isNotBlank(task.getInput()))")
|
||||
public abstract ListItem from(FlowTask task);
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class DetailItem extends ListItem {
|
||||
private String error;
|
||||
private String result;
|
||||
|
||||
@org.mapstruct.Mapper(imports = {
|
||||
StrUtil.class
|
||||
})
|
||||
public static abstract class Mapper extends ListItem.Mapper {
|
||||
@Mapping(target = "hasInput", expression = "java(StrUtil.isNotBlank(task.getInput()))")
|
||||
public abstract DetailItem from(FlowTask task);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("flow_task/template")
|
||||
public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemplate, TaskTemplateController.SaveItem, TaskTemplateController.ListItem, TaskTemplateController.DetailItem> {
|
||||
private final FlowTaskTemplateService flowTaskTemplateService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public TaskTemplateController(FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(flowTaskTemplateService);
|
||||
this.flowTaskTemplateService = flowTaskTemplateService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("input_schema/{id}")
|
||||
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var template = flowTaskTemplateService.detailOrThrow(id);
|
||||
if (ObjectUtil.isEmpty(template.getInputSchema())) {
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
return AmisResponse.responseSuccess(mapper.readValue(template.getInputSchema(), Map.class));
|
||||
}
|
||||
|
||||
@GetMapping("flow_graph/{id}")
|
||||
public AmisResponse<?> getFlowGraph(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var template = flowTaskTemplateService.detailOrThrow(id);
|
||||
return AmisResponse.responseSuccess(mapper.readValue(template.getFlowGraph(), Map.class));
|
||||
}
|
||||
|
||||
@PostMapping("update_flow_graph")
|
||||
public AmisResponse<?> updateFlowGraph(@RequestBody UpdateGraphItem item) throws JsonProcessingException {
|
||||
flowTaskTemplateService.updateFlowGraph(item.getId(), mapper.writeValueAsString(item.getGraph()));
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SaveItemMapper<FlowTaskTemplate, SaveItem> saveItemMapper() {
|
||||
return Mappers.getMapper(SaveItem.Mapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItemMapper<FlowTaskTemplate, ListItem> listItemMapper() {
|
||||
return Mappers.getMapper(ListItem.Mapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<FlowTaskTemplate, DetailItem> detailItemMapper() {
|
||||
var map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||
return template -> map.from(template, mapper);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class SaveItem {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper extends SaveItemMapper<FlowTaskTemplate, SaveItem> {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleItem {
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public interface Mapper extends ListItemMapper<FlowTaskTemplate, ListItem> {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class DetailItem extends SimpleItem {
|
||||
private String name;
|
||||
private String description;
|
||||
private Map<String, Object> inputSchema;
|
||||
private Map<String, Object> flowGraph;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public static abstract class Mapper {
|
||||
public abstract DetailItem from(FlowTaskTemplate template, @Context ObjectMapper mapper) throws Exception;
|
||||
|
||||
public Map<String, Object> mapJson(String source, @Context ObjectMapper mapper) throws Exception {
|
||||
if (ObjectUtil.isNull(source)) {
|
||||
return null;
|
||||
}
|
||||
return mapper.readValue(source, new TypeReference<>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class UpdateGraphItem {
|
||||
private Long id;
|
||||
private Map<String, Object> graph;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.store.FlowStore;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 流程执行器
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250630
|
||||
*/
|
||||
public class FlowExecutor {
|
||||
private final FlowStore flowStore;
|
||||
private final ImmutableMap<String, Class<? extends FlowNodeRunner>> runnerMap;
|
||||
|
||||
public FlowExecutor(FlowStore flowStore, ImmutableMap<String, Class<? extends FlowNodeRunner>> runnerMap) {
|
||||
this.flowStore = flowStore;
|
||||
this.runnerMap = runnerMap;
|
||||
}
|
||||
|
||||
public void execute(FlowGraph graph) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
execute(graph, new FlowContext());
|
||||
}
|
||||
|
||||
public void execute(FlowGraph graph, FlowContext context) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
var runner = new FlowGraphRunner(graph, context, flowStore, runnerMap);
|
||||
runner.run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.store.FlowStore;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
|
||||
|
||||
/**
|
||||
* Graph执行器
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250701
|
||||
*/
|
||||
public final class FlowGraphRunner {
|
||||
private final FlowGraph flowGraph;
|
||||
private final FlowContext flowContext;
|
||||
private final FlowStore flowStore;
|
||||
private final ImmutableMap<String, Class<? extends FlowNodeRunner>> nodeRunnerClass;
|
||||
private final Queue<FlowNode> executionQueue = new LinkedList<>();
|
||||
private final ImmutableSetMultimap<String, FlowEdge> nodeInputMap;
|
||||
private final ImmutableSetMultimap<String, FlowEdge> nodeOutputMap;
|
||||
private final ImmutableMap<String, FlowNode> nodeMap;
|
||||
|
||||
public FlowGraphRunner(FlowGraph flowGraph, FlowContext flowContext, FlowStore flowStore, ImmutableMap<String, Class<? extends FlowNodeRunner>> nodeRunnerClass) {
|
||||
this.flowGraph = flowGraph;
|
||||
this.flowContext = flowContext;
|
||||
this.flowStore = flowStore;
|
||||
this.nodeRunnerClass = nodeRunnerClass;
|
||||
|
||||
nodeInputMap = flowGraph.edges().groupBy(FlowEdge::target);
|
||||
nodeOutputMap = flowGraph.edges().groupBy(FlowEdge::source);
|
||||
nodeMap = flowGraph.nodes().toImmutableMap(FlowNode::id, node -> node);
|
||||
}
|
||||
|
||||
public void run() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
flowStore.init(flowGraph);
|
||||
|
||||
for (FlowNode node : flowGraph.nodes()) {
|
||||
if (ObjectUtil.isNull(node.parentId())) {
|
||||
executionQueue.offer(node);
|
||||
}
|
||||
}
|
||||
while (!executionQueue.isEmpty()) {
|
||||
var node = executionQueue.poll();
|
||||
if (ObjectUtil.isNull(node)) {
|
||||
continue;
|
||||
}
|
||||
process(node, flowContext);
|
||||
}
|
||||
}
|
||||
|
||||
private void process(FlowNode node, FlowContext context) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
if (
|
||||
(
|
||||
// 没有入节点,即开始节点
|
||||
!nodeInputMap.containsKey(node.id())
|
||||
// 或者所有入的边状态都已经完成
|
||||
|| nodeInputMap.get(node.id()).allSatisfy(edge -> flowStore.checkEdgeStatus(flowGraph.id(), edge.id(), FlowEdge.Status.EXECUTE, FlowEdge.Status.SKIP))
|
||||
)
|
||||
// 当前节点还未执行
|
||||
&& flowStore.checkNodeStatus(flowGraph.id(), node.id(), FlowNode.Status.INITIAL)
|
||||
) {
|
||||
// 是开始节点或入的边有至少一条是「执行」
|
||||
if (
|
||||
!nodeInputMap.containsKey(node.id())
|
||||
|| nodeInputMap.get(node.id()).anySatisfy(edge -> flowStore.checkEdgeStatus(flowGraph.id(), edge.id(), FlowEdge.Status.EXECUTE))
|
||||
) {
|
||||
flowStore.updateNodeToRunning(flowGraph.id(), node.id());
|
||||
|
||||
var runnerClazz = nodeRunnerClass.get(node.type());
|
||||
var runner = runnerClazz.getDeclaredConstructor().newInstance();
|
||||
runner.setNodeId(node.id());
|
||||
runner.setContext(context);
|
||||
|
||||
// 处理子流程节点的逻辑
|
||||
if (runner instanceof FlowNodeSubflowRunner subflowRunner) {
|
||||
var subflowNodes = flowGraph.nodes().select(n -> StrUtil.equals(n.parentId(), node.id()));
|
||||
var subGraph = new FlowGraph(IdUtil.fastUUID(), subflowNodes, flowGraph.edges());
|
||||
subflowRunner.setSubGraph(subGraph);
|
||||
}
|
||||
|
||||
runner.run();
|
||||
|
||||
// 处理选择节点的逻辑
|
||||
if (runner instanceof FlowNodeOptionalRunner) {
|
||||
var targetPoint = ((FlowNodeOptionalRunner) runner).getTargetPoint();
|
||||
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||
if (StrUtil.equals(targetPoint, edge.sourcePoint())) {
|
||||
flowStore.updateEdgeToExecute(flowGraph.id(), edge.id());
|
||||
} else {
|
||||
flowStore.updateEdgeToSkip(flowGraph.id(), edge.id());
|
||||
}
|
||||
executionQueue.offer(nodeMap.get(edge.target()));
|
||||
}
|
||||
} else {
|
||||
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||
flowStore.updateEdgeToExecute(flowGraph.id(), edge.id());
|
||||
executionQueue.offer(nodeMap.get(edge.target()));
|
||||
}
|
||||
}
|
||||
|
||||
flowStore.updateNodeToFinished(flowGraph.id(), node.id());
|
||||
}
|
||||
// 所有入的边都是跳过,当前节点就跳过
|
||||
else {
|
||||
flowStore.updateNodeToSkipped(flowGraph.id(), node.id());
|
||||
|
||||
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||
flowStore.updateEdgeToSkip(flowGraph.id(), edge.id());
|
||||
executionQueue.offer(nodeMap.get(edge.target()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250711
|
||||
*/
|
||||
@Slf4j
|
||||
public class FlowHelper {
|
||||
private static final TemplateEngine TEMPLATE_ENGINE = TemplateUtil.createEngine();
|
||||
|
||||
public static ImmutableMap<String, Object> generateInputVariablesMap(String nodeId, FlowContext context) {
|
||||
var variableMap = Maps.mutable.<String, Object>empty();
|
||||
var currentNodeData = context.get(nodeId);
|
||||
if (currentNodeData.containsKey("inputs")) {
|
||||
var inputsMap = (Map<String, Map<String, String>>) currentNodeData.get("inputs");
|
||||
for (String variableName : inputsMap.keySet()) {
|
||||
var expression = inputsMap.get(variableName).get("variable");
|
||||
var targetVariable = generateVariable(expression, context);
|
||||
if (ObjectUtil.isNotNull(targetVariable)) {
|
||||
variableMap.put(variableName, targetVariable);
|
||||
}
|
||||
}
|
||||
}
|
||||
return variableMap.toImmutable();
|
||||
}
|
||||
|
||||
public static Object generateVariable(String expression, FlowContext context) {
|
||||
if (StrUtil.contains(expression, ".")) {
|
||||
var splits = StrUtil.splitTrim(expression, ".", 2);
|
||||
var targetNodeId = splits.get(0);
|
||||
var targetVariableName = splits.get(1);
|
||||
if (!context.getData().containsKey(targetNodeId)) {
|
||||
throw new RuntimeException(StrUtil.format("Target node id not found: {}", targetNodeId));
|
||||
}
|
||||
var targetNodeData = context.getData().get(targetNodeId);
|
||||
if (!targetNodeData.containsKey(targetVariableName)) {
|
||||
throw new RuntimeException(StrUtil.format("Target node variable not found: {}.{}", targetNodeId, targetVariableName));
|
||||
}
|
||||
return targetNodeData.get(targetVariableName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String renderTemplateText(String templateText, Map<?, ?> data) {
|
||||
var template = TEMPLATE_ENGINE.getTemplate(templateText);
|
||||
return template.render(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public abstract class FlowNodeOptionalRunner extends FlowNodeRunner {
|
||||
@Getter
|
||||
private String targetPoint;
|
||||
|
||||
public abstract String runOptional();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.targetPoint = runOptional();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||
import lombok.Getter;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
|
||||
public abstract class FlowNodeRunner {
|
||||
@Getter
|
||||
private String nodeId;
|
||||
@Getter
|
||||
private FlowContext context;
|
||||
|
||||
public abstract void run();
|
||||
|
||||
void setNodeId(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
void setContext(FlowContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
protected MutableMap<String, Object> getData() {
|
||||
return context.get(nodeId);
|
||||
}
|
||||
|
||||
protected <T> T getData(String key) {
|
||||
var data = context.get(nodeId);
|
||||
return (T) data.get(key);
|
||||
}
|
||||
|
||||
protected <T> void setData(String key, T value) {
|
||||
var data = context.get(nodeId);
|
||||
data.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 包含子流程的流程
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
public abstract class FlowNodeSubflowRunner extends FlowNodeRunner {
|
||||
@Getter
|
||||
@Setter
|
||||
private FlowGraph subGraph;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
|
||||
@Data
|
||||
public class FlowContext {
|
||||
private MutableMap<String, MutableMap<String, Object>> data = Maps.mutable.<String, MutableMap<String, Object>>empty().asSynchronized();
|
||||
|
||||
public MutableMap<String, Object> get(String key) {
|
||||
if (!data.containsKey(key)) {
|
||||
data.put(key, Maps.mutable.<String, Object>empty().asSynchronized());
|
||||
}
|
||||
return data.get(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 流程图中的边
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250630
|
||||
*/
|
||||
public record FlowEdge(
|
||||
String id,
|
||||
String source,
|
||||
String target,
|
||||
@JsonProperty("sourceHandle")
|
||||
String sourcePoint,
|
||||
@JsonProperty("targetHandle")
|
||||
String targetPoint
|
||||
) {
|
||||
public enum Status {
|
||||
INITIAL, EXECUTE, SKIP
|
||||
}
|
||||
|
||||
public record State(
|
||||
String id,
|
||||
Status status,
|
||||
LocalDateTime startingTime,
|
||||
LocalDateTime finishedTime
|
||||
) {
|
||||
public State(String edgeId) {
|
||||
this(edgeId, Status.INITIAL, LocalDateTime.now(), null);
|
||||
}
|
||||
|
||||
public State(String edgeId, Status status) {
|
||||
this(edgeId, status, LocalDateTime.now(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
|
||||
/**
|
||||
* 流程图
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250630
|
||||
*/
|
||||
public record FlowGraph(
|
||||
String id,
|
||||
ImmutableSet<FlowNode> nodes,
|
||||
ImmutableSet<FlowEdge> edges
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 流程图中的节点
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250630
|
||||
*/
|
||||
public record FlowNode(
|
||||
String id,
|
||||
String type,
|
||||
String parentId
|
||||
) {
|
||||
public enum Status {
|
||||
INITIAL, RUNNING, FINISHED, SKIPPED
|
||||
}
|
||||
|
||||
public record State(
|
||||
String id,
|
||||
Status status,
|
||||
LocalDateTime startingTime,
|
||||
LocalDateTime finishedTime
|
||||
) {
|
||||
public State(String nodeId) {
|
||||
this(nodeId, Status.INITIAL, LocalDateTime.now(), null);
|
||||
}
|
||||
|
||||
public State(String nodeId, Status status) {
|
||||
this(nodeId, status, LocalDateTime.now(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.CodeExecutor;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.JavaScriptCodeExecutor;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.PythonCodeExecutor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
@Slf4j
|
||||
public class CodeNode extends FlowNodeRunner {
|
||||
@Override
|
||||
public void run() {
|
||||
var mapper = SpringBeanGetter.getBean(ObjectMapper.class);
|
||||
var inputVariablesMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||
var type = this.<String>getData("type");
|
||||
var script = this.<String>getData("content");
|
||||
CodeExecutor executor = switch (type) {
|
||||
case "javascript" -> new JavaScriptCodeExecutor(mapper);
|
||||
case "python" -> new PythonCodeExecutor(mapper);
|
||||
default -> null;
|
||||
};
|
||||
if (ObjectUtil.isNull(executor)) {
|
||||
throw new RuntimeException(StrUtil.format("Unsupported type: {}", type));
|
||||
}
|
||||
var result = executor.execute(script, inputVariablesMap);
|
||||
result.forEachKeyValue(this::setData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250711
|
||||
*/
|
||||
@Slf4j
|
||||
public class InputNode extends FlowNodeRunner {
|
||||
public static final String KEY = "flow_inputs";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
var inputData = getContext().getData().get(KEY);
|
||||
var inputs = this.<Map<String, Object>>getData("inputs");
|
||||
for (String variable : inputs.keySet()) {
|
||||
if (inputData.containsKey(variable)) {
|
||||
setData(variable, inputData.get(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250711
|
||||
*/
|
||||
@Slf4j
|
||||
public class LlmNode extends FlowNodeRunner {
|
||||
@Override
|
||||
public void run() {
|
||||
var variableMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||
var sourcePrompt = (String) getData("systemPrompt");
|
||||
if (StrUtil.isNotBlank(sourcePrompt)) {
|
||||
var prompt = FlowHelper.renderTemplateText(sourcePrompt, variableMap.toMap());
|
||||
var builder = SpringBeanGetter.getBean("chat", ChatClient.Builder.class);
|
||||
var client = builder.build();
|
||||
var content = client.prompt()
|
||||
.user(prompt)
|
||||
.call()
|
||||
.content();
|
||||
setData("text", content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeSubflowRunner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 循环节点
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
@Slf4j
|
||||
public class LoopNode extends FlowNodeSubflowRunner {
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("{}", getSubGraph());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250711
|
||||
*/
|
||||
@Slf4j
|
||||
public class OutputNode extends FlowNodeRunner {
|
||||
private static final String KEY = "flow_outputs";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
var variableMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||
getContext().getData().put(KEY, variableMap.toMap());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeOptionalRunner;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Slf4j
|
||||
public class SwitchNode extends FlowNodeOptionalRunner {
|
||||
@Override
|
||||
public String runOptional() {
|
||||
var conditions = this.<List<Map<String, Object>>>getData("conditions");
|
||||
for (Map<String, Object> item : conditions) {
|
||||
var condition = (Map<String, Object>) item.getOrDefault("condition", Map.of());
|
||||
var id = (String) condition.getOrDefault("id", "");
|
||||
var conjunction = (String) condition.getOrDefault("conjunction", "and");
|
||||
var conditionChildren = ((List<Map<String, Object>>) condition.getOrDefault("children", List.<Map<String, Object>>of()));
|
||||
if (
|
||||
StrUtil.equals(conjunction, "and")
|
||||
&& conditionChildren.stream().allMatch(this::check)
|
||||
) {
|
||||
return id;
|
||||
} else if (
|
||||
StrUtil.equals(conjunction, "or")
|
||||
&& conditionChildren.stream().anyMatch(this::check)
|
||||
) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private Boolean check(Map<String, Object> condition) {
|
||||
var leftVariable = (String) BeanUtil.getProperty(condition, "left.field");
|
||||
var left = FlowHelper.generateVariable(leftVariable, getContext());
|
||||
var operator = (String) condition.get("op");
|
||||
var right = condition.get("right");
|
||||
if (left instanceof CharSequence || left instanceof Boolean) {
|
||||
String source = StrUtil.toStringOrNull(left);
|
||||
String target = StrUtil.toStringOrNull(right);
|
||||
return switch (operator) {
|
||||
case "equal" -> StrUtil.equals(source, target);
|
||||
case "not_equal" -> !StrUtil.equals(source, target);
|
||||
case "is_empty" -> StrUtil.isBlank(source);
|
||||
case "is_not_empty" -> StrUtil.isNotBlank(source);
|
||||
case "like" -> StrUtil.contains(source, target);
|
||||
case "not_like" -> !StrUtil.contains(source, target);
|
||||
case "starts_with" -> StrUtil.startWith(source, target);
|
||||
case "ends_with" -> StrUtil.endWith(source, target);
|
||||
default -> false;
|
||||
};
|
||||
} else if (left instanceof Number source) {
|
||||
var sourceNumber = new BigDecimal(StrUtil.toString(source));
|
||||
var targetNumber = new BigDecimal(StrUtil.toString(right));
|
||||
return switch (operator) {
|
||||
case "equal" -> NumberUtil.equals(sourceNumber, targetNumber);
|
||||
case "not_equal" -> !NumberUtil.equals(sourceNumber, targetNumber);
|
||||
case "greater" -> NumberUtil.isGreater(sourceNumber, targetNumber);
|
||||
case "greater_equal" -> NumberUtil.isGreaterOrEqual(sourceNumber, targetNumber);
|
||||
case "less" -> NumberUtil.isLess(sourceNumber, targetNumber);
|
||||
case "less_equal" -> NumberUtil.isLessOrEqual(sourceNumber, targetNumber);
|
||||
default -> false;
|
||||
};
|
||||
} else if (left instanceof Collection<?> source) {
|
||||
return switch (operator) {
|
||||
case "is_empty" -> CollectionUtil.isEmpty(source);
|
||||
case "is_not_empty" -> CollectionUtil.isNotEmpty(source);
|
||||
case "contain" -> CollectionUtil.safeContains(source, right);
|
||||
case "not_contain" -> !CollectionUtil.safeContains(source, right);
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
public interface CodeExecutor {
|
||||
ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.Engine;
|
||||
import org.graalvm.polyglot.Source;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
@Slf4j
|
||||
public class JavaScriptCodeExecutor implements CodeExecutor {
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public JavaScriptCodeExecutor(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap) {
|
||||
if (StrUtil.isBlank(script)) {
|
||||
return Maps.immutable.empty();
|
||||
}
|
||||
try (var engin = Engine.create()) {
|
||||
try (
|
||||
var context = Context.newBuilder()
|
||||
.allowAllAccess(true)
|
||||
.engine(engin)
|
||||
.build()
|
||||
) {
|
||||
var bindings = context.getBindings("js");
|
||||
bindings.putMember("context", inputVariablesMap);
|
||||
var result = context.eval(
|
||||
Source.create(
|
||||
"js",
|
||||
"""
|
||||
function process() {
|
||||
%s
|
||||
}
|
||||
var result = process();
|
||||
JSON.stringify(result? result: {})
|
||||
""".formatted(script)
|
||||
)
|
||||
);
|
||||
return mapper.readValue(result.asString(), new TypeReference<>() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.python.core.PySystemState;
|
||||
import org.python.util.PythonInterpreter;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250718
|
||||
*/
|
||||
@Slf4j
|
||||
public class PythonCodeExecutor implements CodeExecutor {
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public PythonCodeExecutor(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap) {
|
||||
try (var systemState = new PySystemState()) {
|
||||
systemState.setdefaultencoding("UTF-8");
|
||||
var interpreter = new PythonInterpreter(null, systemState);
|
||||
script = Arrays.stream(script.split("\n"))
|
||||
.map(line -> " " + line)
|
||||
.collect(Collectors.joining("\n"));
|
||||
interpreter.set("context", inputVariablesMap);
|
||||
var pythonScript = interpreter.compile(
|
||||
"""
|
||||
import json
|
||||
|
||||
def process():
|
||||
%s
|
||||
|
||||
result = json.dumps(process())
|
||||
""".formatted(script)
|
||||
);
|
||||
interpreter.exec(pythonScript);
|
||||
var result = interpreter.get("result");
|
||||
return mapper.readValue((String) result.__tojava__(String.class), new TypeReference<>() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.store;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||
|
||||
/**
|
||||
* 存储状态
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250701
|
||||
*/
|
||||
public interface FlowStore {
|
||||
void init(FlowGraph flowGraph);
|
||||
|
||||
void updateNodeToRunning(String graphId, String nodeId);
|
||||
|
||||
void updateNodeToSkipped(String graphId, String nodeId);
|
||||
|
||||
void updateNodeToFinished(String graphId, String nodeId);
|
||||
|
||||
void updateEdgeToExecute(String graphId, String edgeId);
|
||||
|
||||
void updateEdgeToSkip(String graphId, String edgeId);
|
||||
|
||||
boolean checkNodeStatus(String graphId, String nodeId, FlowNode.Status... statuses);
|
||||
|
||||
boolean checkEdgeStatus(String graphId, String edgeId, FlowEdge.Status... statuses);
|
||||
|
||||
void print();
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.engine.store;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
|
||||
/**
|
||||
* 基于内存的流程状态存储
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250701
|
||||
*/
|
||||
@Slf4j
|
||||
public class InMemoryFlowStore implements FlowStore {
|
||||
private static final MutableMap<String, FlowNode.State> flowNodeStateMap = Maps.mutable.<String, FlowNode.State>empty().asSynchronized();
|
||||
private static final MutableMap<String, FlowEdge.State> flowEdgeStateMap = Maps.mutable.<String, FlowEdge.State>empty().asSynchronized();
|
||||
|
||||
private String multiKey(String... key) {
|
||||
return String.join("-", key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FlowGraph flowGraph) {
|
||||
for (FlowNode node : flowGraph.nodes()) {
|
||||
flowNodeStateMap.put(multiKey(flowGraph.id(), node.id()), new FlowNode.State(node.id()));
|
||||
}
|
||||
for (FlowEdge edge : flowGraph.edges()) {
|
||||
flowEdgeStateMap.put(multiKey(flowGraph.id(), edge.id()), new FlowEdge.State(edge.id()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNodeToRunning(String graphId, String nodeId) {
|
||||
flowNodeStateMap.updateValue(
|
||||
multiKey(graphId, nodeId),
|
||||
() -> new FlowNode.State(nodeId, FlowNode.Status.RUNNING),
|
||||
old -> new FlowNode.State(nodeId, FlowNode.Status.RUNNING, old.startingTime(), old.finishedTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNodeToSkipped(String graphId, String nodeId) {
|
||||
flowNodeStateMap.updateValue(
|
||||
multiKey(graphId, nodeId),
|
||||
() -> new FlowNode.State(nodeId, FlowNode.Status.SKIPPED),
|
||||
old -> new FlowNode.State(nodeId, FlowNode.Status.SKIPPED, old.startingTime(), old.finishedTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNodeToFinished(String graphId, String nodeId) {
|
||||
flowNodeStateMap.updateValue(
|
||||
multiKey(graphId, nodeId),
|
||||
() -> new FlowNode.State(nodeId, FlowNode.Status.FINISHED),
|
||||
old -> new FlowNode.State(nodeId, FlowNode.Status.FINISHED, old.startingTime(), old.finishedTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEdgeToExecute(String graphId, String edgeId) {
|
||||
flowEdgeStateMap.updateValue(
|
||||
multiKey(graphId, edgeId),
|
||||
() -> new FlowEdge.State(edgeId, FlowEdge.Status.EXECUTE),
|
||||
old -> new FlowEdge.State(edgeId, FlowEdge.Status.EXECUTE, old.startingTime(), old.finishedTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEdgeToSkip(String graphId, String edgeId) {
|
||||
flowEdgeStateMap.updateValue(
|
||||
multiKey(graphId, edgeId),
|
||||
() -> new FlowEdge.State(edgeId, FlowEdge.Status.SKIP),
|
||||
old -> new FlowEdge.State(edgeId, FlowEdge.Status.SKIP, old.startingTime(), old.finishedTime())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNodeStatus(String graphId, String nodeId, FlowNode.Status... statuses) {
|
||||
String key = multiKey(graphId, nodeId);
|
||||
if (flowNodeStateMap.containsKey(key)) {
|
||||
return ArrayUtil.contains(statuses, flowNodeStateMap.get(key).status());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEdgeStatus(String graphId, String edgeId, FlowEdge.Status... statuses) {
|
||||
String key = multiKey(graphId, edgeId);
|
||||
if (flowEdgeStateMap.containsKey(key)) {
|
||||
return ArrayUtil.contains(statuses, flowEdgeStateMap.get(key).status());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print() {
|
||||
log.info("====== Flow Store ======");
|
||||
log.info("====== Flow Node ======");
|
||||
flowNodeStateMap.forEachKeyValue((key, value) -> log.info("{}: {}", key, value.status()));
|
||||
log.info("====== Flow Edge ======");
|
||||
flowEdgeStateMap.forEachKeyValue((key, value) -> log.info("{}: {}", key, value.status()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_file")
|
||||
@NoArgsConstructor
|
||||
@Comment("记录上传的文件存储信息")
|
||||
public class DataFile extends SimpleEntity {
|
||||
@Comment("文件名称")
|
||||
private String filename;
|
||||
@Comment("文件大小,单位是byte")
|
||||
private Long size;
|
||||
@Comment("文件的md5编码,用于校验文件的完整性")
|
||||
private String md5;
|
||||
@Comment("文件在主机上存储的实际路径")
|
||||
private String path;
|
||||
@Comment("文件类型,通常记录的是文件的后缀名")
|
||||
private String type;
|
||||
|
||||
public DataFile(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,58 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Data
|
||||
public class Feedback {
|
||||
private Long id;
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_feedback")
|
||||
@NamedEntityGraph(name = "feedback.detail", attributeNodes = {
|
||||
@NamedAttributeNode("pictures")
|
||||
})
|
||||
@Comment("报障信息记录")
|
||||
public class Feedback extends SimpleEntity {
|
||||
@Comment("原始报障说明")
|
||||
@Column(nullable = false, columnDefinition = "longtext")
|
||||
private String source;
|
||||
private String analysisShort;
|
||||
@Comment("报障相关截图")
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(catalog = Constants.DATABASE_NAME, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private Set<DataFile> pictures;
|
||||
@Comment("AI的分析结果")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String analysis;
|
||||
private ImmutableList<String> pictureIds;
|
||||
private Status status;
|
||||
private Long createdTime;
|
||||
private Long modifiedTime;
|
||||
@Comment("AI的解决方案")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String conclusion;
|
||||
@Comment("报障处理状态")
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status = Status.ANALYSIS_PROCESSING;
|
||||
|
||||
public enum Status {
|
||||
ANALYSIS_PROCESSING,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_flow_task")
|
||||
@Comment("流程任务记录")
|
||||
public class FlowTask extends SimpleEntity {
|
||||
// 每个任务对应的模板都是唯一,避免模板修改之后任务的状态、运行等状态都无法展示
|
||||
// 不管允许不允许任务重跑,这些都要保存下来
|
||||
@Comment("任务对应的模板名称")
|
||||
@Column(nullable = false)
|
||||
private String templateName;
|
||||
@Comment("任务对应的模板功能、内容说明")
|
||||
private String templateDescription;
|
||||
@Comment("任务对应的模板入参Schema")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String templateInputSchema;
|
||||
@Comment("任务对应的模板前端流程图数据")
|
||||
@Column(nullable = false, columnDefinition = "longtext")
|
||||
private String templateFlowGraph = "{}";
|
||||
|
||||
@Comment("任务注释,用于额外说明")
|
||||
@Column(columnDefinition = "text")
|
||||
private String comment;
|
||||
@Comment("任务输入")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String input;
|
||||
@Comment("任务运行状态")
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status = Status.RUNNING;
|
||||
@Comment("任务运行产生的报错")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String error;
|
||||
@Comment("任务运行结果")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String result;
|
||||
|
||||
public enum Status {
|
||||
RUNNING,
|
||||
ERROR,
|
||||
FINISHED,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_flow_task_template")
|
||||
@Comment("流程任务模板")
|
||||
public class FlowTaskTemplate extends SimpleEntity {
|
||||
@Comment("模板名称")
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@Comment("模板功能、内容说明")
|
||||
private String description;
|
||||
@Comment("模板入参Schema")
|
||||
@Column(columnDefinition = "longtext")
|
||||
private String inputSchema;
|
||||
@Comment("前端流程图数据")
|
||||
@Column(nullable = false, columnDefinition = "longtext")
|
||||
private String flowGraph = "{}";
|
||||
}
|
||||
@@ -1,16 +1,53 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250527
|
||||
*/
|
||||
@Data
|
||||
public class Group {
|
||||
private Long id;
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_group")
|
||||
@Comment("知识库内的逻辑分组,比如一个文件是一个分组或一次上传的所有文本是一个分组,可以自由使用而不是限于文件范畴")
|
||||
public class Group extends SimpleEntity {
|
||||
@Comment("分组名称")
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String status;
|
||||
private Long createdTime;
|
||||
private Long modifiedTime;
|
||||
@Comment("分组处理状态")
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status = Status.RUNNING;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private Knowledge knowledge;
|
||||
|
||||
public enum Status {
|
||||
RUNNING,
|
||||
FINISHED,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,58 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250522
|
||||
*/
|
||||
@Data
|
||||
public class Knowledge {
|
||||
private Long id;
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_knowledge")
|
||||
@Comment("知识库")
|
||||
public class Knowledge extends SimpleEntity {
|
||||
@Comment("知识库对应的向量库名")
|
||||
@Column(nullable = false)
|
||||
private Long vectorSourceId;
|
||||
@Comment("知识库名称")
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String strategy;
|
||||
private Long createdTime;
|
||||
private Long modifiedTime;
|
||||
@Comment("知识库说明")
|
||||
@Column(nullable = false, columnDefinition = "longtext")
|
||||
private String description;
|
||||
@Comment("知识库策略")
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Strategy strategy = Strategy.Cosine;
|
||||
|
||||
@Comment("知识库下包含的分组")
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "knowledge", cascade = CascadeType.ALL)
|
||||
@ToString.Exclude
|
||||
private Set<Group> groups;
|
||||
|
||||
public enum Strategy {
|
||||
Cosine,
|
||||
Euclid,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||
import lombok.Data;
|
||||
import org.eclipse.collections.api.map.MutableMap;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
|
||||
@Data
|
||||
public class FlowGraphVo {
|
||||
private ImmutableSet<FlowNode> nodes;
|
||||
private ImmutableSet<FlowEdge> edges;
|
||||
private MutableMap<String, MutableMap<String, Object>> data;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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 strategy;
|
||||
private Long size;
|
||||
private Long points;
|
||||
private Long segments;
|
||||
private String status;
|
||||
private Long createdTime;
|
||||
private Long modifiedTime;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.DataFile;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DataFileRepository extends SimpleRepository<DataFile, Long> {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface FeedbackRepository extends SimpleRepository<Feedback, Long> {
|
||||
@EntityGraph(value = "feedback.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
@Override
|
||||
List<Feedback> findAll(Specification<Feedback> specification);
|
||||
|
||||
@EntityGraph(value = "feedback.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
@Override
|
||||
List<Feedback> findAll(Specification<Feedback> specification, Sort sort);
|
||||
|
||||
@EntityGraph(value = "feedback.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
@Override
|
||||
Optional<Feedback> findOne(Specification<Feedback> specification);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface FlowTaskRepository extends SimpleRepository<FlowTask, Long> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface FlowTaskTemplateRepository extends SimpleRepository<FlowTaskTemplate, Long> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface GroupRepository extends SimpleRepository<Group, Long> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface KnowledgeRepository extends SimpleRepository<Knowledge, Long> {
|
||||
Boolean existsKnowledgeByName(String name);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.service;
|
||||
|
||||
import club.kingon.sql.builder.SqlBuilder;
|
||||
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.springframework.jdbc.core.JdbcTemplate;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.DataFile;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.DataFileRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -12,65 +13,36 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250527
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataFileService {
|
||||
private static final String DATA_FILE_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_file";
|
||||
private final DataFileRepository dataFileRepository;
|
||||
|
||||
private final JdbcTemplate template;
|
||||
|
||||
public DataFileService(JdbcTemplate template) {
|
||||
this.template = template;
|
||||
public DataFileService(DataFileRepository dataFileRepository) {
|
||||
this.dataFileRepository = dataFileRepository;
|
||||
}
|
||||
|
||||
public DataFileVO downloadFile(Long id) {
|
||||
return template.queryForObject(
|
||||
SqlBuilder.select("id", "filename", "size", "md5", "path", "type")
|
||||
.from(DATA_FILE_TABLE_NAME)
|
||||
.whereEq("id", "?")
|
||||
.precompileSql(),
|
||||
(rs, row) -> {
|
||||
DataFileVO vo = new DataFileVO();
|
||||
vo.setId(String.valueOf(rs.getLong(1)));
|
||||
vo.setFilename(rs.getString(2));
|
||||
vo.setSize(rs.getLong(3));
|
||||
vo.setMd5(rs.getString(4));
|
||||
vo.setPath(rs.getString(5));
|
||||
vo.setType(rs.getString(6));
|
||||
return vo;
|
||||
},
|
||||
id
|
||||
);
|
||||
public DataFile downloadFile(Long id) {
|
||||
return dataFileRepository.findById(id).orElseThrow(() -> new RuntimeException(StrUtil.format("Datafile not exists: {}", id)));
|
||||
}
|
||||
|
||||
public ImmutableSet<DataFile> downloadFile(ImmutableSet<Long> ids) {
|
||||
return Sets.immutable.ofAll(dataFileRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long initialDataFile(String filename) {
|
||||
long id = SnowflakeId.next();
|
||||
template.update(
|
||||
SqlBuilder.insertInto(DATA_FILE_TABLE_NAME, "id", "filename")
|
||||
.values()
|
||||
.addValue("?", "?")
|
||||
.precompileSql(),
|
||||
id,
|
||||
filename
|
||||
);
|
||||
return id;
|
||||
DataFile dataFile = dataFileRepository.save(new DataFile(filename));
|
||||
return dataFile.getId();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDataFile(Long id, String path, Long size, String md5, String type) {
|
||||
template.update(
|
||||
SqlBuilder.update(DATA_FILE_TABLE_NAME)
|
||||
.set("size", "?")
|
||||
.addSet("md5", "?")
|
||||
.addSet("path", "?")
|
||||
.addSet("type", "?")
|
||||
.whereEq("id", "?")
|
||||
.precompileSql(),
|
||||
size,
|
||||
md5,
|
||||
path,
|
||||
type,
|
||||
id
|
||||
);
|
||||
DataFile dataFile = downloadFile(id);
|
||||
dataFile.setPath(path);
|
||||
dataFile.setSize(size);
|
||||
dataFile.setMd5(md5);
|
||||
dataFile.setType(type);
|
||||
dataFileRepository.save(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ 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.web.entity.DataFile;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
|
||||
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;
|
||||
@@ -54,16 +55,19 @@ public class EmbeddingService {
|
||||
return Lists.immutable.ofAll(context.getDocuments());
|
||||
}
|
||||
|
||||
public ImmutableList<Document> preview(String mode, ImmutableList<String> ids) {
|
||||
DataFileVO vo = dataFileService.downloadFile(Long.parseLong(ids.get(0)));
|
||||
String content = FileUtil.readString(vo.getPath(), StandardCharsets.UTF_8);
|
||||
public ImmutableList<Document> preview(String mode, ImmutableList<Long> ids) {
|
||||
DataFile dataFile = dataFileService.downloadFile(ids.get(0));
|
||||
String content = FileUtil.readString(dataFile.getPath(), StandardCharsets.UTF_8);
|
||||
return preview(mode, content);
|
||||
}
|
||||
|
||||
public void submit(Long id, String mode, String content) {
|
||||
executors.submit(() -> {
|
||||
Knowledge knowledge = knowledgeBaseService.get(id);
|
||||
Long groupId = groupService.add(knowledge.getId(), StrUtil.format("文本-{}", IdUtil.nanoId(10)));
|
||||
Knowledge knowledge = knowledgeBaseService.detailOrThrow(id);
|
||||
Group group = new Group();
|
||||
group.setName(StrUtil.format("文本-{}", IdUtil.nanoId(10)));
|
||||
group.setKnowledge(knowledge);
|
||||
Long groupId = groupService.save(group);
|
||||
EmbeddingContext context = EmbeddingContext.builder()
|
||||
.vectorSourceId(knowledge.getVectorSourceId())
|
||||
.groupId(groupId)
|
||||
@@ -77,23 +81,26 @@ public class EmbeddingService {
|
||||
});
|
||||
}
|
||||
|
||||
public void submit(Long id, String mode, ImmutableList<String> ids) {
|
||||
public void submit(Long id, String mode, ImmutableList<Long> ids) {
|
||||
executors.submit(() -> {
|
||||
Knowledge knowledge = knowledgeBaseService.get(id);
|
||||
List<Pair<Long, DataFileVO>> vos = Lists.mutable.empty();
|
||||
for (String fileId : ids) {
|
||||
DataFileVO vo = dataFileService.downloadFile(Long.parseLong(fileId));
|
||||
Long groupId = groupService.add(id, vo.getFilename());
|
||||
vos.add(Pair.of(groupId, vo));
|
||||
Knowledge knowledge = knowledgeBaseService.detailOrThrow(id);
|
||||
List<Pair<Long, DataFile>> dataFiles = Lists.mutable.empty();
|
||||
for (Long fileId : ids) {
|
||||
DataFile dataFile = dataFileService.downloadFile(fileId);
|
||||
Group group = new Group();
|
||||
group.setName(dataFile.getFilename());
|
||||
group.setKnowledge(knowledge);
|
||||
Long groupId = groupService.save(group);
|
||||
dataFiles.add(Pair.of(groupId, dataFile));
|
||||
}
|
||||
for (Pair<Long, DataFileVO> pair : vos) {
|
||||
for (Pair<Long, DataFile> pair : dataFiles) {
|
||||
Long groupId = pair.getKey();
|
||||
DataFileVO vo = pair.getValue();
|
||||
DataFile dataFile = pair.getValue();
|
||||
EmbeddingContext context = EmbeddingContext.builder()
|
||||
.vectorSourceId(knowledge.getVectorSourceId())
|
||||
.groupId(groupId)
|
||||
.file(vo.getPath())
|
||||
.fileFormat(vo.getFilename())
|
||||
.file(dataFile.getPath())
|
||||
.fileFormat(dataFile.getFilename())
|
||||
.config(EmbeddingContext.Config.builder()
|
||||
.splitStrategy(EmbeddingContext.Config.SplitStrategy.valueOf(mode))
|
||||
.build())
|
||||
@@ -106,12 +113,15 @@ public class EmbeddingService {
|
||||
|
||||
public void submitDirectly(Long id, String name, ImmutableList<String> contents) {
|
||||
executors.submit(() -> {
|
||||
Knowledge knowledge = knowledgeBaseService.get(id);
|
||||
Knowledge knowledge = knowledgeBaseService.detailOrThrow(id);
|
||||
String groupName = name;
|
||||
if (StrUtil.isBlank(groupName)) {
|
||||
groupName = StrUtil.format("外部-{}", IdUtil.nanoId(10));
|
||||
}
|
||||
Long groupId = groupService.add(knowledge.getId(), groupName);
|
||||
Group group = new Group();
|
||||
group.setName(groupName);
|
||||
group.setKnowledge(knowledge);
|
||||
Long groupId = groupService.save(group);
|
||||
EmbeddingContext context = EmbeddingContext.builder()
|
||||
.vectorSourceId(knowledge.getVectorSourceId())
|
||||
.groupId(groupId)
|
||||
|
||||
@@ -1,81 +1,65 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.service.feedback;
|
||||
|
||||
import club.kingon.sql.builder.SqlBuilder;
|
||||
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.base.service.SimpleServiceSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import java.util.stream.Collectors;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback_;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.context.FeedbackContext;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.FeedbackRepository;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import java.util.List;
|
||||
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.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";
|
||||
private static final RowMapper<Feedback> feedbackMapper = (rs, row) -> {
|
||||
Feedback feedback = new Feedback();
|
||||
feedback.setId(rs.getLong(1));
|
||||
feedback.setSource(rs.getString(2));
|
||||
feedback.setAnalysisShort(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), ","))
|
||||
);
|
||||
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;
|
||||
public class FeedbackService extends SimpleServiceSupport<Feedback> {
|
||||
private final FlowExecutor executor;
|
||||
|
||||
public FeedbackService(JdbcTemplate template) {
|
||||
this.template = template;
|
||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||
public FeedbackService(FeedbackRepository feedbackRepository, FlowExecutor executor) {
|
||||
super(feedbackRepository);
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@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(",")
|
||||
);
|
||||
}
|
||||
|
||||
public ImmutableList<Feedback> list() {
|
||||
return template.query(
|
||||
SqlBuilder.select("id", "source", "analysis_short", "analysis", "pictures", "status", "created_time", "modified_time")
|
||||
.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)
|
||||
// @Scheduled(initialDelay = 1, fixedDelay = 1, timeUnit = TimeUnit.MINUTES)
|
||||
public void analysis() {
|
||||
List<Feedback> feedbacks = repository.findAll(
|
||||
builder -> builder
|
||||
.andEquals(Feedback_.STATUS, Feedback.Status.ANALYSIS_PROCESSING)
|
||||
.build()
|
||||
);
|
||||
for (Feedback feedback : feedbacks) {
|
||||
FeedbackContext context = new FeedbackContext();
|
||||
context.setFeedback(feedback);
|
||||
executor.execute2Resp("feedback_analysis", null, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateAnalysis(Long id, String analysis) {
|
||||
Feedback feedback = detailOrThrow(id);
|
||||
feedback.setAnalysis(analysis);
|
||||
repository.save(feedback);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateConclusion(Long id, String conclusion) {
|
||||
Feedback feedback = detailOrThrow(id);
|
||||
feedback.setConclusion(conclusion);
|
||||
feedback.setStatus(Feedback.Status.FINISHED);
|
||||
repository.save(feedback);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStatus(Long id, Feedback.Status status) {
|
||||
Feedback feedback = detailOrThrow(id);
|
||||
feedback.setStatus(status);
|
||||
repository.save(feedback);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void reanalysis(Long id) {
|
||||
updateStatus(id, Feedback.Status.ANALYSIS_PROCESSING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
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 com.lanyuanxiaoyao.service.ai.core.configuration.SnowflakeId;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.GroupRepository;
|
||||
import io.qdrant.client.ConditionFactory;
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.grpc.Points;
|
||||
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 lombok.SneakyThrows;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -24,109 +17,34 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @version 20250522
|
||||
*/
|
||||
@Service
|
||||
public class GroupService {
|
||||
public static final String GROUP_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_group";
|
||||
private static final RowMapper<Group> groupMapper = (rs, row) -> {
|
||||
Group vo = new Group();
|
||||
vo.setId(rs.getLong(1));
|
||||
vo.setName(rs.getString(2));
|
||||
vo.setStatus(rs.getString(3));
|
||||
vo.setCreatedTime(rs.getTimestamp(4).getTime());
|
||||
vo.setModifiedTime(rs.getTimestamp(5).getTime());
|
||||
return vo;
|
||||
};
|
||||
|
||||
private final JdbcTemplate template;
|
||||
public class GroupService extends SimpleServiceSupport<Group> {
|
||||
private final QdrantClient client;
|
||||
|
||||
public GroupService(JdbcTemplate template, VectorStore vectorStore) {
|
||||
this.template = template;
|
||||
public GroupService(GroupRepository groupRepository, VectorStore vectorStore) {
|
||||
super(groupRepository);
|
||||
this.client = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
|
||||
}
|
||||
|
||||
public Group get(Long id) {
|
||||
return template.queryForObject(
|
||||
SqlBuilder.select("id", "name", "status", "created_time", "modified_time")
|
||||
.from(GROUP_TABLE_NAME)
|
||||
.whereEq("id", id)
|
||||
.orderByDesc("created_time")
|
||||
.build(),
|
||||
groupMapper
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long add(Long knowledgeId, String name) {
|
||||
long id = SnowflakeId.next();
|
||||
template.update(
|
||||
SqlBuilder.insertInto(GROUP_TABLE_NAME, "id", "knowledge_id", "name", "status")
|
||||
.values()
|
||||
.addValue("?", "?", "?", "?")
|
||||
.precompileSql(),
|
||||
id,
|
||||
knowledgeId,
|
||||
name,
|
||||
"RUNNING"
|
||||
);
|
||||
return id;
|
||||
}
|
||||
|
||||
public ImmutableList<Group> list(Long knowledgeId) {
|
||||
return template.query(
|
||||
SqlBuilder.select("id", "name", "status", "created_time", "modified_time")
|
||||
.from(GROUP_TABLE_NAME)
|
||||
.whereEq("knowledge_id", knowledgeId)
|
||||
.orderByDesc("created_time")
|
||||
.build(),
|
||||
groupMapper
|
||||
)
|
||||
.stream()
|
||||
.collect(Collectors.toCollection(Lists.mutable::empty))
|
||||
.toImmutable();
|
||||
public void finish(Long id) {
|
||||
Group group = detailOrThrow(id);
|
||||
group.setStatus(Group.Status.FINISHED);
|
||||
save(group);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void finish(Long groupId) {
|
||||
template.update(
|
||||
SqlBuilder.update(GROUP_TABLE_NAME)
|
||||
.set("status", "FINISHED")
|
||||
.whereEq("id", groupId)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void remove(Long groupId) throws ExecutionException, InterruptedException {
|
||||
Long vectorSourceId = template.queryForObject(
|
||||
SqlBuilder.select("k.vector_source_id")
|
||||
.from(Alias.of(GROUP_TABLE_NAME, "g"), Alias.of(KnowledgeBaseService.KNOWLEDGE_TABLE_NAME, "k"))
|
||||
.whereEq("g.knowledge_id", Column.as("k.id"))
|
||||
.andEq("g.id", groupId)
|
||||
.precompileSql(),
|
||||
Long.class,
|
||||
groupId
|
||||
);
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
Group group = detailOrThrow(id);
|
||||
Knowledge knowledge = group.getKnowledge();
|
||||
client.deleteAsync(
|
||||
String.valueOf(vectorSourceId),
|
||||
String.valueOf(knowledge.getVectorSourceId()),
|
||||
Points.Filter.newBuilder()
|
||||
.addMust(ConditionFactory.matchKeyword("vector_source_id", String.valueOf(vectorSourceId)))
|
||||
.addMust(ConditionFactory.matchKeyword("group_id", String.valueOf(groupId)))
|
||||
.addMust(ConditionFactory.matchKeyword("vector_source_id", String.valueOf(knowledge.getVectorSourceId())))
|
||||
.addMust(ConditionFactory.matchKeyword("group_id", String.valueOf(group.getId())))
|
||||
.build()
|
||||
).get();
|
||||
template.update(
|
||||
SqlBuilder.delete(GROUP_TABLE_NAME)
|
||||
.whereEq("id", groupId)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeByKnowledgeId(Long knowledgeId) {
|
||||
template.update(
|
||||
SqlBuilder.delete(GROUP_TABLE_NAME)
|
||||
.whereEq("knowledge_id", "?")
|
||||
.precompileSql(),
|
||||
knowledgeId
|
||||
);
|
||||
super.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.service.knowledge;
|
||||
|
||||
import club.kingon.sql.builder.SqlBuilder;
|
||||
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.base.service.SimpleServiceSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SnowflakeIdGenerator;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Group;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Knowledge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.vo.KnowledgeVO;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.KnowledgeRepository;
|
||||
import com.lanyuanxiaoyao.service.common.Constants;
|
||||
import io.qdrant.client.ConditionFactory;
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.grpc.Collections;
|
||||
import java.io.IOException;
|
||||
import io.qdrant.client.grpc.Points;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.springframework.ai.document.Document;
|
||||
@@ -20,8 +21,6 @@ import org.springframework.ai.embedding.EmbeddingModel;
|
||||
import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.ai.vectorstore.qdrant.QdrantVectorStore;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -30,134 +29,66 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @version 20250522
|
||||
*/
|
||||
@Service
|
||||
public class KnowledgeBaseService {
|
||||
public class KnowledgeBaseService extends SimpleServiceSupport<Knowledge> {
|
||||
public static final String KNOWLEDGE_TABLE_NAME = Constants.DATABASE_NAME + ".service_ai_knowledge";
|
||||
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());
|
||||
return knowledge;
|
||||
};
|
||||
private final JdbcTemplate template;
|
||||
private final KnowledgeRepository knowledgeRepository;
|
||||
private final EmbeddingModel model;
|
||||
private final QdrantClient client;
|
||||
private final GroupService groupService;
|
||||
|
||||
public KnowledgeBaseService(JdbcTemplate template, EmbeddingModel model, VectorStore vectorStore, GroupService groupService) {
|
||||
this.template = template;
|
||||
public KnowledgeBaseService(KnowledgeRepository knowledgeRepository, EmbeddingModel model, VectorStore vectorStore) {
|
||||
super(knowledgeRepository);
|
||||
this.knowledgeRepository = knowledgeRepository;
|
||||
this.model = model;
|
||||
this.client = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
public Knowledge get(Long id) {
|
||||
return template.queryForObject(
|
||||
SqlBuilder.select("id", "vector_source_id", "name", "strategy", "created_time", "modified_time")
|
||||
.from(KNOWLEDGE_TABLE_NAME)
|
||||
.whereEq("id", "?")
|
||||
.precompileSql(),
|
||||
knowledgeMapper,
|
||||
id
|
||||
);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(String name, String strategy) throws ExecutionException, InterruptedException {
|
||||
Integer count = template.queryForObject(
|
||||
SqlBuilder.select("count(*)")
|
||||
.from(KNOWLEDGE_TABLE_NAME)
|
||||
.whereEq("name", "?")
|
||||
.precompileSql(),
|
||||
Integer.class,
|
||||
name
|
||||
);
|
||||
if (count > 0) {
|
||||
public Long save(Knowledge entity) {
|
||||
if (knowledgeRepository.existsKnowledgeByName(entity.getName())) {
|
||||
throw new RuntimeException("名称已存在");
|
||||
}
|
||||
|
||||
long id = SnowflakeId.next();
|
||||
long vectorSourceId = SnowflakeId.next();
|
||||
template.update(
|
||||
SqlBuilder.insertInto(KNOWLEDGE_TABLE_NAME, "id", "vector_source_id", "name", "strategy")
|
||||
.values()
|
||||
.addValue("?", "?", "?", "?")
|
||||
.precompileSql(),
|
||||
id,
|
||||
vectorSourceId,
|
||||
name,
|
||||
strategy
|
||||
);
|
||||
Long vectorSourceId = SnowflakeIdGenerator.Snowflake.next();
|
||||
client.createCollectionAsync(
|
||||
String.valueOf(vectorSourceId),
|
||||
Collections.VectorParams.newBuilder()
|
||||
.setDistance(Collections.Distance.valueOf(strategy))
|
||||
.setDistance(Collections.Distance.valueOf(entity.getStrategy().name()))
|
||||
.setSize(model.dimensions())
|
||||
.build()
|
||||
).get();
|
||||
}
|
||||
|
||||
public String getName(Long id) {
|
||||
return template.queryForObject(
|
||||
SqlBuilder.select("name")
|
||||
.from(KNOWLEDGE_TABLE_NAME)
|
||||
.whereEq("id", id)
|
||||
.orderByDesc("created_time")
|
||||
.build(),
|
||||
String.class
|
||||
);
|
||||
}
|
||||
|
||||
public ImmutableList<KnowledgeVO> list() {
|
||||
return template.query(
|
||||
SqlBuilder.select("id", "vector_source_id", "name", "strategy", "created_time", "modified_time")
|
||||
.from(KNOWLEDGE_TABLE_NAME)
|
||||
.orderByDesc("created_time")
|
||||
.build(),
|
||||
knowledgeMapper
|
||||
)
|
||||
.stream()
|
||||
.map(knowledge -> {
|
||||
try {
|
||||
Collections.CollectionInfo info = client.getCollectionInfoAsync(String.valueOf(knowledge.getVectorSourceId())).get();
|
||||
KnowledgeVO vo = new KnowledgeVO();
|
||||
vo.setId(knowledge.getId());
|
||||
vo.setVectorSourceId(knowledge.getVectorSourceId());
|
||||
vo.setName(knowledge.getName());
|
||||
vo.setPoints(info.getPointsCount());
|
||||
vo.setSegments(info.getSegmentsCount());
|
||||
vo.setStatus(info.getStatus().name());
|
||||
Collections.VectorParams vectorParams = info.getConfig().getParams().getVectorsConfig().getParams();
|
||||
vo.setStrategy(vectorParams.getDistance().name());
|
||||
vo.setSize(vectorParams.getSize());
|
||||
vo.setCreatedTime(vo.getCreatedTime());
|
||||
vo.setModifiedTime(vo.getModifiedTime());
|
||||
return vo;
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toCollection(Lists.mutable::empty))
|
||||
.toImmutable();
|
||||
entity.setVectorSourceId(vectorSourceId);
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void remove(Long id) throws ExecutionException, InterruptedException {
|
||||
Knowledge knowledge = get(id);
|
||||
if (ObjectUtil.isNull(knowledge)) {
|
||||
throw new RuntimeException(StrUtil.format("{} 不存在"));
|
||||
}
|
||||
template.update(
|
||||
SqlBuilder.delete(KNOWLEDGE_TABLE_NAME)
|
||||
.whereEq("id", "?")
|
||||
.precompileSql(),
|
||||
knowledge.getId()
|
||||
);
|
||||
groupService.removeByKnowledgeId(knowledge.getId());
|
||||
public void updateDescription(Long id, String description) throws Exception {
|
||||
Knowledge knowledge = detailOrThrow(id);
|
||||
knowledge.setDescription(description);
|
||||
save(knowledge);
|
||||
}
|
||||
|
||||
public String getName(Long id) {
|
||||
return detailOrThrow(id).getName();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
Knowledge knowledge = detailOrThrow(id);
|
||||
client.deleteCollectionAsync(String.valueOf(knowledge.getVectorSourceId())).get();
|
||||
for (Group group : knowledge.getGroups()) {
|
||||
client.deleteAsync(
|
||||
String.valueOf(knowledge.getVectorSourceId()),
|
||||
Points.Filter.newBuilder()
|
||||
.addMust(ConditionFactory.matchKeyword("vector_source_id", String.valueOf(knowledge.getVectorSourceId())))
|
||||
.addMust(ConditionFactory.matchKeyword("group_id", String.valueOf(group.getId())))
|
||||
.build()
|
||||
).get();
|
||||
}
|
||||
super.remove(id);
|
||||
}
|
||||
|
||||
public ImmutableList<String> query(
|
||||
@@ -165,8 +96,8 @@ public class KnowledgeBaseService {
|
||||
String text,
|
||||
Integer limit,
|
||||
Double threshold
|
||||
) throws ExecutionException, InterruptedException, IOException {
|
||||
Knowledge knowledge = get(id);
|
||||
) throws ExecutionException, InterruptedException {
|
||||
Knowledge knowledge = detailOrThrow(id);
|
||||
Boolean exists = client.collectionExistsAsync(String.valueOf(knowledge.getVectorSourceId())).get();
|
||||
if (!exists) {
|
||||
throw new RuntimeException(StrUtil.format("{} not exists", id));
|
||||
@@ -182,14 +113,11 @@ 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);
|
||||
}
|
||||
|
||||
public Collections.CollectionInfo collectionInfo(Long vectorSourceId) throws ExecutionException, InterruptedException {
|
||||
return client.getCollectionInfoAsync(String.valueOf(vectorSourceId)).get();
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@ public class SegmentService {
|
||||
this.client = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
|
||||
}
|
||||
|
||||
public ImmutableList<SegmentVO> list(Long id, Long groupId) throws ExecutionException, InterruptedException {
|
||||
Knowledge knowledge = knowledgeBaseService.get(id);
|
||||
public ImmutableList<SegmentVO> list(Long knowledgeId, Long groupId) throws ExecutionException, InterruptedException {
|
||||
Knowledge knowledge = knowledgeBaseService.detailOrThrow(knowledgeId);
|
||||
Points.ScrollResponse response = client.scrollAsync(
|
||||
Points.ScrollPoints.newBuilder()
|
||||
.setCollectionName(String.valueOf(knowledge.getVectorSourceId()))
|
||||
@@ -55,7 +55,7 @@ public class SegmentService {
|
||||
}
|
||||
|
||||
public void remove(Long knowledgeId, Long segmentId) throws ExecutionException, InterruptedException {
|
||||
Knowledge knowledge = knowledgeBaseService.get(knowledgeId);
|
||||
Knowledge knowledge = knowledgeBaseService.detailOrThrow(knowledgeId);
|
||||
client.deletePayloadAsync(
|
||||
String.valueOf(knowledgeId),
|
||||
List.of(String.valueOf(segmentId)),
|
||||
|
||||
@@ -19,8 +19,6 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.DocumentReader;
|
||||
@@ -42,12 +40,12 @@ import org.springframework.core.io.PathResource;
|
||||
@Slf4j
|
||||
@LiteflowComponent
|
||||
public class EmbeddingNodes {
|
||||
private final ChatClient chatClient;
|
||||
private final ChatClient.Builder chatClientBuilder;
|
||||
private final QdrantClient qdrantClient;
|
||||
private final EmbeddingModel embeddingModel;
|
||||
|
||||
public EmbeddingNodes(@Qualifier("chat") ChatClient.Builder builder, VectorStore vectorStore, EmbeddingModel embeddingModel) {
|
||||
this.chatClient = builder.build();
|
||||
this.chatClientBuilder = builder;
|
||||
this.qdrantClient = (QdrantClient) vectorStore.getNativeClient().orElseThrow();
|
||||
this.embeddingModel = embeddingModel;
|
||||
}
|
||||
@@ -152,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. 问题部分:
|
||||
为同一个主题创建尽可能多的不同表述的问题,确保问题的多样性。
|
||||
每个问题应考虑用户可能的多种问法,例如:
|
||||
@@ -169,7 +169,7 @@ public class EmbeddingNodes {
|
||||
答案应直接基于给定文本,确保准确性和一致性。
|
||||
包含相关的细节,如日期、名称、职位等具体信息,必要时提供背景信息以增强理解。
|
||||
3. 格式:
|
||||
使用"问:"标记问题集合的开始,所有问题应在一个段落内,问题之间用空格分隔。
|
||||
使用"问:"标记问题的开始,问题文本应在一个段落内完成。
|
||||
使用"答:"标记答案的开始,答案应清晰分段,便于阅读。
|
||||
问答对之间用“---”分隔,以提高可读性。
|
||||
4. 内容要求:
|
||||
@@ -177,6 +177,8 @@ public class EmbeddingNodes {
|
||||
避免添加文本中未提及的信息,确保信息的真实性。
|
||||
一个问题搭配一个答案,避免一组问答对中同时涉及多个问题。
|
||||
如果文本信息不足以回答某个方面,可以在答案中说明 "根据给定信息无法确定",并尽量提供相关的上下文。
|
||||
除了问答对本身,避免输出任何与问答对无关的提示性、引导性、解释性的文本。
|
||||
|
||||
格式样例:
|
||||
问:苹果通常是什么颜色的?
|
||||
答:红色。
|
||||
@@ -190,7 +192,8 @@ 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()
|
||||
|
||||
@@ -1,14 +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.DataFile;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.Feedback;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.context.FeedbackContext;
|
||||
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) {
|
||||
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.getPictures());
|
||||
}
|
||||
|
||||
@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 (DataFile picture : feedback.getPictures()) {
|
||||
DataFile file = dataFileService.downloadFile(picture.getId());
|
||||
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 X;2. 触发操作 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.service.task;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowExecutor;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.CodeNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.InputNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.LlmNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.LoopNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.OutputNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.SwitchNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.store.InMemoryFlowStore;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.vo.FlowGraphVo;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.FlowTaskRepository;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FlowTaskService extends SimpleServiceSupport<FlowTask> {
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public FlowTaskService(FlowTaskRepository flowTaskRepository, Jackson2ObjectMapperBuilder builder) {
|
||||
super(flowTaskRepository);
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
public void execute(Long id) throws JsonProcessingException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
var flowTask = detailOrThrow(id);
|
||||
var graphVo = mapper.readValue(flowTask.getTemplateFlowGraph(), FlowGraphVo.class);
|
||||
var flowGraph = new FlowGraph(IdUtil.fastUUID(), graphVo.getNodes(), graphVo.getEdges());
|
||||
|
||||
var store = new InMemoryFlowStore();
|
||||
var executor = new FlowExecutor(
|
||||
store,
|
||||
Maps.immutable.ofAll(Map.of(
|
||||
"loop-node", LoopNode.class,
|
||||
"switch-node", SwitchNode.class,
|
||||
"code-node", CodeNode.class,
|
||||
"llm-node", LlmNode.class,
|
||||
"input-node", InputNode.class,
|
||||
"output-node", OutputNode.class
|
||||
))
|
||||
);
|
||||
FlowContext context = new FlowContext();
|
||||
context.setData(graphVo.getData());
|
||||
|
||||
if (ObjectUtil.isNotEmpty(flowTask.getInput())) {
|
||||
context.getData().put(InputNode.KEY, mapper.readValue(flowTask.getInput(), new TypeReference<>() {
|
||||
}));
|
||||
}
|
||||
|
||||
executor.execute(flowGraph, context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.service.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.vo.FlowGraphVo;
|
||||
import com.lanyuanxiaoyao.service.ai.web.repository.FlowTaskTemplateRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FlowTaskTemplateService extends SimpleServiceSupport<FlowTaskTemplate> {
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public FlowTaskTemplateService(FlowTaskTemplateRepository flowTaskTemplateRepository, Jackson2ObjectMapperBuilder builder) {
|
||||
super(flowTaskTemplateRepository);
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateFlowGraph(Long id, String flowGraph) throws JsonProcessingException {
|
||||
var template = detailOrThrow(id);
|
||||
|
||||
var graph = mapper.readValue(flowGraph, FlowGraphVo.class);
|
||||
// 如果发现输入节点,就单独提取出来
|
||||
var inputNode = graph.getNodes()
|
||||
.detectOptional(node -> StrUtil.equals(node.type(), "input-node") && ObjectUtil.isEmpty(node.parentId()))
|
||||
.orElse(null);
|
||||
if (ObjectUtil.isNotNull(inputNode)) {
|
||||
var nodeId = inputNode.id();
|
||||
var nodeData = graph.getData().getOrDefault(nodeId, null);
|
||||
if (ObjectUtil.isNotNull(nodeData) && nodeData.containsKey("inputs")) {
|
||||
template.setInputSchema(mapper.writeValueAsString(nodeData.get("inputs")));
|
||||
}
|
||||
}
|
||||
|
||||
template.setFlowGraph(flowGraph);
|
||||
save(template);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.tool.annotation.Tool;
|
||||
@@ -44,7 +44,7 @@ public class ChartTool {
|
||||
""") String request
|
||||
) {
|
||||
log.info("Enter method: mermaid[request]. request:{}", request);
|
||||
ChatClient.Builder builder = WebApplication.getBean(ChatClient.Builder.class);
|
||||
ChatClient.Builder builder = SpringBeanGetter.getBean("chat", ChatClient.Builder.class);
|
||||
ChatClient client = builder.build();
|
||||
return client.prompt()
|
||||
// language=TEXT
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
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 = WebApplication.getBean(KnowledgeService.class);
|
||||
KnowledgeService knowledgeService = SpringBeanGetter.getBean(KnowledgeService.class);
|
||||
var documents = knowledgeService.query(knowledgeId, query, 10, 0.5);
|
||||
if (ObjectUtil.isNotEmpty(documents)) {
|
||||
return StrUtil.format("""
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
import com.lanyuanxiaoyao.service.forest.service.InfoService;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -27,7 +27,7 @@ public class TableTool {
|
||||
""") String sql
|
||||
) {
|
||||
log.info("Enter method: executeJdbc[sql]. sql:{}", sql);
|
||||
InfoService infoService = WebApplication.getBean(InfoService.class);
|
||||
InfoService infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||
String result = infoService.jdbc(sql)
|
||||
.collect(map -> map.valuesView().makeString(","))
|
||||
.makeString("\n");
|
||||
@@ -48,7 +48,7 @@ public class TableTool {
|
||||
""") String type
|
||||
) {
|
||||
log.info("Enter method: tableCount[type]. type:{}", type);
|
||||
var infoService = WebApplication.getBean(InfoService.class);
|
||||
var infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||
return switch (type) {
|
||||
case "logic" -> StrUtil.format("""
|
||||
逻辑表共{}张,其中重点表{}张
|
||||
@@ -83,7 +83,7 @@ public class TableTool {
|
||||
String type
|
||||
) {
|
||||
log.info("Enter method: version[date, type]. date:{},type:{}", date, type);
|
||||
InfoService infoService = WebApplication.getBean(InfoService.class);
|
||||
InfoService infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||
String version = date;
|
||||
if (StrUtil.isBlank(version)) {
|
||||
version = LocalDateTime.now().minusDays(1).format(FORMATTER);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
||||
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
|
||||
@@ -27,7 +27,7 @@ public class YarnTool {
|
||||
""") String cluster
|
||||
) {
|
||||
log.info("Enter method: yarnStatus[cluster]. cluster:{}", cluster);
|
||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
||||
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||
YarnRootQueue status = yarnService.cluster(cluster);
|
||||
return (status.getUsedCapacity() * 100.0) / status.getCapacity();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class YarnTool {
|
||||
""") String queue
|
||||
) {
|
||||
log.info("Enter method: yarnQueueStatus[cluster, queue]. cluster:{},queue:{}", cluster, queue);
|
||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
||||
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||
YarnQueue status = yarnService.queueDetail(cluster, queue);
|
||||
return (status.getAbsoluteCapacity() * 100.0) / status.getAbsoluteMaxCapacity();
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class YarnTool {
|
||||
""") String type
|
||||
) {
|
||||
log.info("Enter method: yarnTaskStatus[cluster, type]. cluster:{},type:{}", cluster, type);
|
||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
||||
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||
ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> StrUtil.isNotBlank(type) && StrUtil.contains(app.getName(), type));
|
||||
return StrUtil.format(
|
||||
"""
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: random-port,common,discovery,metrics,forest
|
||||
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:
|
||||
model: 'Qwen3/qwen3-1.7b'
|
||||
visual:
|
||||
model: 'Qwen2.5/qwen2.5-vl-7b'
|
||||
embedding:
|
||||
model: 'Qwen3/qwen3-embedding-4b'
|
||||
reranker:
|
||||
model: 'Bge-reranker-v2'
|
||||
@@ -1,39 +0,0 @@
|
||||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
ai:
|
||||
vectorstore:
|
||||
qdrant:
|
||||
host: 192.168.100.140
|
||||
port: 6334
|
||||
llm:
|
||||
base-url: https://api.siliconflow.cn
|
||||
api-key: sk-xrguybusoqndpqvgzgvllddzgjamksuecyqdaygdwnrnqfwo
|
||||
chat:
|
||||
model: 'Qwen/Qwen3-8B'
|
||||
visual:
|
||||
base-url: https://open.bigmodel.cn/api/paas/v4
|
||||
endpoint: /chat/completions
|
||||
model: 'glm-4v-flash'
|
||||
embedding:
|
||||
model: 'BAAI/bge-m3'
|
||||
reranker:
|
||||
model: 'BAAI/bge-reranker-v2-m3'
|
||||
cloud:
|
||||
discovery:
|
||||
enabled: false
|
||||
zookeeper:
|
||||
enabled: false
|
||||
datasource:
|
||||
url: jdbc:mysql://192.168.100.140:3306/hudi_collect_build_b12?useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: test
|
||||
password: test
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
security:
|
||||
meta:
|
||||
authority: ENC(GXKnbq1LS11U2HaONspvH+D/TkIx13aWTaokdkzaF7HSvq6Z0Rv1+JUWFnYopVXu)
|
||||
username: ENC(moIO5mO39V1Z+RDwROK9JXY4GfM8ZjDgM6Si7wRZ1MPVjbhTpmLz3lz28rAiw7c2LeCmizfJzHkEXIwGlB280g==)
|
||||
darkcode: ENC(0jzpQ7T6S+P7bZrENgYsUoLhlqGvw7DA2MN3BRqEOwq7plhtg72vuuiPQNnr3DaYz0CpyTvxInhpx11W3VZ1trD6NINh7O3LN70ZqO5pWXk=)
|
||||
jasypt:
|
||||
encryptor:
|
||||
password: 'r#(R,P"Dp^A47>WSn:Wn].gs/+"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.'
|
||||
@@ -1,6 +1,11 @@
|
||||
server:
|
||||
compression:
|
||||
enabled: true
|
||||
spring:
|
||||
application:
|
||||
name: service-ai-web
|
||||
profiles:
|
||||
include: random-port,common,discovery,metrics,forest
|
||||
mvc:
|
||||
async:
|
||||
request-timeout: 3600000
|
||||
@@ -13,7 +18,30 @@ spring:
|
||||
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'
|
||||
jpa:
|
||||
show-sql: true
|
||||
generate-ddl: false
|
||||
liteflow:
|
||||
rule-source: liteflow.xml
|
||||
print-banner: false
|
||||
check-node-exists: false
|
||||
check-node-exists: false
|
||||
fenix:
|
||||
print-banner: false
|
||||
|
||||
@@ -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>
|
||||
@@ -25,7 +25,7 @@
|
||||
</appender>
|
||||
|
||||
<logger name="com.zaxxer.hikari" level="ERROR"/>
|
||||
<logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
|
||||
<logger name="org.hibernate.SQL" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="Console"/>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import jakarta.persistence.Entity;
|
||||
import java.util.EnumSet;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
||||
|
||||
/**
|
||||
* JPA直接生成建表语句
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250702
|
||||
*/
|
||||
public class GenerateDDL {
|
||||
public static void main(String[] args) {
|
||||
String root = "/Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-ai/target/sql";
|
||||
FileUtil.mkdir(root);
|
||||
/* ClassUtil.scanPackageBySuper("org.hibernate.dialect", Dialect.class)
|
||||
.stream()
|
||||
.filter(clazz -> StrUtil.startWith(clazz.getSimpleName(), "MySQL"))
|
||||
.filter(clazz -> !StrUtil.startWith(clazz.getSimpleName(), "Abstract"))
|
||||
.filter(clazz -> !StrUtil.startWith(clazz.getSimpleName(), "Dialect"))
|
||||
.forEach(dialectClazz -> generateDDL(root, dialectClazz)); */
|
||||
generateDDL(root, MySQLDialect.class);
|
||||
}
|
||||
|
||||
private static void generateDDL(String path, Class<?> dialect) {
|
||||
var metadataSources = new MetadataSources(
|
||||
new StandardServiceRegistryBuilder()
|
||||
.applySetting("hibernate.dialect", dialect.getName())
|
||||
.applySetting("hibernate.physical_naming_strategy", CamelCaseToUnderscoresNamingStrategy.class.getName())
|
||||
.applySetting("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName())
|
||||
.build()
|
||||
);
|
||||
var classes = ClassUtil.scanPackageByAnnotation("com.lanyuanxiaoyao.service.ai.web.entity", Entity.class);
|
||||
classes.forEach(metadataSources::addAnnotatedClass);
|
||||
var export = new SchemaExport();
|
||||
export.setFormat(true);
|
||||
export.setDelimiter(";");
|
||||
export.setOutputFile(path + "/" + dialect.getSimpleName() + ".sql");
|
||||
export.setOverrideOutputFileContent();
|
||||
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadataSources.buildMetadata());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.JavaScriptCodeExecutor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250717
|
||||
*/
|
||||
@Slf4j
|
||||
public class TestCodeExecutor {
|
||||
public static void main(String[] args) {
|
||||
var mapper = new ObjectMapper();
|
||||
mapper.registerModule(new EclipseCollectionsModule());
|
||||
var executor = new JavaScriptCodeExecutor(mapper);
|
||||
var result = executor.execute(
|
||||
"""
|
||||
return {'code': 1, 'text': context.get('text')}
|
||||
""",
|
||||
Maps.immutable.of(
|
||||
"text", "hello world"
|
||||
)
|
||||
);
|
||||
log.info("Result: {}", result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web;
|
||||
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowExecutor;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeOptionalRunner;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||
import com.lanyuanxiaoyao.service.ai.web.engine.store.InMemoryFlowStore;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250701
|
||||
*/
|
||||
@Slf4j
|
||||
public class TestFlow {
|
||||
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
var store = new InMemoryFlowStore();
|
||||
var executor = new FlowExecutor(
|
||||
store,
|
||||
Maps.immutable.of(
|
||||
"plain-node", PlainNode.class,
|
||||
"option-node", PlainOptionNode.class
|
||||
)
|
||||
);
|
||||
/*
|
||||
* 4 6 7
|
||||
* 1 2 5 8---3
|
||||
* \9/
|
||||
*/
|
||||
var graph = new FlowGraph(
|
||||
"graph-1",
|
||||
Sets.immutable.of(
|
||||
new FlowNode("node-1", "plain-node", null),
|
||||
new FlowNode("node-2", "plain-node", null),
|
||||
new FlowNode("node-4", "plain-node", null),
|
||||
new FlowNode("node-6", "plain-node", null),
|
||||
new FlowNode("node-7", "plain-node", null),
|
||||
new FlowNode("node-5", "plain-node", null),
|
||||
new FlowNode("node-8", "option-node", null),
|
||||
new FlowNode("node-9", "plain-node", null),
|
||||
new FlowNode("node-3", "plain-node", null)
|
||||
),
|
||||
Sets.immutable.of(
|
||||
new FlowEdge("edge-1", "node-1", "node-2", null, null),
|
||||
new FlowEdge("edge-2", "node-2", "node-4", null, null),
|
||||
new FlowEdge("edge-3", "node-2", "node-5", null, null),
|
||||
new FlowEdge("edge-4", "node-5", "node-8", null, null),
|
||||
new FlowEdge("edge-5", "node-8", "node-9", "yes", null),
|
||||
new FlowEdge("edge-6", "node-8", "node-3", "no", null),
|
||||
new FlowEdge("edge-7", "node-9", "node-3", null, null),
|
||||
new FlowEdge("edge-8", "node-4", "node-6", null, null),
|
||||
new FlowEdge("edge-9", "node-6", "node-7", null, null),
|
||||
new FlowEdge("edge-10", "node-7", "node-3", null, null)
|
||||
)
|
||||
);
|
||||
executor.execute(graph);
|
||||
store.print();
|
||||
}
|
||||
|
||||
public static class PlainNode extends FlowNodeRunner {
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("run node id: {}", getNodeId());
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlainOptionNode extends FlowNodeOptionalRunner {
|
||||
@Override
|
||||
public String runOptional() {
|
||||
log.info("run node id: {}", getNodeId());
|
||||
// yes / no
|
||||
return "no";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,114 +1,68 @@
|
||||
package com.lanyuanxiaoyao.service.ai.web;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.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;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250526
|
||||
*/
|
||||
@Slf4j
|
||||
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();
|
||||
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("""
|
||||
对用户输入的文本,生成多组高质量的问答对。请遵循以下指南:
|
||||
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 Lake),Hudi 在实时更新和增量处理方面表现突出,尤其适合需要频繁数据变更的场景。其独特的 MoR 模型在写入性能上优于传统批处理方案。
|
||||
|
||||
总结
|
||||
|
||||
Apache Hudi 通过灵活的存储模型、高效的事务管理和广泛的生态系统集成,成为构建现代化数据湖的核心工具,适用于金融、物联网、实时分析等对数据新鲜度和操作效率要求高的领域。
|
||||
你是一个专业的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);
|
||||
|
||||
@@ -161,23 +161,15 @@ 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:
|
||||
"[spring.profiles.active]": 'build'
|
||||
"[file-store.download-prefix]": 'http://132.126.207.130:35690/hudi_services/ai_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}
|
||||
|
||||
@@ -2,11 +2,15 @@ package com.lanyuanxiaoyao.service.configuration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* Spring Security Config
|
||||
@@ -25,6 +29,19 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
this.securityProperties = securityProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowCredentials(true);
|
||||
configuration.addAllowedOriginPattern("*");
|
||||
configuration.addAllowedHeader("*");
|
||||
configuration.addAllowedMethod("*");
|
||||
configuration.setMaxAge(7200L);
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests()
|
||||
@@ -36,7 +53,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.csrf()
|
||||
.disable()
|
||||
.cors()
|
||||
.disable()
|
||||
.and()
|
||||
.formLogin()
|
||||
.disable();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
|
||||
/**
|
||||
@@ -33,24 +33,12 @@ public class SecurityConfiguration {
|
||||
.httpBasic()
|
||||
.disable()
|
||||
.cors()
|
||||
.configurationSource(corsConfigurationSource())
|
||||
.and()
|
||||
.disable()
|
||||
.csrf()
|
||||
.disable()
|
||||
.build();
|
||||
}
|
||||
|
||||
private CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowCredentials(true);
|
||||
configuration.addAllowedHeader("*");
|
||||
configuration.addAllowedMethod("*");
|
||||
configuration.addAllowedOriginPattern("*");
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", configuration);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MapReactiveUserDetailsService userDetailsService(SecurityProperties securityProperties) {
|
||||
UserDetails user = User.builder()
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user