10 Commits

19 changed files with 82 additions and 65 deletions

View File

@@ -63,18 +63,19 @@
用户名: admin 密码admin123
### 源码地址
[1]github
- 前端服务-用户端: https://github.com/ageerle/ruoyi-web
- 前端服务-管理端: https://github.com/ageerle/ruoyi-admin
- 前端服务-小程序端: https://github.com/ageerle/ruoyi-uniapp
- 后端服务https://github.com/ageerle/ruoyi-ai
[2]gitee
[1]gitee
- 前端服务-用户端: https://gitee.com/ageerle/ruoyi-web
- 前端服务-管理端: https://gitee.com/ageerle/ruoyi-admin
- 前端服务-小程序端: https://gitee.com/ageerle/ruoyi-uniapp
- 后端服务https://gitee.com/ageerle/ruoyi-ai
[2]github
- 前端服务-用户端: https://github.com/ageerle/ruoyi-web
- 前端服务-管理端: https://github.com/ageerle/ruoyi-admin
- 前端服务-小程序端: https://github.com/ageerle/ruoyi-uniapp
- 后端服务https://github.com/ageerle/ruoyi-ai
[3]gitcode
- 前端服务-用户端https://gitcode.com/ageerle/ruoyi-web
- 前端服务-管理端: https://gitcode.com/ageerle/ruoyi-admin
@@ -83,7 +84,7 @@
### 配套文档
- 配套文档: https://doc.pandarobot.chat
- 项目部署文档https://doc.pandarobot.chat/guide/introduction/
- 项目部署文档https://doc.pandarobot.chat/guide/introduction/
### 核心功能
1. 全套开源系统提供完整的前端应用、后台管理以及小程序应用基于MIT协议开箱即用。
@@ -96,7 +97,16 @@
### 项目演示
#### mcp支持(需要切换dev分支 下周发布正式版)
#### mcp支持
### 如何使用
1. ruoyi-admin\src\main\resources\application.yml中mcp.client.enabled改为true
2. application.yml中配置openai api-key(用于推理使用那个工具,并构建工具所需参数)
3. 启动[ruoyi-mcp-server]
4. [mcp-server.json]中配置fileSystem.command(npx本地安装路径)
5. 指定fileSystem操作目录(本地必须存在指定的目录)
6. 配置search1api.env.SEARCH1API_KEY 申请地址https://www.search1api.com/
7. 详情教程https://blog.csdn.net/weixin_42416319/article/details/147385808
<div style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;">
<img src="image/mcp-01.png" alt="drawing" style="width: 600px; height: 300px; border: 2px solid #ddd; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);"/>
<img src="image/mcp-02.png" alt="drawing" style="width: 600px; height: 300px; border: 2px solid #ddd; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);"/>
@@ -215,9 +225,12 @@
### 开发计划
- 流程编排
| 主题 | 方向 | 时间节点 |
| --- |-----------------------------------|--------|
| 前端简化版 | 与element-plus-x框架合作推出基于该框架的前端简化版 | 2025.5 |
| agent2agent | Agent2Agent协议支持 | 2025.6 |
| 流程编排 | 通过可视化界面和灵活的配置方式快速构建AI应用 | 2025.7 |
通过流程编排功能,用户可以将不同的模型按照业务逻辑进行有序连接。这将解决单一模型能力不足的问题,充分发挥多个模型的协同作用,从而更好地满足企业的复杂业务需求。
- 感谢

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 KiB

After

Width:  |  Height:  |  Size: 227 KiB

View File

@@ -42,12 +42,6 @@
<artifactId>mssql-jdbc</artifactId>
</dependency>
<!-- demo模块 -->
<!-- <dependency>-->
<!-- <groupId>org.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-demo</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
@@ -58,6 +52,12 @@
<artifactId>ruoyi-chat</artifactId>
</dependency>
<dependency>
<groupId>org.ruoyi</groupId>
<artifactId>ruoyi-generator</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -25,7 +25,7 @@ spring:
master:
type: ${spring.datasource.type}
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://43.139.70.230:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
url: jdbc:mysql://127.0.0.1:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
username: ry-vue
password: xx

View File

@@ -323,11 +323,11 @@ wechat:
spring:
ai:
openai:
api-key: sk-xxx
api-key: sk-xx
base-url: https://api.pandarobot.chat/
mcp:
client:
enabled: true
enabled: false
name: ruoyi-ai-mcp
sse:
connections:
@@ -335,4 +335,5 @@ spring:
url: http://127.0.0.1:8081
stdio:
servers-configuration: classpath:mcp-server.json
request-timeout: 300s

View File

@@ -21,7 +21,7 @@ import jakarta.validation.constraints.*;
public class KnowledgeInfoBo extends BaseEntity {
/**
*
* 主键
*/
@NotNull(message = "不能为空", groups = { EditGroup.class })
private Long id;
@@ -29,13 +29,13 @@ public class KnowledgeInfoBo extends BaseEntity {
/**
* 知识库ID
*/
@NotBlank(message = "知识库ID不能为空", groups = { AddGroup.class, EditGroup.class })
@NotBlank(message = "知识库ID不能为空", groups = {EditGroup.class })
private String kid;
/**
* 用户ID
*/
@NotNull(message = "用户ID不能为空", groups = { AddGroup.class, EditGroup.class })
@NotNull(message = "用户ID不能为空", groups = {EditGroup.class })
private Long uid;
/**
@@ -53,25 +53,21 @@ public class KnowledgeInfoBo extends BaseEntity {
/**
* 描述
*/
@NotBlank(message = "描述不能为空", groups = { AddGroup.class, EditGroup.class })
private String description;
/**
* 知识分隔符
*/
@NotBlank(message = "知识分隔符不能为空", groups = { AddGroup.class, EditGroup.class })
private String knowledgeSeparator;
/**
* 提问分隔符
*/
@NotBlank(message = "提问分隔符不能为空", groups = { AddGroup.class, EditGroup.class })
private String questionSeparator;
/**
* 重叠字符数
*/
@NotNull(message = "重叠字符数不能为空", groups = { AddGroup.class, EditGroup.class })
private Long overlapChar;
/**
@@ -101,8 +97,6 @@ public class KnowledgeInfoBo extends BaseEntity {
/**
* 备注
*/
@NotBlank(message = "备注不能为空", groups = { AddGroup.class, EditGroup.class })
private String remark;
}

View File

@@ -75,12 +75,19 @@ public class ChatConfigController extends BaseController {
/**
* 新增配置信息
*/
@SaCheckPermission("system:config:add")
@Log(title = "配置信息", businessType = BusinessType.INSERT)
@SaCheckPermission("system:config:edit")
@Log(title = "新增或者修改配置信息", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody ChatConfigBo bo) {
return toAjax(chatConfigService.insertByBo(bo));
@PostMapping("/saveOrUpdate")
public R<Void> saveOrUpdate(@RequestBody List<ChatConfigBo> boList) {
for (ChatConfigBo chatConfigBo : boList) {
if(chatConfigBo.getId() == null){
chatConfigService.insertByBo(chatConfigBo);
}else {
chatConfigService.updateByBo(chatConfigBo);
}
}
return toAjax(true);
}
/**

View File

@@ -39,7 +39,6 @@ public class ChatGptsController extends BaseController {
/**
* 查询应用管理列表
*/
@SaCheckPermission("system:gpts:list")
@GetMapping("/list")
public TableDataInfo<ChatGptsVo> list(ChatGptsBo bo, PageQuery pageQuery) {
return chatGptsService.queryPageList(bo, pageQuery);

View File

@@ -45,6 +45,14 @@ public class ChatPackagePlanController extends BaseController {
return chatPackagePlanService.queryPageList(bo, pageQuery);
}
/**
* 查询套餐列表-不分页
*/
@GetMapping("/listPlan")
public R<List<ChatPackagePlanVo>> listPlan() {
return R.ok(chatPackagePlanService.queryList(new ChatPackagePlanBo()));
}
/**
* 导出套餐管理列表
*/

View File

@@ -4,8 +4,8 @@ import lombok.Getter;
@Getter
public enum BillingType {
TOKEN("1", "token扣费"), // token扣费
TIMES("2", "次数扣费"); // 次数扣费
TOKEN("1", "token扣费"),
TIMES("2", "次数扣费");
private final String code;
private final String description;

View File

@@ -4,9 +4,9 @@ import lombok.Getter;
@Getter
public enum ChatModeType {
OLLAMA("ollama", "本地部署模型"), // token扣费
CHAT("chat", "中转模型"), // 次数扣费
VECTOR("vector", "知识库向量模型"); // 次数扣费
OLLAMA("ollama", "本地部署模型"),
CHAT("chat", "中转模型"),
VECTOR("vector", "知识库向量模型");
private final String code;
private final String description;
@@ -16,11 +16,4 @@ public enum ChatModeType {
this.description = description;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
}

View File

@@ -3,7 +3,7 @@ package org.ruoyi.chat.enums;
import lombok.Getter;
/**
* 描述:
* 描述:是否显示
*
* @author ageerle@163.com
* date 2025/4/10

View File

@@ -12,6 +12,7 @@ import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
import org.jetbrains.annotations.NotNull;
import org.ruoyi.chat.service.chat.IChatCostService;
import org.ruoyi.chat.util.SSEUtil;
import org.ruoyi.common.chat.entity.chat.ChatCompletionResponse;
import org.ruoyi.common.chat.request.ChatRequest;
import org.ruoyi.common.core.utils.SpringUtils;
@@ -84,10 +85,10 @@ public class SSEEventSourceListener extends EventSourceListener {
modelName = completionResponse.getModel();
}
stringBuffer.append(content);
emitter.send(content);
emitter.send(data);
}
} catch (Exception e) {
emitter.completeWithError(e);
log.error(e.getMessage(), e);
}
}

View File

@@ -15,6 +15,7 @@ import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.util.List;
@@ -29,6 +30,10 @@ public class OpenAIServiceImpl implements IChatService {
private OpenAiStreamClient openAiStreamClient;
@Value("${spring.ai.mcp.client.enabled}")
private Boolean enabled;
private final ChatClient chatClient;
public OpenAIServiceImpl(ChatClient.Builder chatClientBuilder, List<McpSyncClient> mcpSyncClients) {
@@ -43,10 +48,12 @@ public class OpenAIServiceImpl implements IChatService {
public SseEmitter chat(ChatRequest chatRequest,SseEmitter emitter) {
ChatModelVo chatModelVo = chatModelService.selectModelByName(chatRequest.getModel());
openAiStreamClient = ChatConfig.createOpenAiStreamClient(chatModelVo.getApiHost(), chatModelVo.getApiKey());
String toolString = mcpChat(chatRequest.getPrompt());
Message userMessage = Message.builder().content("工具返回信息:"+toolString).role(Message.Role.USER).build();
List<Message> messages = chatRequest.getMessages();
messages.add(userMessage);
if (enabled) {
String toolString = mcpChat(chatRequest.getPrompt());
Message userMessage = Message.builder().content("工具返回信息:"+toolString).role(Message.Role.USER).build();
messages.add(userMessage);
}
SSEEventSourceListener listener = new SSEEventSourceListener(emitter);
ChatCompletion completion = ChatCompletion
.builder()

View File

@@ -11,6 +11,7 @@ import org.ruoyi.chat.enums.ChatModeType;
import org.ruoyi.chat.service.chat.IChatCostService;
import org.ruoyi.chat.service.chat.ISseService;
import org.ruoyi.chat.util.IpUtil;
import org.ruoyi.chat.util.SSEUtil;
import org.ruoyi.common.chat.config.LocalCache;
import org.ruoyi.common.chat.entity.Tts.TextToSpeech;
import org.ruoyi.common.chat.entity.chat.ChatCompletion;
@@ -80,16 +81,15 @@ public class SseServiceImpl implements ISseService {
checkUnauthenticatedUserChatLimit(request);
}else {
LocalCache.CACHE.put("userId", chatCostService.getUserId());
chatRequest.setUserId(chatCostService.getUserId());
// 保存消息记录 并扣除费用
chatCostService.deductToken(chatRequest);
}
// 根据模型名称前缀调用不同的处理逻辑
// 根据模型分类调用不同的处理逻辑
switchModelAndHandle(chatRequest,sseEmitter);
} catch (Exception e) {
log.error(e.getMessage(),e);
sseEmitter.completeWithError(e);
SSEUtil.sendErrorEvent(sseEmitter,e.getMessage());
}
return sseEmitter;
}
@@ -119,7 +119,6 @@ public class SseServiceImpl implements ISseService {
count++;
RedisUtils.setCacheObject(redisKey, count);
}
}
/**
@@ -145,8 +144,7 @@ public class SseServiceImpl implements ISseService {
if(StringUtils.isEmpty(sysPrompt)){
sysPrompt ="你是一个由RuoYI-AI开发的人工智能助手名字叫熊猫助手。你擅长中英文对话能够理解并处理各种问题提供安全、有帮助、准确的回答。" +
"当前时间:"+ DateUtils.getDate()+
"#注意:回复之前注意结合上下文和工具返回内容。";
"#注意:回复之前注意结合上下文和工具返回内容进行回复";
}
// 设置系统默认提示词
Message sysMessage = Message.builder().content(sysPrompt).role(Message.Role.SYSTEM).build();

View File

@@ -53,7 +53,7 @@ public class OpenAiVectorizationImpl implements VectorizationService {
ChatModelVo chatModelVo = chatModelService.selectModelByName(knowledgeInfoVo.getVectorModel());
String apiHost= chatModelVo.getApiHost();
String apiKey= chatModelVo.getApiKey();
openAiStreamClient = chatConfig.createOpenAiStreamClient(apiHost,apiKey);
openAiStreamClient = ChatConfig.createOpenAiStreamClient(apiHost,apiKey);
Embedding embedding = buildEmbedding(chunkList, knowledgeInfoVo);
EmbeddingResponse embeddings = openAiStreamClient.embeddings(embedding);
// 处理 OpenAI 返回的嵌入数据

View File

@@ -21,11 +21,8 @@ public class SSEUtil {
* @param errorMessage 错误信息
*/
public static void sendErrorEvent(ResponseBodyEmitter sseEmitter, String errorMessage) {
SseEmitter.SseEventBuilder event = SseEmitter.event()
.name("error")
.data(errorMessage);
try {
sseEmitter.send(event);
sseEmitter.send(errorMessage);
} catch (IOException e) {
log.error("SSE发送失败: {}", e.getMessage());
}

View File

@@ -1 +0,0 @@
INSERT INTO `chat_app_store` (`id`, `name`, `description`, `avatar`, `app_url`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (7, '微信机器人', '微信机器人', 'https://panda-1253683406.cos.ap-guangzhou.myqcloud.com/panda/2025/04/02/0557a7d68fa842bba952ce0d6ef38a2e.png', '/wxbot', NULL, NULL, NULL, NULL, NULL, NULL);

View File

@@ -1,4 +1,4 @@
INSERT INTO `chat_model` (`id`, `tenant_id`, `category`, `model_name`, `model_describe`, `model_price`, `model_type`, `model_show`, `system_prompt`, `api_host`, `api_key`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1907575746601119746, '000000', 'vector', 'text-embedding-3-small', 'text-embedding-3-small', 0, '2', '0', NULL, 'https://api.pandarobot.chat/', 'sk-cdBlIaZcufccm2RaDe547cBd054d49C7B0782eCa72A0052b', 103, 1, '2025-04-03 07:27:54', 1, '2025-04-03 07:27:54', 'text-embedding-3-small');
INSERT INTO `chat_model` (`id`, `tenant_id`, `category`, `model_name`, `model_describe`, `model_price`, `model_type`, `model_show`, `system_prompt`, `api_host`, `api_key`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1907576007017066497, '000000', 'vector', 'quentinz/bge-large-zh-v1.5', 'bge-large-zh-v1.5', 0, '2', '0', NULL, 'https://api.pandarobot.chat/', 'cdBlIaZcufccm2RaDe547cBd054d49C7B0782eCa72A0052b', 103, 1, '2025-04-03 07:28:56', 1, '2025-04-03 07:28:56', 'bge-large-zh-v1.5');
INSERT INTO `chat_model` (`id`, `tenant_id`, `category`, `model_name`, `model_describe`, `model_price`, `model_type`, `model_show`, `system_prompt`, `api_host`, `api_key`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1907576007017066497, '000000', 'vector', 'quentinz/bge-large-zh-v1.5', 'bge-large-zh-v1.5', 0, '2', '0', NULL, 'http://127.0.0.1:11434/', 'cdBlIaZcufccm2RaDe547cBd054d49C7B0782eCa72A0052b', 103, 1, '2025-04-03 07:28:56', 1, '2025-04-03 07:28:56', 'bge-large-zh-v1.5');
INSERT INTO `chat_model` (`id`, `tenant_id`, `category`, `model_name`, `model_describe`, `model_price`, `model_type`, `model_show`, `system_prompt`, `api_host`, `api_key`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1907576806191362049, '000000', 'vector', 'nomic-embed-text', 'nomic-embed-text', 0, '2', '0', NULL, 'http://127.0.0.1:11434/', 'nomic-embed-text', 103, 1, '2025-04-03 07:32:06', 1, '2025-04-03 07:32:06', 'nomic-embed-text');
INSERT INTO `chat_model` (`id`, `tenant_id`, `category`, `model_name`, `model_describe`, `model_price`, `model_type`, `model_show`, `system_prompt`, `api_host`, `api_key`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1907577073490161665, '000000', 'vector', 'snowflake-arctic-embed', 'snowflake-arctic-embed', 0, '2', '0', NULL, 'http://127.0.0.1:11434/', 'snowflake-arctic-embed', 103, 1, '2025-04-03 07:33:10', 1, '2025-04-03 07:33:10', 'snowflake-arctic-embed');