mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-18 06:13:39 +00:00
Compare commits
9 Commits
827ac48826
...
5088c0e6d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5088c0e6d7 | ||
|
|
2995b6ddde | ||
|
|
5475776caa | ||
|
|
08d4977263 | ||
|
|
31602cb85e | ||
|
|
5adc5f0006 | ||
|
|
307d095cf1 | ||
|
|
2cef4e17dc | ||
|
|
b47da3f438 |
@@ -150,6 +150,13 @@
|
||||
<strong>QQ技术交流群</strong><br>
|
||||
<em>技术讨论</em>
|
||||
</td>
|
||||
|
||||
<td align="center">
|
||||
<img width="200" height="200" alt="95e8b1b3baeadbd24650bfb974ca5a58" src="https://github.com/user-attachments/assets/2a346218-6388-484d-aa75-6e98942193f7" /><br>
|
||||
<strong>微信技术交流群</strong><br>
|
||||
<em>技术讨论</em>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.ruoyi.domain;
|
||||
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
@@ -81,6 +82,11 @@ public class ChatModel extends BaseEntity {
|
||||
*/
|
||||
private Integer priority;
|
||||
|
||||
/**
|
||||
* 模型供应商
|
||||
*/
|
||||
private String ProviderName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.ruoyi.domain.bo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -85,6 +86,10 @@ public class ChatModelBo extends BaseEntity {
|
||||
@NotBlank(message = "密钥不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String apiKey;
|
||||
|
||||
/**
|
||||
* 模型供应商
|
||||
*/
|
||||
private String ProviderName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
|
||||
@@ -95,6 +95,12 @@ public class ChatModelVo implements Serializable {
|
||||
@ExcelProperty(value = "优先级")
|
||||
private Integer priority;
|
||||
|
||||
/**
|
||||
* 模型供应商
|
||||
*/
|
||||
@ExcelProperty(value = "模型供应商")
|
||||
private String ProviderName;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -106,6 +106,10 @@
|
||||
<artifactId>dashscope-sdk-java</artifactId>
|
||||
<version>2.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-chat-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -83,6 +83,11 @@ public class KnowledgeInfo extends BaseEntity {
|
||||
*/
|
||||
private String vectorModelName;
|
||||
|
||||
/**
|
||||
* 向量化模型id
|
||||
*/
|
||||
private Long embeddingModelId;
|
||||
|
||||
/**
|
||||
* 向量化模型名称
|
||||
*/
|
||||
|
||||
@@ -92,7 +92,11 @@ public class KnowledgeInfoBo extends BaseEntity {
|
||||
/**
|
||||
* 向量化模型名称
|
||||
*/
|
||||
@NotBlank(message = "向量模型不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long embeddingModelId;
|
||||
|
||||
/**
|
||||
* 向量化模型名称
|
||||
*/
|
||||
private String embeddingModelName;
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ public class QueryVectorBo {
|
||||
private String vectorModelName;
|
||||
|
||||
/**
|
||||
* 向量化模型名称
|
||||
* 向量化模型ID
|
||||
*/
|
||||
private Long embeddingModelId;
|
||||
|
||||
/**
|
||||
* 向量化模型ID
|
||||
*/
|
||||
private String embeddingModelName;
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ public class StoreEmbeddingBo {
|
||||
*/
|
||||
private String vectorModelName;
|
||||
|
||||
/**
|
||||
* 向量化模型id
|
||||
*/
|
||||
private Long embeddingModelId;
|
||||
|
||||
/**
|
||||
* 向量化模型名称
|
||||
*/
|
||||
|
||||
@@ -101,6 +101,11 @@ public class KnowledgeInfoVo implements Serializable {
|
||||
*/
|
||||
private String vectorModelName;
|
||||
|
||||
/**
|
||||
* 向量化模型id
|
||||
*/
|
||||
private Long embeddingModelId;
|
||||
|
||||
/**
|
||||
* 向量化模型名称
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.ruoyi.embedding;
|
||||
|
||||
import dev.langchain4j.model.embedding.EmbeddingModel;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* BaseEmbedModelService 接口,扩展了 EmbeddingModel 接口
|
||||
* 该接口定义了嵌入模型服务的基本配置和功能方法
|
||||
*/
|
||||
public interface BaseEmbedModelService extends EmbeddingModel {
|
||||
/**
|
||||
* 根据配置信息配置嵌入模型
|
||||
* @param config 包含模型配置信息的 ChatModelVo 对象
|
||||
*/
|
||||
void configure(ChatModelVo config);
|
||||
|
||||
/**
|
||||
* 获取当前嵌入模型支持的所有模态类型
|
||||
* @return 返回支持的模态类型集合
|
||||
*/
|
||||
Set<ModalityType> getSupportedModalities();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.ruoyi.embedding;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.service.IChatModelService;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 嵌入模型工厂服务类
|
||||
* 负责创建和管理各种嵌入模型实例
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class EmbeddingModelFactory {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final IChatModelService chatModelService;
|
||||
|
||||
// 模型缓存,使用ConcurrentHashMap保证线程安全
|
||||
private final Map<Long, BaseEmbedModelService> modelCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 创建嵌入模型实例
|
||||
* 如果模型已存在于缓存中,则直接返回;否则创建新的实例
|
||||
*
|
||||
* @param embeddingModelId 嵌入模型的唯一标识ID
|
||||
* @return BaseEmbedModelService 嵌入模型服务实例
|
||||
*/
|
||||
public BaseEmbedModelService createModel(Long embeddingModelId) {
|
||||
return modelCache.computeIfAbsent(embeddingModelId, id -> {
|
||||
ChatModelVo modelConfig = chatModelService.queryById(id);
|
||||
if (modelConfig == null) {
|
||||
throw new IllegalArgumentException("未找到模型配置,ID=" + id);
|
||||
}
|
||||
return createModelInstance(modelConfig.getProviderName(), modelConfig);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模型是否支持多模态
|
||||
*
|
||||
* @param embeddingModelId 嵌入模型的唯一标识ID
|
||||
* @return boolean 如果模型支持多模态则返回true,否则返回false
|
||||
*/
|
||||
public boolean isMultimodalModel(Long embeddingModelId) {
|
||||
return createModel(embeddingModelId) instanceof MultiModalEmbedModelService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建多模态嵌入模型实例
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @return MultiModalEmbedModelService 多模态嵌入模型服务实例
|
||||
* @throws IllegalArgumentException 当模型不支持多模态时抛出
|
||||
*/
|
||||
public MultiModalEmbedModelService createMultimodalModel(Long tenantId) {
|
||||
BaseEmbedModelService model = createModel(tenantId);
|
||||
if (model instanceof MultiModalEmbedModelService) {
|
||||
return (MultiModalEmbedModelService) model;
|
||||
}
|
||||
throw new IllegalArgumentException("该模型不支持多模态");
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新模型缓存
|
||||
* 根据给定的嵌入模型ID从缓存中移除对应的模型
|
||||
*
|
||||
* @param embeddingModelId 嵌入模型的唯一标识ID
|
||||
*/
|
||||
public void refreshModel(Long embeddingModelId) {
|
||||
// 从模型缓存中移除指定ID的模型
|
||||
modelCache.remove(embeddingModelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有支持模型工厂的列表
|
||||
*
|
||||
* @return List<String> 支持的模型工厂名称列表
|
||||
*/
|
||||
public List<String> getSupportedFactories() {
|
||||
return new ArrayList<>(applicationContext.getBeansOfType(BaseEmbedModelService.class)
|
||||
.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建具体的模型实例
|
||||
* 根据提供的工厂名称和配置信息创建并配置模型实例
|
||||
*
|
||||
* @param factory 工厂名称,用于标识模型类型
|
||||
* @param config 模型配置信息
|
||||
* @return BaseEmbedModelService 配置好的模型实例
|
||||
* @throws IllegalArgumentException 当无法获取指定的模型实例时抛出
|
||||
*/
|
||||
private BaseEmbedModelService createModelInstance(String factory, ChatModelVo config) {
|
||||
try {
|
||||
// 从Spring上下文中获取模型实例
|
||||
BaseEmbedModelService model = applicationContext.getBean(factory, BaseEmbedModelService.class);
|
||||
// 配置模型参数
|
||||
model.configure(config);
|
||||
log.info("成功创建嵌入模型: factory={}, modelId={}", config.getProviderName(), config.getId());
|
||||
|
||||
return model;
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
throw new IllegalArgumentException("获取不到嵌入模型: " + factory, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.ruoyi.embedding;
|
||||
|
||||
import dev.langchain4j.data.embedding.Embedding;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import org.ruoyi.embedding.model.MultiModalInput;
|
||||
|
||||
|
||||
/**
|
||||
* 多模态嵌入模型服务接口,继承自基础嵌入模型服务
|
||||
* 该接口提供了处理图像、视频以及多模态数据并转换为嵌入向量的功能
|
||||
*/
|
||||
public interface MultiModalEmbedModelService extends BaseEmbedModelService {
|
||||
/**
|
||||
* 将图像数据转换为嵌入向量
|
||||
* @param imageDataUrl 图像的地址,必须是公开可访问的URL
|
||||
* @return 包含嵌入向量的响应对象,可能包含状态信息和嵌入结果
|
||||
*/
|
||||
Response<Embedding> embedImage(String imageDataUrl);
|
||||
|
||||
/**
|
||||
* 将视频数据转换为嵌入向量
|
||||
* @param videoDataUrl 视频的地址,必须是公开可访问的URL
|
||||
* @return 包含嵌入向量的响应对象,可能包含状态信息和嵌入结果
|
||||
*/
|
||||
Response<Embedding> embedVideo(String videoDataUrl);
|
||||
|
||||
|
||||
/**
|
||||
* 处理多模态输入并返回嵌入向量的方法
|
||||
*
|
||||
* @param input 包含多种模态信息(如图像、文本等)的输入对象
|
||||
* @return Response<Embedding> 包含嵌入向量的响应对象,Embedding通常表示输入数据的向量表示
|
||||
*/
|
||||
Response<Embedding> embedMultiModal(MultiModalInput input);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午3:00
|
||||
* @Description: 阿里百炼基础嵌入模型(兼容openai)
|
||||
*/
|
||||
@Component("alibailian")
|
||||
public class AliBaiLianBaseEmbedProvider extends OpenAiEmbeddingProvider{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.langchain4j.data.embedding.Embedding;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import dev.langchain4j.model.output.TokenUsage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.embedding.MultiModalEmbedModelService;
|
||||
import org.ruoyi.embedding.model.AliyunMultiModalEmbedRequest;
|
||||
import org.ruoyi.embedding.model.AliyunMultiModalEmbedResponse;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
import org.ruoyi.embedding.model.MultiModalInput;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 阿里云百炼多模态嵌入模型服务实现类
|
||||
* 实现了MultiModalEmbedModelService接口,提供文本、图像和视频的嵌入向量生成服务
|
||||
*/
|
||||
@Component("bailianMultiModel")
|
||||
@Slf4j
|
||||
public class AliBaiLianMultiEmbeddingProvider implements MultiModalEmbedModelService {
|
||||
private ChatModelVo chatModelVo;
|
||||
|
||||
private final OkHttpClient okHttpClient;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化HTTP客户端
|
||||
* 设置连接超时、读取超时和写入超时时间
|
||||
*/
|
||||
public AliBaiLianMultiEmbeddingProvider() {
|
||||
this.okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像嵌入向量生成
|
||||
* @param imageDataUrl 图像数据的URL
|
||||
* @return 包含图像嵌入向量的Response对象
|
||||
*/
|
||||
@Override
|
||||
public Response<Embedding> embedImage(String imageDataUrl) {
|
||||
return embedSingleModality("image", imageDataUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频嵌入向量生成
|
||||
* @param videoDataUrl 视频数据的URL
|
||||
* @return 包含视频嵌入向量的Response对象
|
||||
*/
|
||||
@Override
|
||||
public Response<Embedding> embedVideo(String videoDataUrl) {
|
||||
return embedSingleModality("video", videoDataUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多模态嵌入向量生成
|
||||
* 支持同时处理文本、图像和视频等多种模态的数据
|
||||
* @param input 包含多种模态输入的对象
|
||||
* @return 包含多模态嵌入向量的Response对象
|
||||
*/
|
||||
@Override
|
||||
public Response<Embedding> embedMultiModal(MultiModalInput input) {
|
||||
try {
|
||||
// 构建请求内容
|
||||
List<Map<String, Object>> contents = buildContentMap(input);
|
||||
if (contents.isEmpty()) {
|
||||
throw new IllegalArgumentException("至少提供一种模态的内容");
|
||||
}
|
||||
|
||||
// 构建请求
|
||||
AliyunMultiModalEmbedRequest request = buildRequest(contents, chatModelVo);
|
||||
AliyunMultiModalEmbedResponse resp = executeRequest(request, chatModelVo);
|
||||
|
||||
// 转换为 embeddings
|
||||
Response<List<Embedding>> response = toEmbeddings(resp);
|
||||
List<Embedding> embeddings = response.content();
|
||||
|
||||
if (embeddings.isEmpty()) {
|
||||
log.warn("阿里云混合模态嵌入返回为空");
|
||||
return Response.from(Embedding.from(new float[0]), response.tokenUsage());
|
||||
}
|
||||
|
||||
// 多模态通常取第一个向量作为代表,也可以根据业务场景返回多个
|
||||
return Response.from(embeddings.get(0), response.tokenUsage());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("阿里云混合模态嵌入失败", e);
|
||||
throw new IllegalArgumentException("阿里云混合模态嵌入失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置模型参数
|
||||
* @param config 模型配置信息
|
||||
*/
|
||||
@Override
|
||||
public void configure(ChatModelVo config) {
|
||||
this.chatModelVo = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支持的模态类型
|
||||
* @return 支持的模态类型集合
|
||||
*/
|
||||
@Override
|
||||
public Set<ModalityType> getSupportedModalities() {
|
||||
return Set.of(ModalityType.TEXT, ModalityType.VIDEO, ModalityType.IMAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量文本嵌入向量生成
|
||||
* @param textSegments 文本段列表
|
||||
* @return 包含所有文本嵌入向量的Response对象
|
||||
*/
|
||||
@Override
|
||||
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments) {
|
||||
if (textSegments.isEmpty()) return Response.from(Collections.emptyList());
|
||||
|
||||
try {
|
||||
List<Map<String, Object>> contents = new ArrayList<>();
|
||||
for (TextSegment segment : textSegments) {
|
||||
contents.add(Map.of("text", segment.text()));
|
||||
}
|
||||
|
||||
AliyunMultiModalEmbedRequest request = buildRequest(contents, chatModelVo);
|
||||
AliyunMultiModalEmbedResponse resp = executeRequest(request, chatModelVo);
|
||||
|
||||
return toEmbeddings(resp);
|
||||
} catch (Exception e) {
|
||||
log.error("阿里云文本嵌入失败", e);
|
||||
throw new IllegalArgumentException("阿里云文本嵌入失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单模态嵌入(图片/视频/单条文本)复用方法
|
||||
* @param key 模态类型(image/video/text)
|
||||
* @param dataUrl 数据URL
|
||||
* @return 包含嵌入向量的Response对象
|
||||
*/
|
||||
|
||||
public Response<Embedding> embedSingleModality(String key, String dataUrl) {
|
||||
try {
|
||||
AliyunMultiModalEmbedRequest request = buildRequest(List.of(Map.of(key, dataUrl)), chatModelVo);
|
||||
AliyunMultiModalEmbedResponse resp = executeRequest(request, chatModelVo);
|
||||
|
||||
Response<List<Embedding>> response = toEmbeddings(resp);
|
||||
List<Embedding> embeddings = response.content();
|
||||
|
||||
if (embeddings.isEmpty()) {
|
||||
log.warn("阿里云 {} 嵌入返回为空", key);
|
||||
return Response.from(Embedding.from(new float[0]), response.tokenUsage());
|
||||
}
|
||||
|
||||
return Response.from(embeddings.get(0), response.tokenUsage());
|
||||
} catch (Exception e) {
|
||||
log.error("阿里云 {} 嵌入失败", key, e);
|
||||
throw new IllegalArgumentException("阿里云 " + key + " 嵌入失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建请求对象
|
||||
* @param contents 请求内容列表
|
||||
* @param chatModelVo 模型配置信息
|
||||
* @return 构建好的请求对象
|
||||
*/
|
||||
private AliyunMultiModalEmbedRequest buildRequest(List<Map<String, Object>> contents, ChatModelVo chatModelVo) {
|
||||
if (contents.isEmpty()) throw new IllegalArgumentException("请求内容不能为空");
|
||||
return AliyunMultiModalEmbedRequest.create(chatModelVo.getModelName(), contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行 HTTP 请求并解析响应
|
||||
* @param request 请求对象
|
||||
* @param chatModelVo 模型配置信息
|
||||
* @return API响应对象
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private AliyunMultiModalEmbedResponse executeRequest(AliyunMultiModalEmbedRequest request, ChatModelVo chatModelVo) throws IOException {
|
||||
String jsonBody = request.toJson();
|
||||
RequestBody body = RequestBody.create(jsonBody, MediaType.get("application/json"));
|
||||
|
||||
Request httpRequest = new Request.Builder()
|
||||
.url(chatModelVo.getApiHost())
|
||||
.addHeader("Authorization", "Bearer " + chatModelVo.getApiKey())
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
try (okhttp3.Response response = okHttpClient.newCall(httpRequest).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
String err = response.body() != null ? response.body().string() : "无错误信息";
|
||||
throw new IllegalArgumentException("API调用失败: " + response.code() + " - " + err, null);
|
||||
}
|
||||
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody == null) throw new IllegalArgumentException("响应体为空", null);
|
||||
|
||||
return parseEmbeddingsFromResponse(responseBody.string());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析嵌入向量列表
|
||||
* @param responseBody API响应的JSON字符串
|
||||
* @return 嵌入向量响应对象
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private AliyunMultiModalEmbedResponse parseEmbeddingsFromResponse(String responseBody) throws IOException {
|
||||
ObjectMapper objectMapper1 = new ObjectMapper();
|
||||
return objectMapper1.readValue(responseBody, AliyunMultiModalEmbedResponse.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 API 请求内容 Map
|
||||
* @param input 多模态输入对象
|
||||
* @return 包含各种模态内容的Map列表
|
||||
*/
|
||||
private List<Map<String, Object>> buildContentMap(MultiModalInput input) {
|
||||
List<Map<String, Object>> contents = new ArrayList<>();
|
||||
|
||||
if (input.getText() != null && !input.getText().isBlank()) {
|
||||
contents.add(Map.of("text", input.getText()));
|
||||
}
|
||||
if (input.getImageUrl() != null && !input.getImageUrl().isBlank()) {
|
||||
contents.add(Map.of("image", input.getImageUrl()));
|
||||
}
|
||||
if (input.getVideoUrl() != null && !input.getVideoUrl().isBlank()) {
|
||||
contents.add(Map.of("video", input.getVideoUrl()));
|
||||
}
|
||||
if (input.getMultiImageUrls() != null && input.getMultiImageUrls().length > 0) {
|
||||
contents.add(Map.of("multi_images", Arrays.asList(input.getMultiImageUrls())));
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 API 原始响应解析为 LangChain4j 的 Response<Embedding>
|
||||
* @param resp API原始响应对象
|
||||
* @return 包含嵌入向量和token使用情况的Response对象
|
||||
*/
|
||||
private Response<List<Embedding>> toEmbeddings(AliyunMultiModalEmbedResponse resp) {
|
||||
if (resp == null || resp.output() == null || resp.output().embeddings() == null) {
|
||||
return Response.from(Collections.emptyList());
|
||||
}
|
||||
|
||||
// 转换 double -> float
|
||||
List<Embedding> embeddings = resp.output().embeddings().stream()
|
||||
.map(item -> {
|
||||
float[] vector = new float[item.embedding().size()];
|
||||
for (int i = 0; i < item.embedding().size(); i++) {
|
||||
vector[i] = item.embedding().get(i).floatValue();
|
||||
}
|
||||
return Embedding.from(vector);
|
||||
})
|
||||
.toList();
|
||||
|
||||
// 构建 TokenUsage
|
||||
TokenUsage tokenUsage = null;
|
||||
if (resp.usage() != null) {
|
||||
tokenUsage = new TokenUsage(
|
||||
resp.usage().input_tokens(),
|
||||
resp.usage().image_tokens(),
|
||||
resp.usage().input_tokens() +resp.usage().image_tokens()
|
||||
);
|
||||
}
|
||||
|
||||
return Response.from(embeddings, tokenUsage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
import dev.langchain4j.data.embedding.Embedding;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
import dev.langchain4j.model.ollama.OllamaEmbeddingModel;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.embedding.BaseEmbedModelService;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午3:00
|
||||
* @Description: Ollama嵌入模型
|
||||
*/
|
||||
@Component("ollama")
|
||||
public class OllamaEmbeddingProvider implements BaseEmbedModelService {
|
||||
private ChatModelVo chatModelVo;
|
||||
|
||||
@Override
|
||||
public void configure(ChatModelVo config) {
|
||||
this.chatModelVo = config;
|
||||
}
|
||||
@Override
|
||||
public Set<ModalityType> getSupportedModalities() {
|
||||
return Set.of(ModalityType.TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments) {
|
||||
return OllamaEmbeddingModel.builder()
|
||||
.baseUrl(chatModelVo.getApiHost())
|
||||
.modelName(chatModelVo.getModelName())
|
||||
.build()
|
||||
.embedAll(textSegments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
import dev.langchain4j.data.embedding.Embedding;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.embedding.BaseEmbedModelService;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午3:59
|
||||
* @Description: OpenAi嵌入模型
|
||||
*/
|
||||
@Component("openai")
|
||||
public class OpenAiEmbeddingProvider implements BaseEmbedModelService {
|
||||
protected ChatModelVo chatModelVo;
|
||||
|
||||
@Override
|
||||
public void configure(ChatModelVo config) {
|
||||
this.chatModelVo = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ModalityType> getSupportedModalities() {
|
||||
return Set.of(ModalityType.TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments) {
|
||||
return OpenAiEmbeddingModel.builder()
|
||||
.baseUrl(chatModelVo.getApiHost())
|
||||
.apiKey(chatModelVo.getApiKey())
|
||||
.modelName(chatModelVo.getModelName())
|
||||
.build()
|
||||
.embedAll(textSegments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
|
||||
import org.ruoyi.embedding.BaseEmbedModelService;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午3:59
|
||||
* @Description: 硅基流动(兼容 OpenAi)
|
||||
*/
|
||||
@Component("siliconflow")
|
||||
public class SiliconFlowEmbeddingProvider extends OpenAiEmbeddingProvider {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.ruoyi.embedding.impl;
|
||||
|
||||
import dev.langchain4j.community.model.zhipu.ZhipuAiEmbeddingModel;
|
||||
import dev.langchain4j.data.embedding.Embedding;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import org.ruoyi.domain.vo.ChatModelVo;
|
||||
import org.ruoyi.embedding.BaseEmbedModelService;
|
||||
import org.ruoyi.embedding.model.ModalityType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午4:02
|
||||
* @Description: 智谱AI
|
||||
*/
|
||||
@Component("zhipu")
|
||||
public class ZhiPuAiEmbeddingProvider implements BaseEmbedModelService {
|
||||
private ChatModelVo chatModelVo;
|
||||
|
||||
@Override
|
||||
public void configure(ChatModelVo config) {
|
||||
this.chatModelVo = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ModalityType> getSupportedModalities() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<Embedding>> embedAll(List<TextSegment> textSegments) {
|
||||
return ZhipuAiEmbeddingModel.builder()
|
||||
.baseUrl(chatModelVo.getApiHost())
|
||||
.apiKey(chatModelVo.getApiKey())
|
||||
.model(chatModelVo.getModelName())
|
||||
.build()
|
||||
.embedAll(textSegments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.ruoyi.embedding.model;
|
||||
|
||||
import org.ruoyi.common.json.utils.JsonUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-10-1-上午10:00
|
||||
* @Description: 阿里云多模态嵌入请求
|
||||
*/
|
||||
@Data
|
||||
public class AliyunMultiModalEmbedRequest {
|
||||
private String model;
|
||||
private Input input;
|
||||
|
||||
/**
|
||||
* 表示输入数据的记录类(Record)
|
||||
* 该类用于封装一个包含多个映射关系列表的输入数据结构
|
||||
*
|
||||
* @param contents 包含多个Map的列表,每个Map中存储String类型的键和Object类型的值
|
||||
*/
|
||||
public record Input(List<Map<String, Object>> contents) { }
|
||||
|
||||
/**
|
||||
* 创建请求对象
|
||||
*/
|
||||
public static AliyunMultiModalEmbedRequest create(String modelName, List<Map<String, Object>> contents) {
|
||||
AliyunMultiModalEmbedRequest request = new AliyunMultiModalEmbedRequest();
|
||||
request.setModel(modelName);
|
||||
Input input = new Input(contents);
|
||||
request.setInput(input);
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为JSON字符串
|
||||
*/
|
||||
public String toJson() {
|
||||
return JsonUtils.toJsonString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.ruoyi.embedding.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 阿里云多模态嵌入 API 响应数据模型
|
||||
*/
|
||||
public record AliyunMultiModalEmbedResponse(
|
||||
Output output, // 输出结果对象
|
||||
String request_id, // 请求唯一标识
|
||||
String code, // 错误码
|
||||
String message, // 错误消息
|
||||
Usage usage // 用量信息
|
||||
) {
|
||||
|
||||
/**
|
||||
* 输出对象,包含嵌入向量结果
|
||||
*/
|
||||
public record Output(
|
||||
List<EmbeddingItem> embeddings // 嵌入向量列表
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个嵌入向量条目
|
||||
*/
|
||||
public record EmbeddingItem(
|
||||
int index, // 输入内容的索引
|
||||
List<Double> embedding, // 生成的 1024 维向量
|
||||
String type // 输入的类型 (text/image/video/multi_images)
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用量统计信息
|
||||
*/
|
||||
public record Usage(
|
||||
int input_tokens, // 本次请求输入的 Token 数量
|
||||
int image_tokens, // 本次请求输入的图像 Token 数量
|
||||
int image_count, // 本次请求输入的图像数量
|
||||
int duration // 本次请求输入的视频时长(秒)
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.ruoyi.embedding.model;
|
||||
|
||||
/**
|
||||
* 模态类型
|
||||
*/
|
||||
public enum ModalityType {
|
||||
TEXT, IMAGE, AUDIO, VIDEO, MULTI
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.ruoyi.embedding.model;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: Robust_H
|
||||
* @Date: 2025-09-30-下午2:13
|
||||
* @Description: 多模态输入
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class MultiModalInput {
|
||||
private String text;
|
||||
private byte[] imageData;
|
||||
private byte[] videoData;
|
||||
private String imageMimeType;
|
||||
private String videoMimeType;
|
||||
private String[] multiImageUrls;
|
||||
private String imageUrl;
|
||||
private String videoUrl;
|
||||
|
||||
/**
|
||||
* 检查是否有文本内容
|
||||
*/
|
||||
public boolean hasText() {
|
||||
return StrUtil.isNotBlank(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有图片内容
|
||||
*/
|
||||
public boolean hasImage() {
|
||||
return ArrayUtil.isNotEmpty(imageData) || StrUtil.isNotBlank(imageUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有视频内容
|
||||
*/
|
||||
public boolean hasVideo() {
|
||||
return ArrayUtil.isNotEmpty(videoData) || StrUtil.isNotBlank(videoUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有多图片
|
||||
*/
|
||||
public boolean hasMultiImages() {
|
||||
return ArrayUtil.isNotEmpty(multiImageUrls);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有任何内容
|
||||
*/
|
||||
public boolean hasAnyContent() {
|
||||
return hasText() || hasImage() || hasVideo() || hasMultiImages();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容的数量
|
||||
*/
|
||||
public int getContentCount() {
|
||||
int count = 0;
|
||||
if (hasText()) count++;
|
||||
if (hasImage()) count++;
|
||||
if (hasVideo()) count++;
|
||||
if (hasMultiImages()) count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.ruoyi.common.core.service.ConfigService;
|
||||
import org.ruoyi.domain.bo.QueryVectorBo;
|
||||
import org.ruoyi.domain.bo.StoreEmbeddingBo;
|
||||
import org.ruoyi.embedding.BaseEmbedModelService;
|
||||
import org.ruoyi.embedding.EmbeddingModelFactory;
|
||||
import org.ruoyi.service.VectorStoreService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
@@ -48,6 +50,8 @@ public class VectorStoreServiceImpl implements VectorStoreService {
|
||||
// private EmbeddingStore<TextSegment> embeddingStore;
|
||||
private WeaviateClient client;
|
||||
|
||||
private final EmbeddingModelFactory embeddingModelFactory;
|
||||
|
||||
|
||||
@Override
|
||||
public void createSchema(String kid, String modelName) {
|
||||
@@ -98,18 +102,16 @@ public class VectorStoreServiceImpl implements VectorStoreService {
|
||||
@Override
|
||||
public void storeEmbeddings(StoreEmbeddingBo storeEmbeddingBo) {
|
||||
createSchema(storeEmbeddingBo.getKid(), storeEmbeddingBo.getVectorModelName());
|
||||
EmbeddingModel embeddingModel = getEmbeddingModel(storeEmbeddingBo.getEmbeddingModelName(),
|
||||
storeEmbeddingBo.getApiKey(), storeEmbeddingBo.getBaseUrl());
|
||||
BaseEmbedModelService model = embeddingModelFactory.createModel(storeEmbeddingBo.getEmbeddingModelId());
|
||||
List<String> chunkList = storeEmbeddingBo.getChunkList();
|
||||
List<String> fidList = storeEmbeddingBo.getFids();
|
||||
String kid = storeEmbeddingBo.getKid();
|
||||
String docId = storeEmbeddingBo.getDocId();
|
||||
log.info("向量存储条数记录: " + chunkList.size());
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < chunkList.size(); i++) {
|
||||
String text = chunkList.get(i);
|
||||
String fid = fidList.get(i);
|
||||
Embedding embedding = embeddingModel.embed(text).content();
|
||||
Embedding embedding = model.embed(text).content();
|
||||
Map<String, Object> properties = Map.of(
|
||||
"text", text,
|
||||
"fid",fid,
|
||||
@@ -137,9 +139,8 @@ public class VectorStoreServiceImpl implements VectorStoreService {
|
||||
@Override
|
||||
public List<String> getQueryVector(QueryVectorBo queryVectorBo) {
|
||||
createSchema(queryVectorBo.getKid(), queryVectorBo.getVectorModelName());
|
||||
EmbeddingModel embeddingModel = getEmbeddingModel(queryVectorBo.getEmbeddingModelName(),
|
||||
queryVectorBo.getApiKey(), queryVectorBo.getBaseUrl());
|
||||
Embedding queryEmbedding = embeddingModel.embed(queryVectorBo.getQuery()).content();
|
||||
BaseEmbedModelService model = embeddingModelFactory.createModel(queryVectorBo.getEmbeddingModelId());
|
||||
Embedding queryEmbedding = model.embed(queryVectorBo.getQuery()).content();
|
||||
float[] vector = queryEmbedding.vector();
|
||||
List<String> vectorStrings = new ArrayList<>();
|
||||
for (float v : vector) {
|
||||
@@ -246,28 +247,4 @@ public class VectorStoreServiceImpl implements VectorStoreService {
|
||||
log.error("删除失败: {}", result.getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取向量模型
|
||||
*/
|
||||
@SneakyThrows
|
||||
public EmbeddingModel getEmbeddingModel(String modelName, String apiKey, String baseUrl) {
|
||||
EmbeddingModel embeddingModel;
|
||||
if ("quentinz/bge-large-zh-v1.5".equals(modelName)) {
|
||||
embeddingModel = OllamaEmbeddingModel.builder()
|
||||
.baseUrl(baseUrl)
|
||||
.modelName(modelName)
|
||||
.build();
|
||||
} else if ("baai/bge-m3".equals(modelName)) {
|
||||
embeddingModel = OpenAiEmbeddingModel.builder()
|
||||
.apiKey(apiKey)
|
||||
.baseUrl(baseUrl)
|
||||
.modelName(modelName)
|
||||
.build();
|
||||
} else {
|
||||
throw new ServiceException("未找到对应向量化模型!");
|
||||
}
|
||||
return embeddingModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
74
ruoyi-modules/ruoyi-aihuman/pom.xml
Normal file
74
ruoyi-modules/ruoyi-aihuman/pom.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>ruoyi-aihuman</artifactId>
|
||||
|
||||
<description>
|
||||
aihuman模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<easyexcel.version>3.2.1</easyexcel.version>
|
||||
</properties>
|
||||
|
||||
<!-- 按照用户要求,不添加任何依赖 -->
|
||||
<dependencies>
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--velocity代码生成使用模板 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>easyexcel</artifactId>-->
|
||||
<!-- <version>${easyexcel.version}</version>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.apache.poi</groupId>-->
|
||||
<!-- <artifactId>poi-ooxml-schemas</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-excel</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,125 @@
|
||||
package org.ruoyi.aihuman.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.ruoyi.common.log.annotation.Log;
|
||||
import org.ruoyi.common.web.core.BaseController;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import org.ruoyi.common.log.enums.BusinessType;
|
||||
import org.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanConfigVo;
|
||||
import org.ruoyi.aihuman.domain.bo.AihumanConfigBo;
|
||||
import org.ruoyi.aihuman.service.AihumanConfigService;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 交互数字人配置
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
|
||||
//临时免登录
|
||||
@SaIgnore
|
||||
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/aihuman/aihumanConfig")
|
||||
public class AihumanConfigController extends BaseController {
|
||||
|
||||
private final AihumanConfigService aihumanConfigService;
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置列表
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<AihumanConfigVo> list(AihumanConfigBo bo, PageQuery pageQuery) {
|
||||
return aihumanConfigService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出交互数字人配置列表
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:export")
|
||||
@Log(title = "交互数字人配置", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(AihumanConfigBo bo, HttpServletResponse response) {
|
||||
List<AihumanConfigVo> list = aihumanConfigService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "交互数字人配置", AihumanConfigVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交互数字人配置详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<AihumanConfigVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Integer id) {
|
||||
return R.ok(aihumanConfigService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增交互数字人配置
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:add")
|
||||
@Log(title = "交互数字人配置", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody AihumanConfigBo bo) {
|
||||
return toAjax(aihumanConfigService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改交互数字人配置
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:edit")
|
||||
@Log(title = "交互数字人配置", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody AihumanConfigBo bo) {
|
||||
return toAjax(aihumanConfigService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除交互数字人配置
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("aihuman:aihumanConfig:remove")
|
||||
@Log(title = "交互数字人配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Integer[] ids) {
|
||||
return toAjax(aihumanConfigService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询已发布的交互数字人配置列表
|
||||
* 只返回 publish = 1 的数据
|
||||
*/
|
||||
@GetMapping("/publishedList")
|
||||
public TableDataInfo<AihumanConfigVo> publishedList(PageQuery pageQuery) {
|
||||
// 创建查询条件对象并设置publish=1
|
||||
AihumanConfigBo bo = new AihumanConfigBo();
|
||||
bo.setPublish(1);
|
||||
// 调用现有的查询方法,传入预设了publish=1条件的bo对象
|
||||
return aihumanConfigService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.ruoyi.aihuman.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanInfoVo;
|
||||
import org.ruoyi.aihuman.service.IAihumanInfoService;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI人类交互信息Controller
|
||||
* 免登录接口,方便验证
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
@SaIgnore
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/aihuman/info")
|
||||
public class AihumanInfoController {
|
||||
|
||||
private final IAihumanInfoService aihumanInfoService;
|
||||
|
||||
/**
|
||||
* 获取AI人类交互信息详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AihumanInfoVo> getInfo(@PathVariable Long id) {
|
||||
return R.ok(aihumanInfoService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R<TableDataInfo<AihumanInfoVo>> list(AihumanInfo aihumanInfo, PageQuery pageQuery) {
|
||||
TableDataInfo<AihumanInfoVo> tableDataInfo = aihumanInfoService.queryPageList(aihumanInfo, pageQuery);
|
||||
return R.ok(tableDataInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增AI人类交互信息
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Integer> add(@Validated @RequestBody AihumanInfo aihumanInfo) {
|
||||
return R.ok(aihumanInfoService.insert(aihumanInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改AI人类交互信息
|
||||
*/
|
||||
@PutMapping
|
||||
public R<Integer> edit(@Validated @RequestBody AihumanInfo aihumanInfo) {
|
||||
return R.ok(aihumanInfoService.update(aihumanInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除AI人类交互信息
|
||||
*/
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Integer> remove(@PathVariable Long[] ids) {
|
||||
return R.ok(aihumanInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试接口
|
||||
* 提供一个简单的GET接口用于快速验证控制器是否正常工作
|
||||
*/
|
||||
@GetMapping("/test")
|
||||
public R<String> test() {
|
||||
return R.ok("AI Human Controller is working!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.ruoyi.aihuman.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 交互数字人配置对象 aihuman_config
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
@Data
|
||||
@TableName("aihuman_config")
|
||||
public class AihumanConfig implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* modelName
|
||||
*/
|
||||
private String modelName;
|
||||
|
||||
/**
|
||||
* modelPath
|
||||
*/
|
||||
private String modelPath;
|
||||
|
||||
/**
|
||||
* modelParams
|
||||
*/
|
||||
private String modelParams;
|
||||
|
||||
/**
|
||||
* agentParams
|
||||
*/
|
||||
private String agentParams;
|
||||
|
||||
/**
|
||||
* createTime
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* updateTime
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* status
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
private Integer publish;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.ruoyi.aihuman.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* AI人类交互信息实体类
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
@Data
|
||||
@TableName("aihuman_info")
|
||||
public class AihumanInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 交互名称 */
|
||||
private String name;
|
||||
|
||||
/** 交互内容 */
|
||||
private String content;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.ruoyi.aihuman.domain.bo;
|
||||
|
||||
import org.ruoyi.aihuman.domain.AihumanConfig;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import java.io.Serializable;
|
||||
import java.io.Serializable;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
|
||||
/**
|
||||
* 交互数字人配置业务对象 aihuman_config
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
@Data
|
||||
|
||||
@AutoMapper(target = AihumanConfig.class, reverseConvertGenerate = false)
|
||||
public class AihumanConfigBo implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* modelName
|
||||
*/
|
||||
private String modelName;
|
||||
/**
|
||||
* modelPath
|
||||
*/
|
||||
private String modelPath;
|
||||
/**
|
||||
* modelParams
|
||||
*/
|
||||
private String modelParams;
|
||||
/**
|
||||
* agentParams
|
||||
*/
|
||||
private String agentParams;
|
||||
/**
|
||||
* createTime
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* updateTime
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* status
|
||||
*/
|
||||
@NotNull(message = "status不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Integer status;
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
@NotNull(message = "publish不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Integer publish;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.ruoyi.aihuman.domain.bo;
|
||||
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import java.io.Serializable;
|
||||
import java.io.Serializable;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
|
||||
/**
|
||||
* 数字人信息管理业务对象 aihuman_info
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 20:03:06 GMT+08:00 2025
|
||||
*/
|
||||
@Data
|
||||
|
||||
@AutoMapper(target = AihumanInfo.class, reverseConvertGenerate = false)
|
||||
public class AihumanInfoBo implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 交互名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 交互内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.ruoyi.aihuman.domain.vo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import org.ruoyi.aihuman.domain.AihumanConfig;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.ruoyi.common.excel.annotation.ExcelDictFormat;
|
||||
import org.ruoyi.common.excel.convert.ExcelDictConvert;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 交互数字人配置视图对象 aihuman_config
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = AihumanConfig.class)
|
||||
public class AihumanConfigVo implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
@ExcelProperty(value = "name")
|
||||
private String name;
|
||||
/**
|
||||
* modelName
|
||||
*/
|
||||
@ExcelProperty(value = "modelName")
|
||||
private String modelName;
|
||||
/**
|
||||
* modelPath
|
||||
*/
|
||||
@ExcelProperty(value = "modelPath")
|
||||
private String modelPath;
|
||||
/**
|
||||
* modelParams
|
||||
*/
|
||||
@ExcelProperty(value = "modelParams")
|
||||
private String modelParams;
|
||||
/**
|
||||
* agentParams
|
||||
*/
|
||||
@ExcelProperty(value = "agentParams")
|
||||
private String agentParams;
|
||||
/**
|
||||
* createTime
|
||||
*/
|
||||
@ExcelProperty(value = "createTime")
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* updateTime
|
||||
*/
|
||||
@ExcelProperty(value = "updateTime")
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* status
|
||||
*/
|
||||
@ExcelProperty(value = "status", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_common_status")
|
||||
private Integer status;
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
@ExcelProperty(value = "publish", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_common_status")
|
||||
private Integer publish;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.ruoyi.aihuman.domain.vo;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* AI人类交互信息视图对象
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
@Data
|
||||
@AutoMapper(target = AihumanInfo.class)
|
||||
public class AihumanInfoVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 交互名称 */
|
||||
private String name;
|
||||
|
||||
/** 交互内容 */
|
||||
private String content;
|
||||
|
||||
/** 创建时间 */
|
||||
private Date createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.ruoyi.aihuman.mapper;
|
||||
|
||||
import org.ruoyi.aihuman.domain.AihumanConfig;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanConfigVo;
|
||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 交互数字人配置Mapper接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
@Mapper
|
||||
public interface AihumanConfigMapper extends BaseMapperPlus<AihumanConfig, AihumanConfigVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.ruoyi.aihuman.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanInfoVo;
|
||||
|
||||
/**
|
||||
* AI人类交互信息Mapper接口
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
@Mapper
|
||||
public interface AihumanInfoMapper extends BaseMapperPlus<AihumanInfo, AihumanInfoVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.ruoyi.aihuman.service;
|
||||
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanConfigVo;
|
||||
import org.ruoyi.aihuman.domain.bo.AihumanConfigBo;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 交互数字人配置Service接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
public interface AihumanConfigService {
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置
|
||||
*/
|
||||
AihumanConfigVo queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置列表
|
||||
*/
|
||||
TableDataInfo<AihumanConfigVo> queryPageList(AihumanConfigBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置列表
|
||||
*/
|
||||
List<AihumanConfigVo> queryList(AihumanConfigBo bo);
|
||||
|
||||
/**
|
||||
* 新增交互数字人配置
|
||||
*/
|
||||
Boolean insertByBo(AihumanConfigBo bo);
|
||||
|
||||
/**
|
||||
* 修改交互数字人配置
|
||||
*/
|
||||
Boolean updateByBo(AihumanConfigBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除交互数字人配置信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Integer> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.ruoyi.aihuman.service;
|
||||
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanInfoVo;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI人类交互信息Service接口
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
public interface IAihumanInfoService {
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息
|
||||
*/
|
||||
AihumanInfoVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息列表
|
||||
*/
|
||||
TableDataInfo<AihumanInfoVo> queryPageList(AihumanInfo record, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息列表
|
||||
*/
|
||||
List<AihumanInfoVo> queryList(AihumanInfo record);
|
||||
|
||||
/**
|
||||
* 新增AI人类交互信息
|
||||
*/
|
||||
int insert(AihumanInfo record);
|
||||
|
||||
/**
|
||||
* 修改AI人类交互信息
|
||||
*/
|
||||
int update(AihumanInfo record);
|
||||
|
||||
/**
|
||||
* 批量删除AI人类交互信息
|
||||
*/
|
||||
int deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package org.ruoyi.aihuman.service.impl;
|
||||
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.ruoyi.aihuman.domain.bo.AihumanConfigBo;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanConfigVo;
|
||||
import org.ruoyi.aihuman.domain.AihumanConfig;
|
||||
import org.ruoyi.aihuman.mapper.AihumanConfigMapper;
|
||||
import org.ruoyi.aihuman.service.AihumanConfigService;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 交互数字人配置Service业务层处理
|
||||
*
|
||||
* @author ageerle
|
||||
* @date Fri Sep 26 22:27:00 GMT+08:00 2025
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class AihumanConfigServiceImpl implements AihumanConfigService {
|
||||
|
||||
private final AihumanConfigMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置
|
||||
*/
|
||||
@Override
|
||||
public AihumanConfigVo queryById(Integer id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<AihumanConfigVo> queryPageList(AihumanConfigBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<AihumanConfig> lqw = buildQueryWrapper(bo);
|
||||
Page<AihumanConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询交互数字人配置列表
|
||||
*/
|
||||
@Override
|
||||
public List<AihumanConfigVo> queryList(AihumanConfigBo bo) {
|
||||
LambdaQueryWrapper<AihumanConfig> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<AihumanConfig> buildQueryWrapper(AihumanConfigBo bo) {
|
||||
LambdaQueryWrapper<AihumanConfig> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getName()), AihumanConfig::getName, bo.getName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getModelName()), AihumanConfig::getModelName, bo.getModelName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getModelPath()), AihumanConfig::getModelPath, bo.getModelPath());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getModelParams()), AihumanConfig::getModelParams, bo.getModelParams());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getAgentParams()), AihumanConfig::getAgentParams, bo.getAgentParams());
|
||||
lqw.eq(bo.getCreateTime() != null, AihumanConfig::getCreateTime, bo.getCreateTime());
|
||||
lqw.eq(bo.getUpdateTime() != null, AihumanConfig::getUpdateTime, bo.getUpdateTime());
|
||||
lqw.eq(bo.getStatus() != null, AihumanConfig::getStatus, bo.getStatus());
|
||||
lqw.eq(bo.getPublish() != null, AihumanConfig::getPublish, bo.getPublish());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增交互数字人配置
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(AihumanConfigBo bo) {
|
||||
AihumanConfig add = MapstructUtils.convert(bo, AihumanConfig. class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改交互数字人配置
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(AihumanConfigBo bo) {
|
||||
AihumanConfig update = MapstructUtils.convert(bo, AihumanConfig. class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(AihumanConfig entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除交互数字人配置
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Integer> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package org.ruoyi.aihuman.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.ruoyi.aihuman.domain.AihumanInfo;
|
||||
import org.ruoyi.aihuman.domain.vo.AihumanInfoVo;
|
||||
import org.ruoyi.aihuman.mapper.AihumanInfoMapper;
|
||||
import org.ruoyi.aihuman.service.IAihumanInfoService;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI人类交互信息Service业务层处理
|
||||
*
|
||||
* @author QingYunAI
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class AihumanInfoServiceImpl implements IAihumanInfoService {
|
||||
|
||||
private final AihumanInfoMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息
|
||||
*/
|
||||
@Override
|
||||
public AihumanInfoVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<AihumanInfoVo> queryPageList(AihumanInfo record, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<AihumanInfo> lqw = buildQueryWrapper(record);
|
||||
Page<AihumanInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询AI人类交互信息列表
|
||||
*/
|
||||
@Override
|
||||
public List<AihumanInfoVo> queryList(AihumanInfo record) {
|
||||
LambdaQueryWrapper<AihumanInfo> lqw = buildQueryWrapper(record);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
private LambdaQueryWrapper<AihumanInfo> buildQueryWrapper(AihumanInfo record) {
|
||||
LambdaQueryWrapper<AihumanInfo> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(record.getId() != null, AihumanInfo::getId, record.getId());
|
||||
lqw.like(StringUtils.isNotBlank(record.getName()), AihumanInfo::getName, record.getName());
|
||||
lqw.like(StringUtils.isNotBlank(record.getContent()), AihumanInfo::getContent, record.getContent());
|
||||
lqw.orderByDesc(AihumanInfo::getCreateTime);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增AI人类交互信息
|
||||
*/
|
||||
@Override
|
||||
public int insert(AihumanInfo record) {
|
||||
return baseMapper.insert(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改AI人类交互信息
|
||||
*/
|
||||
@Override
|
||||
public int update(AihumanInfo record) {
|
||||
return baseMapper.updateById(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除AI人类交互信息
|
||||
*/
|
||||
@Override
|
||||
public int deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
// 如果需要逻辑删除,MyBatis-Plus会自动处理
|
||||
// 这里的@TableLogic注解已经在实体类中配置
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666752, '交互数字人配置', '2000', '1', 'aihumanConfig', 'aihuman/aihumanConfig/index', 1, 0, 'C', '0', '0', 'aihuman:aihumanConfig:list', '#', 103, 1, sysdate(), null, null, '交互数字人配置菜单');
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666753, '交互数字人配置查询', 1971582278942666752, '1', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanConfig:query', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666754, '交互数字人配置新增', 1971582278942666752, '2', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanConfig:add', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666755, '交互数字人配置修改', 1971582278942666752, '3', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanConfig:edit', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666756, '交互数字人配置删除', 1971582278942666752, '4', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanConfig:remove', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971582278942666757, '交互数字人配置导出', 1971582278942666752, '5', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanConfig:export', '#', 103, 1, sysdate(), null, null, '');
|
||||
@@ -0,0 +1,19 @@
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597696, '数字人信息管理', '2000', '1', 'aihumanInfo', 'aihuman/aihumanInfo/index', 1, 0, 'C', '0', '0', 'aihuman:aihumanInfo:list', '#', 103, 1, sysdate(), null, null, '数字人信息管理菜单');
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597697, '数字人信息管理查询', 1971546066781597696, '1', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanInfo:query', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597698, '数字人信息管理新增', 1971546066781597696, '2', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanInfo:add', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597699, '数字人信息管理修改', 1971546066781597696, '3', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanInfo:edit', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597700, '数字人信息管理删除', 1971546066781597696, '4', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanInfo:remove', '#', 103, 1, sysdate(), null, null, '');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark)
|
||||
values(1971546066781597701, '数字人信息管理导出', 1971546066781597696, '5', '#', '', 1, 0, 'F', '0', '0', 'aihuman:aihumanInfo:export', '#', 103, 1, sysdate(), null, null, '');
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.ruoyi.aihuman.mapper.AihumanInfoMapper">
|
||||
|
||||
<!-- 可在此添加自定义SQL语句 -->
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.ruoyi.aihuman.mapper.AihumanConfigMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -290,7 +290,7 @@ public class KnowledgeInfoServiceImpl implements IKnowledgeInfoService {
|
||||
.eq(KnowledgeInfo::getId, kid));
|
||||
|
||||
// 通过向量模型查询模型信息
|
||||
ChatModelVo chatModelVo = chatModelService.selectModelByName(knowledgeInfoVo.getEmbeddingModelName());
|
||||
ChatModelVo chatModelVo = chatModelService.queryById(knowledgeInfoVo.getEmbeddingModelId());
|
||||
|
||||
StoreEmbeddingBo storeEmbeddingBo = new StoreEmbeddingBo();
|
||||
storeEmbeddingBo.setKid(kid);
|
||||
@@ -298,7 +298,7 @@ public class KnowledgeInfoServiceImpl implements IKnowledgeInfoService {
|
||||
storeEmbeddingBo.setFids(fids);
|
||||
storeEmbeddingBo.setChunkList(chunkList);
|
||||
storeEmbeddingBo.setVectorModelName(knowledgeInfoVo.getVectorModelName());
|
||||
storeEmbeddingBo.setEmbeddingModelName(knowledgeInfoVo.getEmbeddingModelName());
|
||||
storeEmbeddingBo.setEmbeddingModelId(knowledgeInfoVo.getEmbeddingModelId());
|
||||
storeEmbeddingBo.setApiKey(chatModelVo.getApiKey());
|
||||
storeEmbeddingBo.setBaseUrl(chatModelVo.getApiHost());
|
||||
vectorStoreService.storeEmbeddings(storeEmbeddingBo);
|
||||
|
||||
13
script/sql/update/2025-10-4-多供应商嵌入模型集成.sql
Normal file
13
script/sql/update/2025-10-4-多供应商嵌入模型集成.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- 为 chat_model 表添加 provider_name 字段
|
||||
-- 变更日期: 2025-10-04
|
||||
-- 负责人: Robust_H
|
||||
-- 说明: 嵌入模型供应商 (用于实现动态选择嵌入模型实现类)
|
||||
ALTER TABLE `ruoyi-ai`.chat_model
|
||||
ADD COLUMN `provider_name` varchar(20) DEFAULT NULL COMMENT '模型供应商' AFTER `model_name`;
|
||||
|
||||
-- 修改 knowledge_info 中的 ‘embedding_model_name’ 为 ‘embedding_model_id’
|
||||
-- 变更日期: 2025-10-04
|
||||
-- 负责人: Robust_H
|
||||
-- 说明: 用于区分多个供应商实现同一嵌入模型的情况
|
||||
ALTER TABLE `ruoyi-ai`.knowledge_info
|
||||
ADD COLUMN `embedding_model_id` bigint DEFAULT NULL COMMENT '模型id' AFTER `embedding_model_name`;
|
||||
Reference in New Issue
Block a user