mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-06 00:07:34 +00:00
Compare commits
8 Commits
v2.0.3
...
990da8da6f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
990da8da6f | ||
|
|
8fc7ad0359 | ||
|
|
8a89d9eb9c | ||
|
|
abfa9ae97b | ||
|
|
bde2e8ff8e | ||
|
|
4d8eb1850f | ||
|
|
5aaa3a5662 | ||
|
|
8fec96f5b2 |
33
README.md
33
README.md
@@ -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 |
|
||||
|
||||
通过流程编排功能,用户可以将不同的模型按照业务逻辑进行有序连接。这将解决单一模型能力不足的问题,充分发挥多个模型的协同作用,从而更好地满足企业的复杂业务需求。
|
||||
|
||||
- 感谢
|
||||
|
||||
|
||||
BIN
image/mcp-01.png
BIN
image/mcp-01.png
Binary file not shown.
|
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 227 KiB |
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出套餐管理列表
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.ruoyi.chat.enums;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 描述:
|
||||
* 描述:是否显示
|
||||
*
|
||||
* @author ageerle@163.com
|
||||
* date 2025/4/10
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -80,12 +80,11 @@ 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);
|
||||
@@ -119,7 +118,6 @@ public class SseServiceImpl implements ISseService {
|
||||
count++;
|
||||
RedisUtils.setCacheObject(redisKey, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,8 +143,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();
|
||||
|
||||
@@ -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 返回的嵌入数据
|
||||
|
||||
@@ -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);
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user