Compare commits
29 Commits
761d954ef1
...
v2.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5476a4b0b7 | ||
|
|
cd490aa0e5 | ||
|
|
b1ff44df4b | ||
|
|
dc6d00f0fc | ||
|
|
990da8da6f | ||
|
|
8fc7ad0359 | ||
|
|
8a89d9eb9c | ||
|
|
abfa9ae97b | ||
|
|
bde2e8ff8e | ||
|
|
4d8eb1850f | ||
|
|
5aaa3a5662 | ||
|
|
8fec96f5b2 | ||
|
|
15c306eca2 | ||
|
|
620ea1fc76 | ||
|
|
c5c375dc6d | ||
|
|
1b793e822a | ||
|
|
6281840f36 | ||
|
|
f5daa7eb78 | ||
|
|
52cb563383 | ||
|
|
69efc3261e | ||
|
|
fb19fb29cc | ||
|
|
9f257cf712 | ||
|
|
4af26fe4b4 | ||
|
|
ab2a118ee9 | ||
|
|
9cd97a4dc5 | ||
|
|
788b372e32 | ||
|
|
744f9b6c7f | ||
|
|
b50c15755d | ||
|
|
09abc0b5af |
142
README.md
@@ -36,48 +36,85 @@
|
||||
|
||||
## 目录
|
||||
|
||||
- [系统体验](#系统体验)
|
||||
- [源码地址](#源码地址)
|
||||
- [特色功能](#特色功能)
|
||||
- [配套文档](#项目文档)
|
||||
- [核心功能](#核心功能)
|
||||
- [项目演示](#项目演示)
|
||||
- [后台管理](#后台管理)
|
||||
- [管理端](#管理端)
|
||||
- [用户端](#用户端)
|
||||
- [小程序端](#小程序端)
|
||||
- [开发前的配置要求](#开发前的配置要求)
|
||||
- [文件目录说明](#文件目录说明)
|
||||
- [使用到的框架](#使用到的框架)
|
||||
- [开发环境](#开发环境)
|
||||
- [项目结构](#项目结构)
|
||||
- [ruoyi-ai](#ruoyi-ai)
|
||||
- [注意事项](#注意事项)
|
||||
- [vben模板](#vben模板)
|
||||
- [贡献者](#贡献者)
|
||||
- [如何参与开源项目](#如何参与开源项目)
|
||||
- [版本控制](#版本控制)
|
||||
- [作者](#作者)
|
||||
- [鸣谢](#鸣谢)
|
||||
- [技术讨论群](#技术讨论群)
|
||||
|
||||
### 系统体验
|
||||
- 用户端:https://web.pandarobot.chat
|
||||
- 管理端:https://admin.pandarobot.chat
|
||||
|
||||
用户名: admin 密码:admin123
|
||||
|
||||
### 源码地址
|
||||
- 项目文档: https://doc.pandarobot.chat
|
||||
- 前端-后台管理: https://github.com/ageerle/ruoyi-admin
|
||||
- 前端-用户端: https://github.com/ageerle/ruoyi-web
|
||||
- 小程序端: https://github.com/ageerle/ruoyi-uniapp
|
||||
- 演示地址: https://web.pandarobot.chat
|
||||
- 后台管理: https://admin.pandarobot.chat
|
||||
- 用户名: admin 密码:admin123
|
||||
|
||||
### gitcode源码地址
|
||||
- https://gitcode.com/ageerle/ruoyi-ai
|
||||
- https://gitcode.com/ageerle/ruoyi-web
|
||||
- https://gitcode.com/ageerle/ruoyi-admin
|
||||
- https://gitcode.com/ageerle/ruoyi-uniapp
|
||||
[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
|
||||
- 前端服务-小程序端: https://gitcode.com/ageerle/ruoyi-uniapp
|
||||
- 后端服务:https://gitcode.com/ageerle/ruoyi-ai
|
||||
|
||||
### 配套文档
|
||||
- 配套文档: https://doc.pandarobot.chat
|
||||
- 项目部署文档:https://doc.pandarobot.chat/guide/introduction/
|
||||
|
||||
### 核心功能
|
||||
1. 全套开源系统:提供完整的前端应用、后台管理以及小程序应用,基于MIT协议,开箱即用。
|
||||
2. 本地RAG方案:集成Milvus/Weaviate向量库、本地向量化模型与Ollama,实现本地化RAG
|
||||
2. 本地RAG方案:集成Milvus/Weaviate向量库、本地向量化模型与Ollama,实现本地化RAG。
|
||||
3. 丰富插件功能:支持联网、SQL查询插件及Text2API插件,扩展系统能力与应用场景。
|
||||
4. 内置SSE、websocket等网络协议,支持对接多种大语言模型,同时还集成了MidJourney和DALLE AI绘画功能
|
||||
5. 强大的多媒体功能:支持AI翻译、PPT制作、语音克隆和翻唱等
|
||||
6. 扩展功能:支持将大模型接入个人或企业微信
|
||||
7. 支付功能:支持易支付、微信支付等多种支付方式
|
||||
4. 内置SSE、websocket等网络协议,支持对接多种大语言模型,同时还集成了MidJourney和DALLE AI绘画功能。
|
||||
5. 强大的多媒体功能:支持AI翻译、PPT制作、语音克隆和翻唱等。
|
||||
6. 扩展功能:支持将大模型接入个人或企业微信。
|
||||
7. 支付功能:支持易支付、微信支付等多种支付方式。
|
||||
|
||||
### 项目演示
|
||||
|
||||
#### 后台管理
|
||||
#### 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);"/>
|
||||
<img src="image/mcp-03.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-04.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);"/>
|
||||
</div>
|
||||
|
||||
#### 管理端
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;">
|
||||
<img src="image/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);"/>
|
||||
<img src="image/03.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);"/>
|
||||
@@ -100,7 +137,7 @@
|
||||
<img src="image/07.png" alt="drawing" style="width: 320px; height: 600px; border: 2px solid #ddd; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);"/>
|
||||
</div>
|
||||
|
||||
### 开发前的配置要求
|
||||
### 开发环境
|
||||
|
||||
1. jdk 17
|
||||
2. mysql 5.7、8.0
|
||||
@@ -108,8 +145,14 @@
|
||||
4. maven 3.8+
|
||||
5. nodejs 20+ & pnpm
|
||||
|
||||
### 文件目录说明
|
||||
RuoYi-AI
|
||||
- 附-部署配套视频:https://www.bilibili.com/video/BV1jDXkYWEba
|
||||
|
||||
<div>
|
||||
<img src="image/教程搭建.png" alt="drawing" width="600px" height="300px"/>
|
||||
</div>
|
||||
|
||||
### 项目结构
|
||||
- RuoYi-AI
|
||||
|
||||
```
|
||||
├─ ruoyi-admin // 管理模块
|
||||
@@ -158,6 +201,14 @@ RuoYi-AI
|
||||
|
||||
```
|
||||
|
||||
### 注意事项
|
||||
- vben模板
|
||||
|
||||
|
||||
Q:vben5 的模板默认是没有的吗?
|
||||
|
||||
A:vben模板是收费的 请联系vben-vue-plus作者获取。
|
||||
|
||||
### 版本控制
|
||||
|
||||
该项目使用Git进行版本管理。您可以在repository参看当前可用版本。
|
||||
@@ -170,20 +221,16 @@ RuoYi-AI
|
||||
|
||||
### 项目现状
|
||||
|
||||
目前,项目还处于早期阶段,距离成熟还有很长的路要走。由于个人精力有限,项目的发展速度受到了一定的限制。为了加快项目的进度,我真诚地希望更多人能够参与到项目中来。无论是经验丰富的开发者,还是刚刚入门的小白,我都热烈欢迎你们提交Pull Request(PR)。即使代码修改得很少,或者存在一些错误,都没有关系。我会认真审核每一位贡献者的代码,并和大家一起完善项目。
|
||||
目前,项目还处于早期阶段,距离成熟还有很长的路要走。由于个人精力有限,项目的发展速度受到了一定的限制。为了加快项目的进度,我真诚地希望更多人能够参与到项目中来。无论是经验丰富的开发者,还是刚刚入门的小白,我都热烈欢迎你们提交Pull Request(PR)👏👏👏。即使代码修改得很少,或者存在一些错误,都没有关系。我会认真审核每一位贡献者的代码,并和大家一起完善项目⛽️⛽️⛽️。
|
||||
|
||||
### 开发计划
|
||||
|
||||
- 智能体管理
|
||||
| 主题 | 方向 | 时间节点 |
|
||||
| --- |-----------------------------------|--------|
|
||||
| 前端简化版 | 与element-plus-x框架合作,推出基于该框架的前端简化版 | 2025.5 |
|
||||
| agent2agent | Agent2Agent协议支持 | 2025.6 |
|
||||
| 流程编排 | 通过可视化界面和灵活的配置方式,快速构建AI应用 | 2025.7 |
|
||||
|
||||
通过设置提示词、插件、知识库等,用户可以快速构建一个AI应用。这将极大地简化AI应用的开发流程,降低开发门槛,使更多企业能够轻松地利用AI技术。
|
||||
<div>
|
||||
<img src="image/13.png" alt="drawing" width="600px" height="300px"/>
|
||||
</div>
|
||||
|
||||
- 流程编排
|
||||
|
||||
通过流程编排功能,用户可以将不同的模型按照业务逻辑进行有序连接。这将解决单一模型能力不足的问题,充分发挥多个模型的协同作用,从而更好地满足企业的复杂业务需求。
|
||||
|
||||
- 感谢
|
||||
|
||||
@@ -193,7 +240,7 @@ RuoYi-AI
|
||||
|
||||
#### 如何参与开源项目
|
||||
|
||||
贡献使开源社区成为一个学习、激励和创造的绝佳场所。你所作的任何贡献都是**非常感谢**的。
|
||||
贡献使开源社区成为一个学习、激励和创造的绝佳场所。你所作的任何贡献,我们都非常感谢!🙏
|
||||
|
||||
1. Fork 这个项目
|
||||
2. 创建你的功能分支 (`git checkout -b feature/dev`)
|
||||
@@ -231,4 +278,23 @@ RuoYi-AI
|
||||
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
|
||||
|
||||
|
||||
### 附:技术讨论群
|
||||
|
||||
#### 全面开放,欢迎加入
|
||||
🏠 wx:ruoyi-ai(加人备注:ruoyi-ai)
|
||||
|
||||
🏠 qq:1603234088 (加人备注:ruoyi-ai)
|
||||
|
||||
👏👏👏 ruoyi-ai官方交流1群(qq区):1034554687
|
||||
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;">
|
||||
<img src="image/QQ区-官方交流1群.png" alt="drawing" style="width: 400px; height: 400px; border: 2px solid #ddd; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);"/>
|
||||
</div>
|
||||
|
||||
👏👏👏 ruoyi-ai官方交流4群(微信区):
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;">
|
||||
<img src="image/WX区-官方交流4群.jpg" alt="drawing" style="width: 400px; height: 400px; border: 2px solid #ddd; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);"/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
image/QQ区-官方交流1群.png
Normal file
|
After Width: | Height: | Size: 214 KiB |
BIN
image/WX区-官方交流4群.jpg
Normal file
|
After Width: | Height: | Size: 310 KiB |
BIN
image/mcp-01.png
Normal file
|
After Width: | Height: | Size: 227 KiB |
BIN
image/mcp-02.png
Normal file
|
After Width: | Height: | Size: 251 KiB |
BIN
image/mcp-03.png
Normal file
|
After Width: | Height: | Size: 189 KiB |
BIN
image/mcp-04.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
image/qq-msg.png
Normal file
|
After Width: | Height: | Size: 391 KiB |
BIN
image/wx-msg.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
image/wx-msg2.png
Normal file
|
After Width: | Height: | Size: 148 KiB |
BIN
image/教程搭建.png
Normal file
|
After Width: | Height: | Size: 341 KiB |
10
pom.xml
@@ -337,11 +337,11 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.ruoyi</groupId>-->
|
||||
<!-- <artifactId>ruoyi-demo</artifactId>-->
|
||||
<!-- <version>${revision}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-wechat</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -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,16 @@
|
||||
<artifactId>ruoyi-chat</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-generator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-wechat</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -63,6 +63,8 @@ public class AuthController {
|
||||
body.getUsername(), body.getPassword(),
|
||||
body.getCode(), body.getUuid());
|
||||
loginVo.setToken(token);
|
||||
// 兼容后台管理登录
|
||||
loginVo.setAccess_token(token);
|
||||
loginVo.setUserInfo(LoginHelper.getLoginUser());
|
||||
return R.ok(loginVo);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -320,4 +320,20 @@ wechat:
|
||||
token: ''
|
||||
aesKey: ''
|
||||
|
||||
spring:
|
||||
ai:
|
||||
openai:
|
||||
api-key: sk-xx
|
||||
base-url: https://api.pandarobot.chat/
|
||||
mcp:
|
||||
client:
|
||||
enabled: false
|
||||
name: ruoyi-ai-mcp
|
||||
sse:
|
||||
connections:
|
||||
server:
|
||||
url: http://127.0.0.1:8081
|
||||
stdio:
|
||||
servers-configuration: classpath:mcp-server.json
|
||||
request-timeout: 300s
|
||||
|
||||
|
||||
22
ruoyi-admin/src/main/resources/mcp-server.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"fileSystem": {
|
||||
"command": "C:\\Program Files\\nodejs\\npx.cmd",
|
||||
"args": [
|
||||
"-y",
|
||||
"@modelcontextprotocol/server-filesystem",
|
||||
"D:\\"
|
||||
]
|
||||
},
|
||||
"search1api": {
|
||||
"command": "C:\\Program Files\\nodejs\\npx.cmd",
|
||||
"args": [
|
||||
"-y",
|
||||
"search1api-mcp"
|
||||
],
|
||||
"env": {
|
||||
"SEARCH1API_KEY": "xx"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>ruoyi-ai-mcp-webflux-server</module>
|
||||
<module>ruoyi-mcp-server</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.ivy.mcp</groupId>
|
||||
<artifactId>ruoyi-ai-mcp-webflux-server</artifactId>
|
||||
<version>1.0.0-M6</version>
|
||||
|
||||
<name>spring-ai-mcp-webflux-server</name>
|
||||
<description>Spring AI MCP Server example and invoke by stdio</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-ai.version>1.0.0-M6</spring-ai.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-bom</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-server-webflux-spring-boot-starter</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<name>Central Portal Snapshots</name>
|
||||
<id>central-portal-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.ivy.mcp.sse.client;
|
||||
|
||||
|
||||
import io.modelcontextprotocol.client.McpClient;
|
||||
import io.modelcontextprotocol.client.transport.WebFluxSseClientTransport;
|
||||
import io.modelcontextprotocol.spec.McpSchema;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientWebflux {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
var transport = new WebFluxSseClientTransport(WebClient.builder().baseUrl("http://localhost:8080"));
|
||||
try (var client = McpClient.sync(transport).build()) {
|
||||
|
||||
client.initialize();
|
||||
// client.ping();
|
||||
|
||||
McpSchema.ListToolsResult toolsList = client.listTools();
|
||||
System.out.println("Available Tools = " + toolsList);
|
||||
|
||||
McpSchema.CallToolResult sumResult = client.callTool(new McpSchema.CallToolRequest("add",
|
||||
Map.of("a", 1, "b", 2)));
|
||||
System.out.println("add a+ b = " + sumResult.content().get(0));
|
||||
|
||||
|
||||
McpSchema.CallToolResult currentTimResult = client.callTool(new McpSchema.CallToolRequest("getCurrentTime", Map.of()));
|
||||
System.out.println("current time Response = " + currentTimResult);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.ivy.mcp.sse.server;
|
||||
|
||||
import org.springframework.ai.tool.ToolCallback;
|
||||
import org.springframework.ai.tool.ToolCallbacks;
|
||||
import org.springframework.ai.tool.annotation.Tool;
|
||||
import org.springframework.ai.tool.annotation.ToolParam;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
public class McpWebfluxServerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(McpWebfluxServerApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public List<ToolCallback> tools(MyTools myTools) {
|
||||
return List.of(ToolCallbacks.from(myTools));
|
||||
}
|
||||
|
||||
@Service
|
||||
public static class MyTools {
|
||||
|
||||
@Tool(description = "add two numbers")
|
||||
public Integer add(@ToolParam(description = "first number") int a,
|
||||
@ToolParam(description = "second number") int b) {
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@Tool(description = "get current time")
|
||||
public LocalDateTime getCurrentTime() {
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
spring.main.banner-mode=off
|
||||
logging.pattern.console=
|
||||
logging.file.name=mcp-server/spring-ai-mcp-webflux-server/target/target/mcp.mytools.log
|
||||
|
||||
spring.ai.mcp.server.enabled=true
|
||||
spring.ai.mcp.server.name=webflux-server
|
||||
spring.ai.mcp.server.version=1.0.0
|
||||
76
ruoyi-extend/ruoyi-mcp-server/pom.xml
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-mcp-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>ruoyi-mcp-serve</name>
|
||||
<description>ruoyi-mcp-serve</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-ai.version>1.0.0-M7</spring-ai.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-bom</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.ruoyi.mcpserve;
|
||||
|
||||
import org.ruoyi.mcpserve.service.ToolService;
|
||||
import org.springframework.ai.tool.ToolCallbackProvider;
|
||||
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* @author ageer
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RuoyiMcpServeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RuoyiMcpServeApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ToolCallbackProvider systemTools(ToolService toolService) {
|
||||
return MethodToolCallbackProvider.builder().toolObjects(toolService).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.ruoyi.mcpserve.service;
|
||||
|
||||
import org.springframework.ai.tool.annotation.Tool;
|
||||
import org.springframework.ai.tool.annotation.ToolParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* @author ageer
|
||||
*/
|
||||
@Service
|
||||
public class ToolService {
|
||||
|
||||
@Tool(description = "获取一个指定前缀的随机数")
|
||||
public String add(@ToolParam(description = "字符前缀") String prefix) {
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
|
||||
//根据当前时间获取yyMMdd格式的时间字符串
|
||||
String format = LocalDate.now().format(formatter);
|
||||
//生成随机数
|
||||
String replace = prefix + UUID.randomUUID().toString().replace("-", "");
|
||||
return format + replace;
|
||||
}
|
||||
|
||||
@Tool(description = "获取当前时间")
|
||||
public LocalDateTime getCurrentTime() {
|
||||
return LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
server:
|
||||
port: 8081
|
||||
spring:
|
||||
ai:
|
||||
mcp:
|
||||
server:
|
||||
name: ruoyi-mcp-serve
|
||||
version: 1.0.0
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring-ai.version>1.0.0-M7</spring-ai.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -23,7 +24,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-bom</artifactId>
|
||||
<version>1.0.0-M6</version>
|
||||
<version>${spring-ai.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -32,6 +33,13 @@
|
||||
|
||||
<!-- 对话基础模块 -->
|
||||
<dependencies>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.modelcontextprotocol.sdk</groupId>-->
|
||||
<!-- <artifactId>mcp-spring-webflux</artifactId>-->
|
||||
<!-- <version>0.8.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-chat</artifactId>
|
||||
@@ -55,17 +63,14 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mcp-client-webflux-spring-boot-starter</artifactId>
|
||||
<artifactId>spring-ai-starter-mcp-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.modelcontextprotocol.sdk</groupId>
|
||||
<artifactId>mcp-spring-webflux</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -65,7 +65,6 @@ public class ChatModelBo extends BaseEntity {
|
||||
/**
|
||||
* 系统提示词
|
||||
*/
|
||||
@NotBlank(message = "系统提示词不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String systemPrompt;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ruoyi.service;
|
||||
|
||||
/**
|
||||
* 企业微信聊天管理Service接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-04-08
|
||||
*/
|
||||
public interface IChatVxService {
|
||||
|
||||
|
||||
/**
|
||||
* 企业微信应用回复
|
||||
* @param prompt 提示词
|
||||
* @return 回复内容
|
||||
*/
|
||||
String chat(String prompt);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.ruoyi.common.chat.entity.chat.ChatCompletion;
|
||||
import org.ruoyi.common.chat.entity.chat.ChatCompletionResponse;
|
||||
import org.ruoyi.common.chat.entity.chat.Message;
|
||||
import org.ruoyi.common.chat.openai.OpenAiStreamClient;
|
||||
import org.ruoyi.service.IChatVxService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ChatVxServiceImpl implements IChatVxService {
|
||||
|
||||
private final OpenAiStreamClient openAiStreamClient;
|
||||
|
||||
@Override
|
||||
public String chat(String prompt) {
|
||||
List<Message> messageList = new ArrayList<>();
|
||||
Message message = Message.builder().role(Message.Role.USER).content(prompt).build();
|
||||
messageList.add(message);
|
||||
ChatCompletion chatCompletion = ChatCompletion
|
||||
.builder()
|
||||
.messages(messageList)
|
||||
.model("gpt-4o-mini")
|
||||
.stream(false)
|
||||
.build();
|
||||
ChatCompletionResponse chatCompletionResponse = openAiStreamClient.chatCompletion(chatCompletion);
|
||||
return chatCompletionResponse.getChoices().get(0).getMessage().getContent().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class KnowledgeFragment extends BaseEntity {
|
||||
/**
|
||||
* 片段索引下标
|
||||
*/
|
||||
private Long idx;
|
||||
private Integer idx;
|
||||
|
||||
/**
|
||||
* 文档内容
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.ruoyi.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author ageer
|
||||
*/
|
||||
@Data
|
||||
public class KnowledgeInfoUploadBo {
|
||||
|
||||
private String kid;
|
||||
|
||||
private MultipartFile file;
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import org.ruoyi.domain.bo.KnowledgeAttachBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeAttachVo;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -46,4 +47,17 @@ public interface IKnowledgeAttachService {
|
||||
* 校验并批量删除知识库附件信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 删除知识附件
|
||||
*/
|
||||
void removeKnowledgeAttach(String docId);
|
||||
|
||||
/**
|
||||
* 翻译文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @param targetLanguage 目标语音
|
||||
*/
|
||||
String translationByFile(MultipartFile file, String targetLanguage);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.ruoyi.service;
|
||||
|
||||
|
||||
import org.ruoyi.domain.bo.KnowledgeInfoBo;
|
||||
import org.ruoyi.domain.bo.KnowledgeInfoUploadBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeInfoVo;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
@@ -46,4 +47,19 @@ public interface IKnowledgeInfoService {
|
||||
* 校验并批量删除知识库信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 新增知识库
|
||||
*/
|
||||
void saveOne(KnowledgeInfoBo bo);
|
||||
|
||||
/**
|
||||
* 删除知识库
|
||||
*/
|
||||
void removeKnowledge(String id);
|
||||
|
||||
/**
|
||||
* 上传附件
|
||||
*/
|
||||
void upload(KnowledgeInfoUploadBo bo);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.domain.vo.KnowledgeAttachVo;
|
||||
import org.ruoyi.mapper.KnowledgeFragmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.ruoyi.domain.bo.KnowledgeAttachBo;
|
||||
|
||||
import org.ruoyi.domain.KnowledgeAttach;
|
||||
import org.ruoyi.mapper.KnowledgeAttachMapper;
|
||||
import org.ruoyi.service.IKnowledgeAttachService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
@@ -31,6 +34,7 @@ import java.util.Collection;
|
||||
public class KnowledgeAttachServiceImpl implements IKnowledgeAttachService {
|
||||
|
||||
private final KnowledgeAttachMapper baseMapper;
|
||||
private final KnowledgeFragmentMapper fragmentMapper;
|
||||
|
||||
/**
|
||||
* 查询知识库附件
|
||||
@@ -111,4 +115,64 @@ public class KnowledgeAttachServiceImpl implements IKnowledgeAttachService {
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeKnowledgeAttach(String docId) {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("doc_id",docId);
|
||||
baseMapper.deleteByMap(map);
|
||||
fragmentMapper.deleteByMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translationByFile(MultipartFile file, String targetLanguage) {
|
||||
/*String fileName = file.getOriginalFilename();
|
||||
String docType = fileName.substring(fileName.lastIndexOf(".")+1);
|
||||
String content = "";
|
||||
ResourceLoader resourceLoader = resourceLoaderFactory.getLoaderByFileType(docType);
|
||||
try {
|
||||
content = resourceLoader.getContent(file.getInputStream());
|
||||
} catch (IOException e) {
|
||||
throw new BaseException("该文件类型暂不支持!");
|
||||
}
|
||||
// 翻译模型固定为gpt-4o-mini
|
||||
String model = "gpt-4o-mini";
|
||||
ChatMessageBo chatMessageBo = new ChatMessageBo();
|
||||
chatMessageBo.setUserId(getUserId());
|
||||
chatMessageBo.setModelName(model);
|
||||
chatMessageBo.setContent(content);
|
||||
chatMessageBo.setDeductCost(0.01);
|
||||
chatMessageBo.setTotalTokens(0);
|
||||
OpenAiStreamClient openAiStreamClient = chatConfig.getOpenAiStreamClient();
|
||||
List<Message> messageList = new ArrayList<>();
|
||||
Message sysMessage = Message.builder().role(Message.Role.SYSTEM).content("你是一位精通各国语言的翻译大师\n" +
|
||||
"\n" +
|
||||
"请将用户输入词语翻译成{" + targetLanguage + "}\n" +
|
||||
"\n" +
|
||||
"==示例输出==\n" +
|
||||
"**原文** : <这里显示要翻译的原文信息>\n" +
|
||||
"**翻译** : <这里显示翻译之后的结果>\n" +
|
||||
"**总结** : <这里是对关键信息一个总结>\n" +
|
||||
"**提取的关键信息** : <这里返回关键信息>\n" +
|
||||
"==示例结束==\n" +
|
||||
"\n" +
|
||||
"注意:请严格按示例进行输出,返回markdown格式").build();
|
||||
messageList.add(sysMessage);
|
||||
Message message = Message.builder().role(Message.Role.USER).content(content).build();
|
||||
messageList.add(message);
|
||||
ChatCompletionResponse chatCompletionResponse = null;
|
||||
try {
|
||||
ChatCompletion chatCompletion = ChatCompletion
|
||||
.builder()
|
||||
.messages(messageList)
|
||||
.model(model)
|
||||
.stream(false)
|
||||
.build();
|
||||
chatCompletionResponse = openAiStreamClient.chatCompletion(chatCompletion);
|
||||
}catch (Exception e) {
|
||||
throw new BaseException("调用大模型失败,请检查密钥是否正确!");
|
||||
}
|
||||
return chatCompletionResponse.getChoices().get(0).getMessage().getContent().toString();*/
|
||||
return "接口开发中!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
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.ruoyi.domain.vo.KnowledgeInfoVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.ruoyi.domain.bo.KnowledgeInfoBo;
|
||||
import org.ruoyi.domain.KnowledgeInfo;
|
||||
import org.ruoyi.mapper.KnowledgeInfoMapper;
|
||||
import org.ruoyi.service.IKnowledgeInfoService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 知识库Service业务层处理
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-04-08
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class KnowledgeInfoServiceImpl implements IKnowledgeInfoService {
|
||||
|
||||
private final KnowledgeInfoMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询知识库
|
||||
*/
|
||||
@Override
|
||||
public KnowledgeInfoVo queryById(Long id){
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<KnowledgeInfoVo> queryPageList(KnowledgeInfoBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<KnowledgeInfo> lqw = buildQueryWrapper(bo);
|
||||
Page<KnowledgeInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库列表
|
||||
*/
|
||||
@Override
|
||||
public List<KnowledgeInfoVo> queryList(KnowledgeInfoBo bo) {
|
||||
LambdaQueryWrapper<KnowledgeInfo> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<KnowledgeInfo> buildQueryWrapper(KnowledgeInfoBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<KnowledgeInfo> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getKid()), KnowledgeInfo::getKid, bo.getKid());
|
||||
lqw.eq(bo.getUid() != null, KnowledgeInfo::getUid, bo.getUid());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getKname()), KnowledgeInfo::getKname, bo.getKname());
|
||||
lqw.eq(bo.getShare() != null, KnowledgeInfo::getShare, bo.getShare());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getDescription()), KnowledgeInfo::getDescription, bo.getDescription());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getKnowledgeSeparator()), KnowledgeInfo::getKnowledgeSeparator, bo.getKnowledgeSeparator());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getQuestionSeparator()), KnowledgeInfo::getQuestionSeparator, bo.getQuestionSeparator());
|
||||
lqw.eq(bo.getOverlapChar() != null, KnowledgeInfo::getOverlapChar, bo.getOverlapChar());
|
||||
lqw.eq(bo.getRetrieveLimit() != null, KnowledgeInfo::getRetrieveLimit, bo.getRetrieveLimit());
|
||||
lqw.eq(bo.getTextBlockSize() != null, KnowledgeInfo::getTextBlockSize, bo.getTextBlockSize());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getVector()), KnowledgeInfo::getVector, bo.getVector());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getVectorModel()), KnowledgeInfo::getVectorModel, bo.getVectorModel());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增知识库
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(KnowledgeInfoBo bo) {
|
||||
KnowledgeInfo add = MapstructUtils.convert(bo, KnowledgeInfo.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改知识库
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(KnowledgeInfoBo bo) {
|
||||
KnowledgeInfo update = MapstructUtils.convert(bo, KnowledgeInfo.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(KnowledgeInfo entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除知识库
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,10 @@ public interface IChatConfigService {
|
||||
* 校验并批量删除配置信息信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
|
||||
/**
|
||||
* 查询系统参数
|
||||
*/
|
||||
List<ChatConfigVo> getSysConfigValue(String category);
|
||||
}
|
||||
|
||||
@@ -129,4 +129,18 @@ public class ChatConfigServiceImpl implements ConfigService, IChatConfigService
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型和配置key获取值
|
||||
*
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ChatConfigVo> getSysConfigValue(String category) {
|
||||
ChatConfigBo bo = new ChatConfigBo();
|
||||
bo.setCategory(category);
|
||||
LambdaQueryWrapper<ChatConfig> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<module>ruoyi-chat</module>
|
||||
<module>ruoyi-system</module>
|
||||
<module>ruoyi-generator</module>
|
||||
<module>ruoyi-wechat</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.ruoyi.common.core.service.ConfigService;
|
||||
import org.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
@@ -31,11 +32,14 @@ import org.ruoyi.common.log.enums.BusinessType;
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/chatConfig")
|
||||
@RequestMapping("/chat/config")
|
||||
public class ChatConfigController extends BaseController {
|
||||
|
||||
private final IChatConfigService chatConfigService;
|
||||
|
||||
|
||||
private final ConfigService configService;
|
||||
|
||||
/**
|
||||
* 查询配置信息列表
|
||||
*/
|
||||
@@ -71,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,4 +113,24 @@ public class ChatConfigController extends BaseController {
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(chatConfigService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数键名查询系统参数值
|
||||
*
|
||||
* @param configKey 参数Key
|
||||
*/
|
||||
@GetMapping(value = "/configKey/{configKey}")
|
||||
public R<String> getConfigKey(@PathVariable String configKey) {
|
||||
return R.ok(configService.getConfigValue("sys",configKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统参数
|
||||
*
|
||||
*/
|
||||
@GetMapping(value = "/sysConfigKey")
|
||||
public R<List<ChatConfigVo>> getSysConfigKey() {
|
||||
return R.ok(chatConfigService.getSysConfigValue("sys"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出套餐管理列表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.ruoyi.chat.controller.chat;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.common.web.core.BaseController;
|
||||
import org.ruoyi.domain.bo.ChatAppStoreBo;
|
||||
import org.ruoyi.domain.vo.ChatAppStoreVo;
|
||||
import org.ruoyi.service.IChatAppStoreService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 应用商店
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2024-03-19
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/store")
|
||||
public class ChatStoreController extends BaseController {
|
||||
|
||||
private final IChatAppStoreService appStoreService;
|
||||
|
||||
/**
|
||||
* 应用商店
|
||||
*/
|
||||
@GetMapping("/appList")
|
||||
public R<List<ChatAppStoreVo>> appList(ChatAppStoreBo bo) {
|
||||
return R.ok(appStoreService.queryList(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏应用
|
||||
*/
|
||||
@PostMapping("/copyApp")
|
||||
public R<String> copyApp() {
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package org.ruoyi.chat.controller.knowledge;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import org.ruoyi.common.log.annotation.Log;
|
||||
import org.ruoyi.common.log.enums.BusinessType;
|
||||
import org.ruoyi.common.satoken.utils.LoginHelper;
|
||||
import org.ruoyi.common.web.core.BaseController;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.bo.KnowledgeAttachBo;
|
||||
import org.ruoyi.domain.bo.KnowledgeFragmentBo;
|
||||
import org.ruoyi.domain.bo.KnowledgeInfoBo;
|
||||
import org.ruoyi.domain.bo.KnowledgeInfoUploadBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeAttachVo;
|
||||
import org.ruoyi.domain.vo.KnowledgeFragmentVo;
|
||||
import org.ruoyi.domain.vo.KnowledgeInfoVo;
|
||||
import org.ruoyi.service.IKnowledgeAttachService;
|
||||
import org.ruoyi.service.IKnowledgeFragmentService;
|
||||
import org.ruoyi.service.IKnowledgeInfoService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ageer
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/knowledge")
|
||||
public class KnowledgeController extends BaseController {
|
||||
|
||||
private final IKnowledgeInfoService knowledgeInfoService;
|
||||
|
||||
private final IKnowledgeAttachService attachService;
|
||||
|
||||
private final IKnowledgeFragmentService fragmentService;
|
||||
|
||||
/**
|
||||
* 根据用户信息查询本地知识库
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<KnowledgeInfoVo> list(KnowledgeInfoBo bo, PageQuery pageQuery) {
|
||||
if (!StpUtil.isLogin()) {
|
||||
throw new SecurityException("请先去登录!");
|
||||
}
|
||||
bo.setUid(LoginHelper.getUserId());
|
||||
return knowledgeInfoService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增知识库
|
||||
*/
|
||||
@Log(title = "知识库", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/save")
|
||||
public R<Void> save(@Validated(AddGroup.class) @RequestBody KnowledgeInfoBo bo) {
|
||||
knowledgeInfoService.saveOne(bo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除知识库
|
||||
*/
|
||||
@PostMapping("/remove/{id}")
|
||||
public R<String> remove(@PathVariable String id) {
|
||||
knowledgeInfoService.removeKnowledge(id);
|
||||
return R.ok("删除知识库成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改知识库
|
||||
*/
|
||||
@Log(title = "知识库", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
public R<Void> edit(@RequestBody KnowledgeInfoBo bo) {
|
||||
return toAjax(knowledgeInfoService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出知识库列表
|
||||
*/
|
||||
@Log(title = "知识库", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(KnowledgeInfoBo bo, HttpServletResponse response) {
|
||||
List<KnowledgeInfoVo> list = knowledgeInfoService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "知识库", KnowledgeInfoVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识附件信息
|
||||
*/
|
||||
@GetMapping("/detail/{kid}")
|
||||
public TableDataInfo<KnowledgeAttachVo> attach(KnowledgeAttachBo bo, PageQuery pageQuery, @PathVariable String kid) {
|
||||
bo.setKid(kid);
|
||||
return attachService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传知识库附件
|
||||
*/
|
||||
@PostMapping(value = "/attach/upload")
|
||||
public R<String> upload(KnowledgeInfoUploadBo bo) {
|
||||
knowledgeInfoService.upload(bo);
|
||||
return R.ok("上传知识库附件成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库附件详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("attach/info/{id}")
|
||||
public R<KnowledgeAttachVo> getAttachInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(attachService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除知识库附件
|
||||
*/
|
||||
@PostMapping("attach/remove/{kid}")
|
||||
public R<Void> removeAttach(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable String kid) {
|
||||
attachService.removeKnowledgeAttach(kid);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询知识片段
|
||||
*/
|
||||
@GetMapping("/fragment/list/{docId}")
|
||||
public TableDataInfo<KnowledgeFragmentVo> fragmentList(KnowledgeFragmentBo bo, PageQuery pageQuery, @PathVariable String docId) {
|
||||
bo.setDocId(docId);
|
||||
return fragmentService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件翻译
|
||||
*/
|
||||
@PostMapping("/translationByFile")
|
||||
@ResponseBody
|
||||
public String translationByFile(@RequestParam("file") MultipartFile file, String targetLanguage) {
|
||||
return attachService.translationByFile(file, targetLanguage);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,4 @@ public interface ISseService {
|
||||
UploadFileResponse upload(MultipartFile file);
|
||||
|
||||
|
||||
/**
|
||||
* 企业应用回复
|
||||
* @param prompt 提示词
|
||||
* @return 回复内容
|
||||
*/
|
||||
String wxCpChat(String prompt);
|
||||
|
||||
}
|
||||
|
||||