Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2fd3a0b7e | ||
|
|
7b693527d9 | ||
|
|
93e0d57783 | ||
|
|
18027d5d5c | ||
|
|
0ef514a68f | ||
|
|
4780f5e972 | ||
|
|
5b8a567f26 | ||
|
|
488522de6e | ||
|
|
03bcf5d2c7 | ||
|
|
5d94ed853d | ||
|
|
d06e297c2d | ||
|
|
6304467d3a | ||
|
|
e52601a584 | ||
|
|
74226581b7 | ||
|
|
bc28504b3e | ||
|
|
109811199d | ||
|
|
610fa4d101 | ||
|
|
3657f6ce75 | ||
|
|
e62f72810c | ||
|
|
21553410f9 | ||
|
|
a6bc910b0f | ||
|
|
3e68667323 | ||
|
|
c0d4bbcecf | ||
|
|
6bf6159e6c | ||
|
|
fd4193daab | ||
|
|
da2077f3dd | ||
|
|
ee65032f7d | ||
|
|
2d7d75c290 | ||
|
|
237e88ba89 | ||
|
|
48223e4f39 | ||
|
|
ce776f210c | ||
|
|
fb5e25ec16 | ||
|
|
c4f2411fee | ||
|
|
3c3be950e9 | ||
|
|
b24ee0b9a6 | ||
|
|
e1d5caa0fd | ||
|
|
35ba9b0e6b | ||
|
|
66de07823d | ||
|
|
fd96e71d04 | ||
|
|
3c85242efc | ||
|
|
3c288e1e59 | ||
|
|
4bf2f927b0 | ||
|
|
ad30030a1f | ||
|
|
02d66e8093 | ||
|
|
49eab95be9 | ||
|
|
b1bfaf5a5c | ||
|
|
843e605352 | ||
|
|
6a7fa6060b | ||
|
|
43ce1df0ed | ||
|
|
a6deb3af8b | ||
|
|
9c01f5f0b0 | ||
|
|
80b89a85ee | ||
|
|
2fd0bb4912 | ||
|
|
c0329618fe | ||
|
|
c4a240cb04 | ||
|
|
33d5761194 | ||
|
|
a58ddd5880 | ||
|
|
3bbb5f9b83 | ||
|
|
3d6bf800f3 | ||
|
|
a0b0a0e1e8 | ||
|
|
8f48e9ac0c | ||
|
|
bb42095ca0 | ||
|
|
c487f69676 | ||
|
|
3db46a84b2 | ||
|
|
69520391f2 | ||
|
|
4b212753fb | ||
|
|
d86a2cf9de | ||
|
|
625d079168 | ||
|
|
2586843654 | ||
|
|
8ea48f9875 | ||
|
|
d7f3b3caf5 | ||
|
|
b37d8abf62 | ||
|
|
cd930edd06 | ||
|
|
4956aa6d70 | ||
|
|
fd17465d94 | ||
|
|
87a9425241 | ||
|
|
b225e8afd5 | ||
|
|
297b6e69d5 | ||
|
|
d7f0e88801 | ||
|
|
d62b27814c | ||
|
|
19526878b3 | ||
|
|
14ecad720f | ||
|
|
81689c04a5 | ||
|
|
de6b9de341 | ||
|
|
7f864eb84d | ||
|
|
4af0c1e2ce | ||
|
|
6a4ed78812 | ||
|
|
23b881f364 | ||
|
|
22054cf8bc | ||
|
|
fc236b1d96 | ||
|
|
4f81454f93 | ||
|
|
b3d6f173f1 | ||
|
|
8d2ba39ab8 | ||
|
|
4260e5a1a7 | ||
|
|
17585c8294 | ||
|
|
d242a9e5c0 | ||
|
|
9ca98f6391 | ||
|
|
be7ef08f40 | ||
|
|
626692df29 | ||
|
|
631787a4f1 | ||
|
|
09cf6cdc2d | ||
|
|
baf174b059 | ||
|
|
49eb3178a9 | ||
|
|
6a6aceff1d | ||
|
|
b8349af3da | ||
|
|
258d783f8e | ||
|
|
761fc05331 | ||
|
|
0c8e943d1b | ||
|
|
9787ca60da | ||
|
|
b8e57aeff4 | ||
|
|
9a0240ef3e | ||
|
|
cf5ccafe7e | ||
|
|
ae64233986 | ||
|
|
6dda79ee10 | ||
|
|
335a855968 | ||
|
|
94c92c5f38 | ||
|
|
35fa1493b3 | ||
|
|
f78f6fc529 | ||
|
|
5be65216e2 | ||
|
|
24526ad206 | ||
|
|
d7564a65f7 | ||
|
|
866d61cfaf | ||
|
|
3f3f3fdaa6 | ||
|
|
e0da59096a | ||
|
|
40632019ac | ||
|
|
3c5563b62f | ||
|
|
562424b74d | ||
|
|
7a598d5839 | ||
|
|
574d34bc2c | ||
|
|
16a4ccdb12 | ||
|
|
920cf4f897 | ||
|
|
76ee2c5365 | ||
|
|
472106390d | ||
|
|
d97f8b2e9a | ||
|
|
98e2526f8a | ||
|
|
c30c4649a4 | ||
|
|
ede8676979 | ||
|
|
17fb60b7ae | ||
|
|
8119897818 | ||
|
|
0a9e5d2cea | ||
|
|
a5f74d7767 | ||
|
|
02cb9c35b3 | ||
|
|
d934e0a69d | ||
|
|
2ecce6485c | ||
|
|
1ad8aeeaa7 | ||
|
|
46a15082d6 | ||
|
|
153ecf0b41 | ||
|
|
f0f7304ae2 | ||
|
|
997e171118 | ||
|
|
04a8fe8af2 | ||
|
|
a0822a356c | ||
|
|
b78d337fd0 | ||
|
|
13c5cb3f1d | ||
|
|
197c0532fa | ||
|
|
76342b09ff | ||
|
|
241d96f6ac | ||
|
|
fdc6dcb26e | ||
|
|
9fd010e91e | ||
|
|
c900498ce8 | ||
|
|
c4c84e44e1 | ||
|
|
191ac47353 | ||
|
|
851365fb58 | ||
|
|
ede2bc6a4e | ||
|
|
38780b6daa | ||
|
|
0dc267c109 | ||
|
|
bc6c85c6c6 | ||
|
|
915f4cac5e | ||
|
|
b8da0714c2 | ||
|
|
f1105e6822 | ||
|
|
20296148eb | ||
|
|
2138c0fb4f | ||
|
|
34d9857089 | ||
|
|
888b71a196 | ||
|
|
5f16c871dc | ||
|
|
595a338de7 | ||
|
|
fe47fd1910 | ||
|
|
ac9abf8ede | ||
|
|
282706dbc8 | ||
|
|
5360cbf19c | ||
|
|
84ac1b6686 | ||
|
|
ebc16207f4 | ||
|
|
7611e98156 | ||
|
|
848f73715f | ||
|
|
6f30dfb963 | ||
|
|
c8aa903e3e | ||
|
|
f0e55037de | ||
|
|
1335b368d1 | ||
|
|
a647f3c105 | ||
|
|
c936372105 | ||
|
|
f242d43f73 | ||
|
|
c216012304 | ||
|
|
87c2f0e38e | ||
|
|
d9cc75edc0 | ||
|
|
1f91ec32da | ||
|
|
92b60b7f25 | ||
|
|
8104d02a3a | ||
|
|
83c4add375 | ||
|
|
c19084b7b4 | ||
|
|
2761e97c6a | ||
|
|
0cdfd1d114 | ||
|
|
8566e048b6 | ||
|
|
31fc731af6 | ||
|
|
ff95764824 | ||
|
|
737c4a6b5d | ||
|
|
db68871646 | ||
|
|
748f17b777 | ||
|
|
bbba24c7bc | ||
|
|
5bba864faa | ||
|
|
33b7fe6072 | ||
|
|
4d0bef62ed | ||
|
|
e09ba81cfa | ||
|
|
baf15450a3 | ||
|
|
d24419cfb7 | ||
|
|
fe88db2094 | ||
|
|
91d2ab7d1d | ||
|
|
9a405a756f | ||
|
|
86f5be23fe | ||
|
|
9f4ca1aa6b | ||
|
|
624b1cce74 | ||
|
|
29216768e1 | ||
|
|
59e18dc1c1 | ||
|
|
858a85f952 | ||
|
|
1cbd68f1e3 | ||
|
|
324bf62bb8 | ||
|
|
dd1d7d5dc1 | ||
|
|
e6ad9e23cc | ||
|
|
a557322dc6 | ||
|
|
7d7324ddbc | ||
|
|
680ed4596f | ||
|
|
e66ab647e1 | ||
|
|
253f4c59a3 | ||
|
|
38a97d6b5a | ||
|
|
ae8f11d5a8 | ||
|
|
dcfd82f84e | ||
|
|
25a531341a | ||
|
|
f421f6dee8 | ||
|
|
a5332ccc7d | ||
|
|
76c3f401ea | ||
|
|
5173dded2a | ||
|
|
bdd8597f69 | ||
|
|
46bba64a94 | ||
|
|
d0694a0e70 | ||
|
|
bd12b0e81f | ||
|
|
2f4fb0fc52 | ||
|
|
cbabf01902 | ||
|
|
c51c8b4af0 | ||
|
|
2741e11078 | ||
|
|
aa251aa011 | ||
|
|
0509ddb129 | ||
|
|
5a180836b7 | ||
|
|
9c7c6b9ea7 | ||
|
|
d64eb0b087 | ||
|
|
28e4318f8a | ||
|
|
36f0821ea0 | ||
|
|
293a690ccd | ||
|
|
1c96ff7d3b | ||
|
|
db8a2bb872 | ||
|
|
dfbe4fc7ee | ||
|
|
3cccc4ec64 | ||
|
|
e29684e672 | ||
|
|
30796c6f81 | ||
|
|
86b5eb1818 | ||
|
|
696405a8bf | ||
|
|
a2c2eab6b3 | ||
|
|
eadb69bdc0 | ||
|
|
e73223ca8a | ||
|
|
6dd66dbae9 | ||
|
|
ead9ee81fb | ||
|
|
073b69f94a | ||
|
|
1a0a0777a3 | ||
|
|
a971ae2168 | ||
|
|
bd140af714 | ||
|
|
6b8d2502b7 | ||
|
|
96008fa78f | ||
|
|
da4d0f515c | ||
|
|
67e6a22da9 | ||
|
|
b791fb1494 | ||
|
|
9e329bf19f | ||
|
|
3906e8a942 | ||
|
|
f74faea065 | ||
|
|
7d3759acce | ||
|
|
172962f711 | ||
|
|
36109e3b88 | ||
|
|
7c63b7c062 | ||
|
|
1efaf048f5 | ||
|
|
ac52714498 | ||
|
|
c3de89f504 | ||
|
|
6f6a645d0a | ||
|
|
5605352144 | ||
|
|
ef433f446d | ||
|
|
fe8f200364 | ||
|
|
e4194cdf4d | ||
|
|
c8392c9b47 | ||
|
|
be3a030302 | ||
|
|
cd6d4488d1 | ||
|
|
da3a5df5c3 | ||
|
|
4864407d61 | ||
|
|
f6f7879d6e | ||
|
|
dab1f14a59 | ||
|
|
51ca914206 | ||
|
|
933ffb8ca2 | ||
|
|
2f5f20a257 | ||
|
|
92544f89f3 | ||
|
|
f1cf1acbfa | ||
|
|
f22008389c | ||
|
|
885b7a0b05 | ||
|
|
91de372cbc | ||
|
|
811bd94934 | ||
|
|
5987488b3d | ||
|
|
966c9e972d | ||
|
|
464261a1b7 | ||
|
|
363dcef81a | ||
|
|
4439617c50 | ||
|
|
5d2fa3d65d | ||
|
|
8930ab0af6 | ||
|
|
6af6fe22fc | ||
|
|
dd577a7843 | ||
|
|
f772155674 | ||
|
|
3ce204338a | ||
|
|
168bc9ef45 | ||
|
|
bfc3d4888b | ||
|
|
0148b115db | ||
|
|
0b11953f6f | ||
|
|
6e210faacf | ||
|
|
4ef755e10b | ||
|
|
62b7cc5509 | ||
|
|
0e1ec05110 | ||
|
|
dd38fc74db | ||
|
|
d619d7ac76 | ||
|
|
37f7511ba0 | ||
|
|
afd03ba1b5 | ||
|
|
ac7b02d28a | ||
|
|
4a0bdbf779 | ||
|
|
164dada46a | ||
|
|
fd1c4ec792 | ||
|
|
add000d221 | ||
|
|
def598f728 | ||
|
|
0294885fbf | ||
|
|
c0ec4338f8 | ||
|
|
fb7f6f73bd | ||
|
|
e04c38e557 | ||
|
|
bfb5420733 | ||
|
|
9e6fc32903 | ||
|
|
217ceb1c7a | ||
|
|
846f89664e | ||
|
|
0e30f69e96 | ||
|
|
af9eb538f4 | ||
|
|
66a0beea33 | ||
|
|
411e73bb35 | ||
|
|
852e222f5d | ||
|
|
054ceab4f4 | ||
|
|
d9149ff572 | ||
|
|
7f331690a0 | ||
|
|
a5698dfff0 | ||
|
|
1e5866da06 | ||
|
|
7e712c5003 | ||
|
|
474eeb9e68 | ||
|
|
0c0386f4ba | ||
|
|
6c2b1cb589 | ||
|
|
92e117c10a | ||
|
|
71db92ef61 | ||
|
|
118bb728a9 | ||
|
|
d7aac5e10f | ||
|
|
4359f1d5b3 | ||
|
|
8bb888c58e | ||
|
|
4c81585e32 | ||
|
|
0e6d1cd677 | ||
|
|
98368cbe06 | ||
|
|
0b4a4df1af | ||
|
|
c8a3d378b7 | ||
|
|
aa34473560 | ||
|
|
f479a789db | ||
|
|
d4ce501c75 | ||
|
|
c2643d0b80 | ||
|
|
078605c188 | ||
|
|
cd3e9ed494 | ||
|
|
8a5a9cc0b3 | ||
|
|
347fc4ca44 | ||
|
|
61db1192e2 | ||
|
|
d9d973b6aa | ||
|
|
cc4aed5a8e | ||
|
|
b44d52fb3e | ||
|
|
93265be974 | ||
|
|
2028405af6 | ||
|
|
bb9df3f54c | ||
|
|
264487574b | ||
|
|
6a00895af8 | ||
|
|
1136ca4b24 | ||
|
|
b153bc11f2 | ||
|
|
a067a6ba87 | ||
|
|
c271b88c87 | ||
|
|
1dfa619243 | ||
|
|
91bdc05a38 | ||
|
|
0e8edfe002 | ||
|
|
c1084923f7 | ||
|
|
b2381fc689 | ||
|
|
fa75f56ffb |
@@ -107,6 +107,7 @@ celerybeat.pid
|
|||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
||||||
# Environments
|
# Environments
|
||||||
|
.env
|
||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
@@ -145,24 +146,31 @@ tmp
|
|||||||
.history
|
.history
|
||||||
.DS_Store
|
.DS_Store
|
||||||
main/xiaozhi-server/data
|
main/xiaozhi-server/data
|
||||||
main/xiaozhi-server/config/assets/wakeup_words.*
|
|
||||||
main/manager-web/node_modules
|
main/manager-web/node_modules
|
||||||
.config.yaml
|
.config.yaml
|
||||||
.secrets.yaml
|
.secrets.yaml
|
||||||
.private_config.yaml
|
.private_config.yaml
|
||||||
|
.env.development
|
||||||
|
|
||||||
# model files
|
# model files
|
||||||
main/xiaozhi-server/models/SenseVoiceSmall/model.pt
|
main/xiaozhi-server/models/SenseVoiceSmall/model.pt
|
||||||
main/xiaozhi-server/models/sherpa-onnx*
|
main/xiaozhi-server/models/sherpa-onnx*
|
||||||
|
/main/xiaozhi-server/audio_ref/
|
||||||
|
/audio_ref/
|
||||||
|
/asr-models/iic/SenseVoiceSmall/
|
||||||
|
/main/xiaozhi-server/asr-models/iic/SenseVoiceSmall/
|
||||||
|
/models/SenseVoiceSmall/model.pt
|
||||||
my_wakeup_words.mp3
|
my_wakeup_words.mp3
|
||||||
!main/xiaozhi-server/config/assets/bind_code.wav
|
!main/xiaozhi-server/config/assets/bind_code.wav
|
||||||
|
!main/xiaozhi-server/config/assets/wakeup_words.wav
|
||||||
!main/xiaozhi-server/config/assets/bind_not_found.wav
|
!main/xiaozhi-server/config/assets/bind_not_found.wav
|
||||||
!main/xiaozhi-server/config/assets/bind_code/*.wav
|
!main/xiaozhi-server/config/assets/bind_code/*.wav
|
||||||
!main/xiaozhi-server/config/assets/max_output_size.wav
|
!main/xiaozhi-server/config/assets/max_output_size.wav
|
||||||
main/manager-api/.vscode
|
main/manager-api/.vscode
|
||||||
|
|
||||||
# Ignore webpack cache directory
|
# Ignore webpack cache directory
|
||||||
main/manager-web/.webpack_cache/
|
main/manager-web/.webpack_cache/
|
||||||
main/xiaozhi-server/mysql
|
main/xiaozhi-server/mysql
|
||||||
uploadfile
|
uploadfile
|
||||||
|
*.json
|
||||||
.vscode
|
.vscode
|
||||||
|
|||||||
@@ -7,20 +7,23 @@ COPY main/manager-web .
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# 第二阶段:构建Java后端
|
# 第二阶段:构建Java后端
|
||||||
FROM maven:3-eclipse-temurin-21-alpine as api-builder
|
FROM maven:3.9.4-eclipse-temurin-21 as api-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY main/manager-api/pom.xml .
|
COPY main/manager-api/pom.xml .
|
||||||
COPY main/manager-api/src ./src
|
COPY main/manager-api/src ./src
|
||||||
RUN mvn clean package -Dmaven.test.skip=true
|
RUN mvn clean package -Dmaven.test.skip=true
|
||||||
|
|
||||||
# 第三阶段:构建最终镜像
|
# 第三阶段:构建最终镜像
|
||||||
FROM eclipse-temurin:21-jdk-jammy
|
FROM bellsoft/liberica-runtime-container:jre-21-glibc
|
||||||
|
|
||||||
# 安装Nginx并清理缓存
|
# 安装Nginx和字体库
|
||||||
RUN apt-get update && \
|
RUN apk update && \
|
||||||
apt-get install -y nginx && \
|
apk add --no-cache nginx bash && \
|
||||||
apt-get clean && \
|
apk add --no-cache fontconfig ttf-dejavu msttcorefonts-installer && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# 更新字体缓存
|
||||||
|
RUN printf 'YES\n' | update-ms-fonts && fc-cache -f -v
|
||||||
|
|
||||||
# 配置Nginx
|
# 配置Nginx
|
||||||
COPY docs/docker/nginx.conf /etc/nginx/nginx.conf
|
COPY docs/docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|||||||
@@ -121,6 +121,33 @@
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV12J7WzBEaH" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="实时打断" src="docs/images/demo10.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV1Co76z7EvK" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="拍照识物品" src="docs/images/demo12.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV1TJ7WzzEo6" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="多指令任务" src="docs/images/demo11.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -141,11 +168,11 @@
|
|||||||
本项目提供两种部署方式,请根据您的具体需求选择:
|
本项目提供两种部署方式,请根据您的具体需求选择:
|
||||||
|
|
||||||
#### 🚀 部署方式选择
|
#### 🚀 部署方式选择
|
||||||
|
| 部署方式 | 特点 | 适用场景 | 部署文档 | 配置要求 | 视频教程 |
|
||||||
|
|---------|------|---------|---------|---------|---------|
|
||||||
|
| **最简化安装** | 智能对话、IOT功能,数据存储在配置文件 | 低配置环境,无需数据库 | [①Docker版](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E5%8F%AA%E8%BF%90%E8%A1%8Cserver) / [②源码部署](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E5%8F%AA%E8%BF%90%E8%A1%8Cserver)| 如果使用`FunASR`要2核4G,如果全API,要2核2G | - |
|
||||||
|
| **全模块安装** | 智能对话、IOT、OTA、智控台,数据存储在数据库 | 完整功能体验 |[①Docker版](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) / [②源码部署](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) / [③源码部署自动更新教程](./docs/dev-ops-integration.md) | 如果使用`FunASR`要4核8G,如果全API,要2核4G| [本地源码启动视频教程](https://www.bilibili.com/video/BV1wBJhz4Ewe) |
|
||||||
|
|
||||||
| 部署方式 | 特点 | 适用场景 | Docker部署文档 | 源码部署文档 |
|
|
||||||
|---------|------|---------|---------|---------|
|
|
||||||
| **最简化安装** | 智能对话、IOT功能,数据存储在配置文件 | 低配置环境,无需数据库 | [Docker只运行Server](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E5%8F%AA%E8%BF%90%E8%A1%8Cserver) | [本地源码只运行Server](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E5%8F%AA%E8%BF%90%E8%A1%8Cserver)|
|
|
||||||
| **全模块安装** | 智能对话、IOT、OTA、智控台,数据存储在数据库 | 完整功能体验 |[Docker运行全模块](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) | [本地源码运行全模块](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) |
|
|
||||||
|
|
||||||
> 💡 提示:以下是按最新代码部署后的测试平台,有需要可烧录测试,并发为6个,每天会清空数据
|
> 💡 提示:以下是按最新代码部署后的测试平台,有需要可烧录测试,并发为6个,每天会清空数据
|
||||||
|
|
||||||
@@ -157,22 +184,49 @@ OTA接口地址: https://2662r3426b.vicp.fun/xiaozhi/ota/
|
|||||||
Websocket接口地址: wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
Websocket接口地址: wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 🚩 配置说明和推荐
|
||||||
|
> [!Note]
|
||||||
|
> 本项目默认的配置是`入门全免费`设置,如果想效果更优,推荐使用`流式配置`。
|
||||||
|
>
|
||||||
|
> 本项目自`0.5.2`版本,已支持使用流式配置,相比`0.5`版本以前,响应速度提升约`2.5秒`
|
||||||
|
|
||||||
|
| 模块名称 | 入门全免费设置 | 流式配置 |
|
||||||
|
|:---:|:---:|:---:|
|
||||||
|
| ASR(语音识别) | FunASR(本地) | 👍DoubaoStreamASR(火山流式语音识别) |
|
||||||
|
| LLM(大模型) | ChatGLMLLM(智谱glm-4-flash) | 👍DoubaoLLM(火山doubao-1-5-pro-32k-250115) |
|
||||||
|
| VLLM(视觉大模型) | ChatGLMVLLM(智谱glm-4v-flash) | 👍QwenVLVLLM(千问qwen2.5-vl-3b-instructh) |
|
||||||
|
| TTS(语音合成) | EdgeTTS(微软语音) | 👍HuoshanDoubleStreamTTS(火山双流式语音合成) |
|
||||||
|
| Intent(意图识别) | function_call(函数调用) | ✅function_call(函数调用) |
|
||||||
|
| Memory(记忆功能) | mem_local_short(本地短期记忆) | ✅mem_local_short(本地短期记忆) |
|
||||||
|
|
||||||
|
#### 🔧 测试工具
|
||||||
|
本项目提供以下测试工具,帮助您验证系统和选择合适的模型:
|
||||||
|
|
||||||
|
| 工具名称 | 位置 | 使用方法 | 功能说明 |
|
||||||
|
|:---:|:---|:---:|:---:|
|
||||||
|
| 音频交互测试工具 | 位于`main/xiaozhi-server/test/test_page.html` | 使用谷歌浏览器直接打开 | 测试音频播放和接收功能,验证Python端音频处理是否正常 |
|
||||||
|
| 模型响应测试工具1 | 位于`main/xiaozhi-server/performance_tester.py` | 执行 `python performance_tester.py` | 测试ASR(语音识别)、LLM(大模型)、TTS(语音合成)三个核心模块的响应速度 |
|
||||||
|
| 模型响应测试工具2 | 位于`main/xiaozhi-server/performance_tester_vllm.py` | 执行 `python performance_tester_vllm.py` | 测试VLLM(视觉模型)的响应速度 |
|
||||||
|
|
||||||
|
> 💡 提示:测试模型速度时,只会测试配置了密钥的模型。
|
||||||
|
|
||||||
---
|
---
|
||||||
## 功能清单 ✨
|
## 功能清单 ✨
|
||||||
|
|
||||||
### 已实现 ✅
|
### 已实现 ✅
|
||||||
|
|
||||||
| 功能模块 | 描述 |
|
| 功能模块 | 描述 |
|
||||||
|---------|------|
|
|:---:|:---|
|
||||||
| 通信协议 | 基于 `xiaozhi-esp32` 协议,通过 WebSocket 实现数据交互 |
|
| 核心服务架构 | 基于WebSocket和HTTP服务器,提供完整的控制台管理和认证系统 |
|
||||||
| 对话交互 | 支持唤醒对话、手动对话及实时打断。长时间无对话时自动休眠 |
|
| 语音交互系统 | 支持流式ASR(语音识别)、流式TTS(语音合成)、VAD(语音活动检测),支持多语言识别和语音处理 |
|
||||||
| 意图识别 | 支持使用LLM意图识别、function call函数调用,减少硬编码意图判断 |
|
| 智能对话系统 | 支持多种LLM(大语言模型),实现智能对话 |
|
||||||
| 多语言识别 | 支持国语、粤语、英语、日语、韩语(默认使用 FunASR) |
|
| 视觉感知系统 | 支持多种VLLM(视觉大模型),实现多模态交互 |
|
||||||
| LLM 模块 | 支持灵活切换 LLM 模块,默认使用 ChatGLMLLM,也可选用阿里百炼、DeepSeek、Ollama 等接口 |
|
| 意图识别系统 | 支持LLM意图识别、Function Call函数调用,提供插件化意图处理机制 |
|
||||||
| TTS 模块 | 支持 EdgeTTS(默认)、火山引擎豆包 TTS 等多种 TTS 接口,满足语音合成需求 |
|
| 记忆系统 | 支持本地短期记忆、mem0ai接口记忆,具备记忆总结功能 |
|
||||||
| 记忆功能 | 支持超长记忆、本地总结记忆、无记忆三种模式,满足不同场景需求 |
|
| IOT/MCP控制协议 | 支持设备注册管理、智能控制接口,同时支持IOT、MCP控制协议 |
|
||||||
| IOT功能 | 支持管理注册设备IOT功能,支持基于对话上下文语境下的智能物联网控制 |
|
| 管理后台 | 提供Web管理界面,支持用户管理、系统配置和设备管理 |
|
||||||
| 智控台 | 提供Web管理界面,支持智能体管理、用户管理、系统配置等功能,方便管理员和用户进行管理 |
|
| 测试工具 | 提供性能测试工具、视觉模型测试工具和音频交互测试工具 |
|
||||||
|
| 部署支持 | 支持Docker部署和本地部署,提供完整的配置文件管理 |
|
||||||
|
| 插件系统 | 支持功能插件扩展、自定义插件开发和插件热加载 |
|
||||||
|
|
||||||
### 正在开发 🚧
|
### 正在开发 🚧
|
||||||
|
|
||||||
@@ -209,6 +263,16 @@ Websocket接口地址: wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### VLLM 视觉模型
|
||||||
|
|
||||||
|
| 使用方式 | 支持平台 | 免费平台 |
|
||||||
|
|:---:|:---:|:---:|
|
||||||
|
| openai 接口调用 | 阿里百炼、智谱ChatGLMVLLM | 智谱ChatGLMVLLM |
|
||||||
|
|
||||||
|
实际上,任何支持 openai 接口调用的 VLLM 均可接入使用。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### TTS 语音合成
|
### TTS 语音合成
|
||||||
|
|
||||||
| 使用方式 | 支持平台 | 免费平台 |
|
| 使用方式 | 支持平台 | 免费平台 |
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
This project provides backend services for the open-source smart hardware project
|
This project provides backend services for the open-source smart hardware project
|
||||||
<a href="https://github.com/78/xiaozhi-esp32">xiaozhi-esp32</a><br/>
|
<a href="https://github.com/78/xiaozhi-esp32">xiaozhi-esp32</a><br/>
|
||||||
Implemented using Python, Java, and Vue according to the <a href="https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh">Xiaozhi Communication Protocol</a><br/>
|
Implemented using Python, Java, and Vue according to the <a href="https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh">Xiaozhi Communication Protocol</a><br/>
|
||||||
Helping you quickly set up your Xiaozhi server
|
Helps you quickly set up your Xiaozhi server
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="./README.md">中文</a>
|
<a href="./README.md">中文</a>
|
||||||
· <a href="./docs/FAQ.md">FAQ</a>
|
· <a href="./docs/FAQ.md">FAQ</a>
|
||||||
· <a href="https://github.com/xinnan-tech/xiaozhi-esp32-server/issues">Report Issues</a>
|
· <a href="https://github.com/xinnan-tech/xiaozhi-esp32-server/issues">Report Issues</a>
|
||||||
· <a href="./README_ed.md#deployment-documentation">Deployment Guide</a>
|
· <a href="./README_en.md#deployment-documentation">Deployment Guide</a>
|
||||||
· <a href="https://github.com/xinnan-tech/xiaozhi-esp32-server/releases">Release Notes</a>
|
· <a href="https://github.com/xinnan-tech/xiaozhi-esp32-server/releases">Release Notes</a>
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -50,7 +50,7 @@ Want to see it in action? Check out these videos 🎥
|
|||||||
<td>
|
<td>
|
||||||
<a href="https://www.bilibili.com/video/BV1FMFyejExX" target="_blank">
|
<a href="https://www.bilibili.com/video/BV1FMFyejExX" target="_blank">
|
||||||
<picture>
|
<picture>
|
||||||
<img alt="Xiaozhi esp32 connecting to custom backend model" src="docs/images/demo1.png" />
|
<img alt="Xiaozhi esp32 connecting to own backend model" src="docs/images/demo1.png" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -64,14 +64,14 @@ Want to see it in action? Check out these videos 🎥
|
|||||||
<td>
|
<td>
|
||||||
<a href="https://www.bilibili.com/video/BV12yA2egEaC" target="_blank">
|
<a href="https://www.bilibili.com/video/BV12yA2egEaC" target="_blank">
|
||||||
<picture>
|
<picture>
|
||||||
<img alt="Cantonese communication" src="docs/images/demo3.png" />
|
<img alt="Using Cantonese" src="docs/images/demo3.png" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="https://www.bilibili.com/video/BV1pNXWYGEx1" target="_blank">
|
<a href="https://www.bilibili.com/video/BV1pNXWYGEx1" target="_blank">
|
||||||
<picture>
|
<picture>
|
||||||
<img alt="Home appliance control" src="docs/images/demo5.png" />
|
<img alt="Control home appliances" src="docs/images/demo5.png" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -94,7 +94,7 @@ Want to see it in action? Check out these videos 🎥
|
|||||||
<td>
|
<td>
|
||||||
<a href="https://www.bilibili.com/video/BV1VC96Y5EMH" target="_blank">
|
<a href="https://www.bilibili.com/video/BV1VC96Y5EMH" target="_blank">
|
||||||
<picture>
|
<picture>
|
||||||
<img alt="Music playback" src="docs/images/demo7.png" />
|
<img alt="Play music" src="docs/images/demo7.png" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -108,7 +108,7 @@ Want to see it in action? Check out these videos 🎥
|
|||||||
<td>
|
<td>
|
||||||
<a href="https://www.bilibili.com/video/BV178XuYfEpi" target="_blank">
|
<a href="https://www.bilibili.com/video/BV178XuYfEpi" target="_blank">
|
||||||
<picture>
|
<picture>
|
||||||
<img alt="IOT device control" src="docs/images/demo9.png" />
|
<img alt="IOT command control" src="docs/images/demo9.png" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -120,6 +120,33 @@ Want to see it in action? Check out these videos 🎥
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV12J7WzBEaH" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="Real-time interruption" src="docs/images/demo10.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV1Co76z7EvK" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="Photo recognition" src="docs/images/demo12.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://www.bilibili.com/video/BV1TJ7WzzEo6" target="_blank">
|
||||||
|
<picture>
|
||||||
|
<img alt="Multi-command tasks" src="docs/images/demo11.png" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -137,91 +164,102 @@ It is recommended that users prioritize service providers with relevant business
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
This project offers two deployment methods. Please choose based on your specific needs:
|
This project provides two deployment methods. Please choose according to your specific needs:
|
||||||
|
|
||||||
#### 🚀 Deployment Method Selection
|
#### 🚀 Deployment Method Selection
|
||||||
|
| Deployment Method | Features | Suitable Scenarios | Deployment Guide | Requirements | Video Tutorial |
|
||||||
|
|---------|------|---------|---------|---------|---------|
|
||||||
|
| **Simplified Installation** | Smart dialogue, IOT functionality, data stored in configuration files | Low-configuration environment, no database needed | [Docker Version](./docs/Deployment.md#method-1-docker-server-only) / [Source Code Deployment](./docs/Deployment.md#method-2-local-source-code-server-only) | 2 cores 4G if using `FunASR`, 2 cores 2G if using all APIs | - |
|
||||||
|
| **Full Module Installation** | Smart dialogue, IOT, OTA, Control Panel, data stored in database | Complete functionality experience | [Docker Version](./docs/Deployment_all.md#method-1-docker-full-modules) / [Source Code Deployment](./docs/Deployment_all.md#method-2-local-source-code-full-modules) | 4 cores 8G if using `FunASR`, 2 cores 4G if using all APIs | [Local Source Code Startup Video Tutorial](https://www.bilibili.com/video/BV1wBJhz4Ewe) / [Local Source Code Auto-Update Tutorial](./docs/dev-ops-integration.md) |
|
||||||
|
|
||||||
| Deployment Method | Features | Use Case | Docker Deployment Guide | Source Code Deployment Guide |
|
> 💡 Note: Below are the test platforms deployed with the latest code. You can flash and test if needed. Concurrent users: 6, data will be cleared daily
|
||||||
|---------|------|---------|---------|---------|
|
|
||||||
| **Simplified Installation** | Smart dialogue, IOT functionality, data stored in configuration files | Low-configuration environment, no database required | [Docker Server Only](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E5%8F%AA%E8%BF%90%E8%A1%8Cserver) | [Local Source Code Server Only](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E5%8F%AA%E8%BF%90%E8%A1%8Cserver)|
|
|
||||||
| **Full Module Installation** | Smart dialogue, IOT, OTA, Control Panel, data stored in database | Complete functionality experience |[Docker Full Module](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%B8%80docker%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) | [Local Source Code Full Module](./docs/Deployment_all.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E8%BF%90%E8%A1%8C%E5%85%A8%E6%A8%A1%E5%9D%97) |
|
|
||||||
|
|
||||||
> 💡 Note: Below is the test platform deployed with the latest code. You can flash and test if needed. Concurrent users: 6, data cleared daily
|
|
||||||
|
|
||||||
```
|
```
|
||||||
Control Panel: https://2662r3426b.vicp.fun
|
Control Panel Address: https://2662r3426b.vicp.fun
|
||||||
|
|
||||||
Service Test Tool: https://2662r3426b.vicp.fun/test/
|
Service Test Tool: https://2662r3426b.vicp.fun/test/
|
||||||
OTA Interface: https://2662r3426b.vicp.fun/xiaozhi/ota/
|
OTA Interface Address: https://2662r3426b.vicp.fun/xiaozhi/ota/
|
||||||
Websocket Interface: wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
Websocket Interface Address: wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 🚩 Configuration Description and Recommendations
|
||||||
|
> [!Note]
|
||||||
|
> The default configuration of this project is `Entry Level Free` settings. For better results, we recommend using `Full Streaming Configuration`.
|
||||||
|
>
|
||||||
|
> Since version `0.5.2`, this project supports full streaming throughout the entire lifecycle. Compared to versions before `0.5`, response speed has improved by approximately `2.5 seconds`
|
||||||
|
|
||||||
|
| Module Name | Entry Level Free Settings | Full Streaming Configuration |
|
||||||
|
|---------|---------|------|
|
||||||
|
| ASR(Speech Recognition) | FunASR(Local) | ✅DoubaoASR(Volcano Streaming Speech Recognition) |
|
||||||
|
| LLM(Large Language Model) | ChatGLMLLM(Zhipu glm-4-flash) | ✅DoubaoLLM(Volcano doubao-1-5-pro-32k-250115) |
|
||||||
|
| VLLM(Vision Large Model) | ChatGLMVLLM(Zhipu glm-4v-flash) | ✅ChatGLMVLLM(Zhipu glm-4v-flash) |
|
||||||
|
| TTS(Speech Synthesis) | EdgeTTS(Microsoft Speech) | ✅HuoshanDoubleStreamTTS(Volcano Double Streaming Speech Synthesis) |
|
||||||
|
| Intent(Intent Recognition) | function_call(Function Call) | ✅function_call(Function Call) |
|
||||||
|
| Memory(Memory Function) | mem_local_short(Local Short-term Memory) | ✅mem_local_short(Local Short-term Memory) |
|
||||||
|
|
||||||
---
|
---
|
||||||
## Feature List ✨
|
## Feature List ✨
|
||||||
|
|
||||||
### Implemented ✅
|
### Implemented ✅
|
||||||
|
|
||||||
| Feature Module | Description |
|
| Feature Module | Description |
|
||||||
|---------|------|
|
|---------|------|
|
||||||
| Communication Protocol | Based on `xiaozhi-esp32` protocol, implements data interaction through WebSocket |
|
| Communication Protocol | Based on `xiaozhi-esp32` protocol, implements data interaction through WebSocket |
|
||||||
| Dialogue Interaction | Supports wake-up dialogue, manual dialogue, and real-time interruption. Auto-sleep after long periods of inactivity |
|
| Dialogue Interaction | Supports wake-up dialogue, manual dialogue, and real-time interruption. Auto-sleep after long periods of no dialogue |
|
||||||
| Intent Recognition | Supports LLM intent recognition, function call, reducing hard-coded intent judgment |
|
| Intent Recognition | Supports LLM intent recognition, function call, reducing hard-coded intent judgment |
|
||||||
| Multi-language Recognition | Supports Mandarin, Cantonese, English, Japanese, Korean (default using FunASR) |
|
| Multi-language Recognition | Supports Mandarin, Cantonese, English, Japanese, Korean (default using FunASR) |
|
||||||
| LLM Module | Supports flexible LLM module switching, default using ChatGLMLLM, also supports Ali Bailing, DeepSeek, Ollama, etc. |
|
| LLM Module | Supports flexible LLM module switching, default using ChatGLMLLM, can also use Ali Bailian, DeepSeek, Ollama, etc. |
|
||||||
| TTS Module | Supports EdgeTTS (default), Volcano Engine Doubao TTS, and other TTS interfaces for speech synthesis |
|
| TTS Module | Supports EdgeTTS (default), Volcano Engine Doubao TTS, and other TTS interfaces |
|
||||||
| Memory Function | Supports ultra-long memory, local summary memory, and no memory modes for different scenarios |
|
| Memory Function | Supports ultra-long memory, local summary memory, and no memory modes |
|
||||||
| IOT Function | Supports managing registered device IOT functionality, intelligent IoT control based on dialogue context |
|
| IOT Function | Supports managing registered device IOT functionality, supports smart IoT control based on dialogue context |
|
||||||
| Control Panel | Provides web management interface, supports agent management, user management, system configuration, etc. |
|
| Control Panel | Provides Web management interface, supports agent management, user management, system configuration, etc. |
|
||||||
|
|
||||||
### In Development 🚧
|
### In Development 🚧
|
||||||
|
|
||||||
To learn about specific development progress, [click here](https://github.com/users/xinnan-tech/projects/3)
|
To learn about specific development progress, [click here](https://github.com/users/xinnan-tech/projects/3)
|
||||||
|
|
||||||
If you're a software developer, here's an [Open Letter to Developers](docs/contributor_open_letter.md). Welcome to join!
|
If you are a software developer, here is an [Open Letter to Developers](docs/contributor_open_letter.md). Welcome to join!
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Product Ecosystem 👬
|
## Product Ecosystem 👬
|
||||||
Xiaozhi is an ecosystem. When using this product, you might want to check out other excellent projects in this ecosystem:
|
Xiaozhi is an ecosystem. When using this product, you might also want to check out other excellent projects in this ecosystem
|
||||||
|
|
||||||
| Project Name | Project Link | Description |
|
| Project Name | Project Address | Project Description |
|
||||||
|:---------------------|:--------|:--------|
|
|:---------------------|:--------|:--------|
|
||||||
| Xiaozhi Android Client | [xiaozhi-android-client](https://github.com/TOM88812/xiaozhi-android-client) | A Flutter-based Android and iOS voice dialogue application supporting real-time voice interaction and text dialogue |
|
| Xiaozhi Android Client | [xiaozhi-android-client](https://github.com/TOM88812/xiaozhi-android-client) | A Flutter-based Android and iOS voice dialogue application supporting real-time voice interaction and text dialogue. |
|
||||||
| Xiaozhi PC Client | [py-xiaozhi](https://github.com/Huang-junsen/py-xiaozhi) | A Python-based AI client that allows you to experience Xiaozhi AI functionality through code without physical hardware |
|
| Xiaozhi PC Client | [py-xiaozhi](https://github.com/Huang-junsen/py-xiaozhi) | This project provides a Python-based Xiaozhi AI client, allowing you to experience Xiaozhi AI's functionality through code even without physical hardware. |
|
||||||
| Xiaozhi Java Server | [xiaozhi-esp32-server-java](https://github.com/joey-zhou/xiaozhi-esp32-server-java) | A Java-based open-source project providing complete backend service solutions |
|
| Xiaozhi Java Server | [xiaozhi-esp32-server-java](https://github.com/joey-zhou/xiaozhi-esp32-server-java) | The Java version of Xiaozhi open-source backend service is a Java-based open-source project.<br/>It includes both frontend and backend services, aiming to provide users with a complete backend service solution. |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Supported Platforms/Components 📋
|
## Supported Platforms/Components List 📋
|
||||||
|
|
||||||
### LLM Language Models
|
### LLM Language Models
|
||||||
|
|
||||||
| Usage Method | Supported Platforms | Free Platforms |
|
| Usage Method | Supported Platforms | Free Platforms |
|
||||||
|:---:|:---:|:---:|
|
|:---:|:---:|:---:|
|
||||||
| openai API | Ali Bailing, Volcano Engine Doubao, DeepSeek, ChatGLM, Gemini | ChatGLM, Gemini |
|
| openai interface call | Ali Bailian, Volcano Engine Doubao, DeepSeek, Zhipu ChatGLM, Gemini | Zhipu ChatGLM, Gemini |
|
||||||
| ollama API | Ollama | - |
|
| ollama interface call | Ollama | - |
|
||||||
| dify API | Dify | - |
|
| dify interface call | Dify | - |
|
||||||
| fastgpt API | Fastgpt | - |
|
| fastgpt interface call | Fastgpt | - |
|
||||||
| coze API | Coze | - |
|
| coze interface call | Coze | - |
|
||||||
|
|
||||||
Actually, any LLM supporting openai API calls can be integrated.
|
In fact, any LLM that supports openai interface calls can be integrated and used.
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### TTS Speech Synthesis
|
### TTS Speech Synthesis
|
||||||
|
|
||||||
| Usage Method | Supported Platforms | Free Platforms |
|
| Usage Method | Supported Platforms | Free Platforms |
|
||||||
|:---:|:---:|:---:|
|
|:---:|:---:|:---:|
|
||||||
| API Calls | EdgeTTS, Volcano Engine Doubao TTS, Tencent Cloud, Aliyun TTS, CosyVoiceSiliconflow, TTS302AI, CozeCnTTS, GizwitsTTS, ACGNTTS, OpenAITTS | EdgeTTS, CosyVoiceSiliconflow(partial) |
|
| API Call | EdgeTTS, Volcano Engine Doubao TTS, Tencent Cloud, Alibaba Cloud TTS, CosyVoiceSiliconflow, TTS302AI, CozeCnTTS, GizwitsTTS, ACGNTTS, OpenAITTS | EdgeTTS, CosyVoiceSiliconflow(partial) |
|
||||||
| Local Service | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS |
|
| Local Service | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### VAD Voice Activity Detection
|
### VAD Voice Activity Detection
|
||||||
|
|
||||||
| Type | Platform Name | Usage Method | Pricing | Notes |
|
| Type | Platform Name | Usage Method | Pricing Model | Notes |
|
||||||
|:---:|:---------:|:----:|:----:|:--:|
|
|:---:|:---------:|:----:|:----:|:--:|
|
||||||
| VAD | SileroVAD | Local Use | Free | |
|
| VAD | SileroVAD | Local Usage | Free | |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -229,26 +267,26 @@ Actually, any LLM supporting openai API calls can be integrated.
|
|||||||
|
|
||||||
| Usage Method | Supported Platforms | Free Platforms |
|
| Usage Method | Supported Platforms | Free Platforms |
|
||||||
|:---:|:---:|:---:|
|
|:---:|:---:|:---:|
|
||||||
| Local Use | FunASR, SherpaASR | FunASR, SherpaASR |
|
| Local Usage | FunASR, SherpaASR | FunASR, SherpaASR |
|
||||||
| API Calls | DoubaoASR, FunASRServer, TencentASR, AliyunASR | FunASRServer |
|
| API Call | DoubaoASR, FunASRServer, TencentASR, AliyunASR | FunASRServer |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Memory Storage
|
### Memory Storage
|
||||||
|
|
||||||
| Type | Platform Name | Usage Method | Pricing | Notes |
|
| Type | Platform Name | Usage Method | Pricing Model | Notes |
|
||||||
|:------:|:---------------:|:----:|:---------:|:--:|
|
|:------:|:---------------:|:----:|:---------:|:--:|
|
||||||
| Memory | mem0ai | API Calls | 1000 calls/month quota | |
|
| Memory | mem0ai | API Call | 1000 calls/month quota | |
|
||||||
| Memory | mem_local_short | Local Summary | Free | |
|
| Memory | mem_local_short | Local Summary | Free | |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Intent Recognition
|
### Intent Recognition
|
||||||
|
|
||||||
| Type | Platform Name | Usage Method | Pricing | Notes |
|
| Type | Platform Name | Usage Method | Pricing Model | Notes |
|
||||||
|:------:|:-------------:|:----:|:-------:|:---------------------:|
|
|:------:|:-------------:|:----:|:-------:|:---------------------:|
|
||||||
| Intent | intent_llm | API Calls | Based on LLM pricing | Uses large model for intent recognition, highly versatile |
|
| Intent | intent_llm | API Call | Based on LLM pricing | Uses large model for intent recognition, highly versatile |
|
||||||
| Intent | function_call | API Calls | Based on LLM pricing | Uses large model function calls for intent, fast and effective |
|
| Intent | function_call | API Call | Based on LLM pricing | Uses large model function calls for intent, fast and effective |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -257,10 +295,10 @@ Actually, any LLM supporting openai API calls can be integrated.
|
|||||||
| Logo | Project/Company | Description |
|
| Logo | Project/Company | Description |
|
||||||
|:---:|:---:|:---|
|
|:---:|:---:|:---|
|
||||||
| <img src="./docs/images/logo_bailing.png" width="160"> | [Bailing Voice Dialogue Robot](https://github.com/wwbin2017/bailing) | This project was inspired by [Bailing Voice Dialogue Robot](https://github.com/wwbin2017/bailing) and implemented based on it |
|
| <img src="./docs/images/logo_bailing.png" width="160"> | [Bailing Voice Dialogue Robot](https://github.com/wwbin2017/bailing) | This project was inspired by [Bailing Voice Dialogue Robot](https://github.com/wwbin2017/bailing) and implemented based on it |
|
||||||
| <img src="./docs/images/logo_tenclass.png" width="160"> | [Tenclass](https://www.tenclass.com/) | Thanks to [Tenclass](https://www.tenclass.com/) for developing standard communication protocols, multi-device compatibility solutions, and high-concurrency scenario practices for the Xiaozhi ecosystem; providing comprehensive technical documentation support for this project |
|
| <img src="./docs/images/logo_tenclass.png" width="160"> | [Tenclass](https://www.tenclass.com/) | Thanks to [Tenclass](https://www.tenclass.com/) for establishing standard communication protocols, multi-device compatibility solutions, and high-concurrency scenario practices for the Xiaozhi ecosystem; providing full-chain technical documentation support for this project |
|
||||||
| <img src="./docs/images/logo_xuanfeng.png" width="160"> | [Xuanfeng Technology](https://github.com/Eric0308) | Thanks to [Xuanfeng Technology](https://github.com/Eric0308) for contributing function call framework, MCP communication protocol, and plugin call mechanism implementation code, significantly improving front-end device (IoT) interaction efficiency and functional extensibility through standardized instruction scheduling system and dynamic expansion capabilities |
|
| <img src="./docs/images/logo_xuanfeng.png" width="160"> | [Xuanfeng Technology](https://github.com/Eric0308) | Thanks to [Xuanfeng Technology](https://github.com/Eric0308) for contributing the function call framework, MCP communication protocol, and plugin call mechanism implementation code, significantly improving front-end device (IoT) interaction efficiency and functional extensibility through standardized instruction scheduling system and dynamic expansion capabilities |
|
||||||
| <img src="./docs/images/logo_huiyuan.png" width="160"> | [Huiyuan Design](http://ui.kwd988.net/) | Thanks to [Huiyuan Design](http://ui.kwd988.net/) for providing professional visual solutions for this project, empowering product user experience with their design experience serving over a thousand enterprises |
|
| <img src="./docs/images/logo_huiyuan.png" width="160"> | [Huiyuan Design](http://ui.kwd988.net/) | Thanks to [Huiyuan Design](http://ui.kwd988.net/) for providing professional visual solutions for this project, empowering the product user experience with their design experience serving over a thousand enterprises |
|
||||||
| <img src="./docs/images/logo_qinren.png" width="160"> | [Xi'an Qinren Information Technology](https://www.029app.com/) | Thanks to [Xi'an Qinren Information Technology](https://www.029app.com/) for deepening this project's visual system, ensuring consistency and extensibility of overall design style in multi-scenario applications |
|
| <img src="./docs/images/logo_qinren.png" width="160"> | [Xi'an Qinren Information Technology](https://www.029app.com/) | Thanks to [Xi'an Qinren Information Technology](https://www.029app.com/) for deepening the visual system of this project, ensuring consistency and extensibility of the overall design style in multi-scenario applications |
|
||||||
|
|
||||||
|
|
||||||
<a href="https://star-history.com/#xinnan-tech/xiaozhi-esp32-server&Date">
|
<a href="https://star-history.com/#xinnan-tech/xiaozhi-esp32-server&Date">
|
||||||
@@ -270,4 +308,4 @@ Actually, any LLM supporting openai API calls can be integrated.
|
|||||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=xinnan-tech/xiaozhi-esp32-server&type=Date" />
|
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=xinnan-tech/xiaozhi-esp32-server&type=Date" />
|
||||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=xinnan-tech/xiaozhi-esp32-server&type=Date" />
|
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=xinnan-tech/xiaozhi-esp32-server&type=Date" />
|
||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -104,7 +104,15 @@ VAD:
|
|||||||
|
|
||||||
参考教程[ESP32设备与HomeAssistant集成指南](./homeassistant-integration.md)
|
参考教程[ESP32设备与HomeAssistant集成指南](./homeassistant-integration.md)
|
||||||
|
|
||||||
### 8、更多问题,可联系我们反馈 💬
|
### 8、如何开启手机注册智控台 📱
|
||||||
|
|
||||||
|
参考教程[阿里云短信集成指南](./ali-sms-integration.md)
|
||||||
|
|
||||||
|
### 9、如何开启视觉模型实现拍照识物 📷
|
||||||
|
|
||||||
|
参考教程[视觉模型使用指南](./mcp-vision-integration.md)
|
||||||
|
|
||||||
|
### 10、更多问题,可联系我们反馈 💬
|
||||||
|
|
||||||
可以在[issues](https://github.com/xinnan-tech/xiaozhi-esp32-server/issues)提交您的问题。
|
可以在[issues](https://github.com/xinnan-tech/xiaozhi-esp32-server/issues)提交您的问题。
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# 阿里云短信集成指南
|
||||||
|
|
||||||
|
登录阿里云控制台,进入“短信服务”页面:https://dysms.console.aliyun.com/overview
|
||||||
|
|
||||||
|
## 第一步 添加签名
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
以上步骤,会得到签名,请把它写入到智控台参数,`aliyun.sms.sign_name`
|
||||||
|
|
||||||
|
## 第二步 添加模版
|
||||||
|

|
||||||
|
|
||||||
|
以上步骤,会得到模版code,请把它写入到智控台参数,`aliyun.sms.sms_code_template_code`
|
||||||
|
|
||||||
|
注意,签名要等7个工作日,等运营商报备成功后才能发送成功。
|
||||||
|
|
||||||
|
注意,签名要等7个工作日,等运营商报备成功后才能发送成功。
|
||||||
|
|
||||||
|
注意,签名要等7个工作日,等运营商报备成功后才能发送成功。
|
||||||
|
|
||||||
|
可以等报备成功后,再继续往下操作。
|
||||||
|
|
||||||
|
## 第三步 创建短信账户和开通权限
|
||||||
|
|
||||||
|
登录阿里云控制台,进入“访问控制”页面:https://ram.console.aliyun.com/overview?activeTab=overview
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
以上步骤,会得到access_key_id和access_key_secret,请把它写入到智控台参数,`aliyun.sms.access_key_id`、`aliyun.sms.access_key_secret`
|
||||||
|
## 第四步 启动手机注册功能
|
||||||
|
|
||||||
|
1、正常来说,以上信息都填完后,会有这个效果,如果没有,可能缺少了某个步骤
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2、开启允许非管理员用户可注册,将参数`server.allow_user_register`设置成`true`
|
||||||
|
|
||||||
|
3、开启手机注册功能,将参数`server.enable_mobile_register`设置成`true`
|
||||||
|

|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
# 全模块源码部署自动升级方法
|
||||||
|
|
||||||
|
本教程是方便全模块源码部署的爱好者,如何通过自动命令,自动拉取源码,自动编译,自动启动端口运行。实现最高效率的升级系统。
|
||||||
|
|
||||||
|
本项目的测试平台`https://2662r3426b.vicp.fun`,从开放以来就使用了该方法,效果良好。
|
||||||
|
|
||||||
|
# 开始条件
|
||||||
|
- 你的电脑/服务器是linux操作系统
|
||||||
|
- 你已经跑通了整个流程
|
||||||
|
- 你喜欢跟进最新功能,但是觉得每次手动部署有点麻烦,期待有一个自动更新的方法
|
||||||
|
|
||||||
|
第二个条件必须满足,因为本教程所涉及的某些文件,JDK、Node.js环境、Conda环境等,是需要你跑通整个流程才有的,如果你没有跑通,当我讲到某个文件的时候,你可能就不知道什么意思。
|
||||||
|
|
||||||
|
# 教程效果
|
||||||
|
- 解决国内不能拉取最新项目源码问题
|
||||||
|
- 自动拉取代码编译前端文件
|
||||||
|
- 自动拉取代码编译java文件,自动杀掉8002端口,自动启动8002端口
|
||||||
|
- 自动拉取python代码,自动杀掉8000端口,自动启动8000端口
|
||||||
|
|
||||||
|
# 第一步 选好你的项目目录
|
||||||
|
|
||||||
|
例如,我规划了我的项目目录是,这是一个新建的空白的目录,如果你不想出错,可以和我一样
|
||||||
|
```
|
||||||
|
/home/system/xiaozhi
|
||||||
|
```
|
||||||
|
|
||||||
|
# 第二步 克隆本项目
|
||||||
|
此刻,先要执行第一句话,拉取源码,这句命令适用于国内网络的服务器和电脑,无需翻墙
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /home/system/xiaozhi
|
||||||
|
git clone https://ghproxy.net/https://github.com/xinnan-tech/xiaozhi-esp32-server.git
|
||||||
|
```
|
||||||
|
|
||||||
|
执行完后,你的项目目录会多了一个文件夹`xiaozhi-esp32-server`,这个就是项目的源码
|
||||||
|
|
||||||
|
# 第三步 复制基础的文件
|
||||||
|
|
||||||
|
如果你之前已经跑通了整个流程,对funasr的模型文件`xiaozhi-server/models/SenseVoiceSmall/model.pt`和你的私有配置文件`xiaozhi-server/data/.config.yaml`这两个文件不会陌生。
|
||||||
|
|
||||||
|
此刻你需要把`model.pt`文件复制到新的目录去,你可以这样
|
||||||
|
```
|
||||||
|
cp 你原来的.config.yaml完整路径 /home/system/xiaozhi/xiaozhi-esp32-server/main/xiaozhi-server/data/.config.yaml
|
||||||
|
cp 你原来的model.pt完整路径 /home/system/xiaozhi/xiaozhi-esp32-server/main/xiaozhi-server/models/SenseVoiceSmall/model.pt
|
||||||
|
```
|
||||||
|
|
||||||
|
# 第四步 建立三个自动编译文件
|
||||||
|
|
||||||
|
## 4.1 自动编译mananger-web模块
|
||||||
|
在`/home/system/xiaozhi/`目录下,创建名字为`update_8001.sh`的文件,内容如下
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /home/system/xiaozhi/xiaozhi-esp32-server
|
||||||
|
git fetch --all
|
||||||
|
git reset --hard
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
|
||||||
|
cd /home/system/xiaozhi/xiaozhi-esp32-server/main/manager-web
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
rm -rf /home/system/xiaozhi/manager-web
|
||||||
|
mv /home/system/xiaozhi/xiaozhi-esp32-server/main/manager-web/dist /home/system/xiaozhi/manager-web
|
||||||
|
```
|
||||||
|
|
||||||
|
保存好后执行赋权命令
|
||||||
|
```
|
||||||
|
chmod 777 update_8001.sh
|
||||||
|
```
|
||||||
|
执行完后,继续往下
|
||||||
|
|
||||||
|
## 4.2 自动编译运行manager-api模块
|
||||||
|
在`/home/system/xiaozhi/`目录下,创建名字为`update_8002.sh`的文件,内容如下
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /home/system/xiaozhi/xiaozhi-esp32-server
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
|
||||||
|
cd /home/system/xiaozhi/xiaozhi-esp32-server/main/manager-api
|
||||||
|
rm -rf target
|
||||||
|
mvn clean package -Dmaven.test.skip=true
|
||||||
|
cd /home/system/xiaozhi/
|
||||||
|
|
||||||
|
# 查找占用8002端口的进程号
|
||||||
|
PID=$(sudo netstat -tulnp | grep 8002 | awk '{print $7}' | cut -d'/' -f1)
|
||||||
|
|
||||||
|
rm -rf /home/system/xiaozhi/xiaozhi-esp32-api.jar
|
||||||
|
mv /home/system/xiaozhi/xiaozhi-esp32-server/main/manager-api/target/xiaozhi-esp32-api.jar /home/system/xiaozhi/xiaozhi-esp32-api.jar
|
||||||
|
|
||||||
|
# 检查是否找到进程号
|
||||||
|
if [ -z "$PID" ]; then
|
||||||
|
echo "没有找到占用8002端口的进程"
|
||||||
|
else
|
||||||
|
echo "找到占用8002端口的进程,进程号为: $PID"
|
||||||
|
# 杀掉进程
|
||||||
|
kill -9 $PID
|
||||||
|
kill -9 $PID
|
||||||
|
echo "已杀掉进程 $PID"
|
||||||
|
fi
|
||||||
|
|
||||||
|
nohup java -jar xiaozhi-esp32-api.jar --spring.profiles.active=dev &
|
||||||
|
```
|
||||||
|
|
||||||
|
保存好后执行赋权命令
|
||||||
|
```
|
||||||
|
chmod 777 update_8002.sh
|
||||||
|
```
|
||||||
|
执行完后,继续往下
|
||||||
|
|
||||||
|
## 4.3 自动编译运行Python项目
|
||||||
|
在`/home/system/xiaozhi/`目录下,创建名字为`update_8000.sh`的文件,内容如下
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /home/system/xiaozhi/xiaozhi-esp32-server
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# 查找占用8000端口的进程号
|
||||||
|
PID=$(sudo netstat -tulnp | grep 8000 | awk '{print $7}' | cut -d'/' -f1)
|
||||||
|
|
||||||
|
# 检查是否找到进程号
|
||||||
|
if [ -z "$PID" ]; then
|
||||||
|
echo "没有找到占用8000端口的进程"
|
||||||
|
else
|
||||||
|
echo "找到占用8000端口的进程,进程号为: $PID"
|
||||||
|
# 杀掉进程
|
||||||
|
kill -9 $PID
|
||||||
|
kill -9 $PID
|
||||||
|
echo "已杀掉进程 $PID"
|
||||||
|
fi
|
||||||
|
cd main/xiaozhi-server
|
||||||
|
pip install -r requirements.txt
|
||||||
|
nohup python app.py >/dev/null &
|
||||||
|
```
|
||||||
|
|
||||||
|
保存好后执行赋权命令
|
||||||
|
```
|
||||||
|
chmod 777 update_8000.sh
|
||||||
|
```
|
||||||
|
执行完后,继续往下
|
||||||
|
|
||||||
|
# 日常更新
|
||||||
|
|
||||||
|
以上的脚本都建立好后,日常更新,我们只要依次执行以下命令就可以做到自动更新和启动
|
||||||
|
|
||||||
|
```
|
||||||
|
# 进入pyhton环境
|
||||||
|
conda activate xiaozhi-esp32-server
|
||||||
|
cd /home/system/xiaozhi
|
||||||
|
# 更新并启动Java程序
|
||||||
|
./update_8001.sh
|
||||||
|
# 更新web程序
|
||||||
|
./update_8002.sh
|
||||||
|
# 更新并启动python程序
|
||||||
|
./update_8000.sh
|
||||||
|
# 查看Java日志
|
||||||
|
tail -f nohup.out
|
||||||
|
# 查看Python日志
|
||||||
|
tail -f /home/system/xiaozhi/xiaozhi-esp32-server/main/xiaozhi-server/tmp/server.log
|
||||||
|
```
|
||||||
|
|
||||||
|
# 注意事项
|
||||||
|
测试平台`https://2662r3426b.vicp.fun`,是使用nginx做了反向代理。nginx.conf详细配置可以[参考这里](https://github.com/xinnan-tech/xiaozhi-esp32-server/issues/791)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# 基于虾哥编译好的固件配置自定义服务器
|
# 基于虾哥编译好的固件配置自定义服务器
|
||||||
|
|
||||||
## 第1步 确认版本
|
## 第1步 确认版本
|
||||||
烧录虾哥已经编译好的1.6.1版本固件
|
烧录虾哥已经编译好的[1.6.1版本以上固件](https://github.com/78/xiaozhi-esp32/releases)
|
||||||
|
|
||||||
## 第2步 准备你的ota地址
|
## 第2步 准备你的ota地址
|
||||||
如果你按照教程使用的是全模块部署,就应该会有ota地址。
|
如果你按照教程使用的是全模块部署,就应该会有ota地址。
|
||||||
@@ -29,6 +29,7 @@ wss://2662r3426b.vicp.fun/xiaozhi/v1/
|
|||||||
|
|
||||||
## 第3步 进入配网模式
|
## 第3步 进入配网模式
|
||||||
进入机器的配网模式,在页面顶部,点击“高级选项”,在里面输入你服务器的`ota`地址,点击保存。重启设备
|
进入机器的配网模式,在页面顶部,点击“高级选项”,在里面输入你服务器的`ota`地址,点击保存。重启设备
|
||||||
|

|
||||||
|
|
||||||
## 第4步 唤醒小智,查看日志输出
|
## 第4步 唤醒小智,查看日志输出
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
登录AutoDL,租赁镜像
|
||||||
|
选择镜像:
|
||||||
|
```
|
||||||
|
PyTorch / 2.1.0 / 3.10(ubuntu22.04) / cuda 12.1
|
||||||
|
```
|
||||||
|
|
||||||
|
机器开机后,设置学术加速
|
||||||
|
```
|
||||||
|
source /etc/network_turbo
|
||||||
|
```
|
||||||
|
|
||||||
|
进入工作目录
|
||||||
|
```
|
||||||
|
cd autodl-tmp/
|
||||||
|
```
|
||||||
|
|
||||||
|
拉取项目
|
||||||
|
```
|
||||||
|
git clone https://gitclone.com/github.com/fishaudio/fish-speech.git ; cd fish-speech
|
||||||
|
```
|
||||||
|
|
||||||
|
安装依赖
|
||||||
|
```
|
||||||
|
pip install -e.
|
||||||
|
```
|
||||||
|
|
||||||
|
如果报错,安装portaudio
|
||||||
|
```
|
||||||
|
apt-get install portaudio19-dev -y
|
||||||
|
```
|
||||||
|
|
||||||
|
安装后执行
|
||||||
|
```
|
||||||
|
pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu121
|
||||||
|
```
|
||||||
|
|
||||||
|
下载模型
|
||||||
|
```
|
||||||
|
cd tools
|
||||||
|
python download_models.py
|
||||||
|
```
|
||||||
|
|
||||||
|
下载完模型后运行接口
|
||||||
|
```
|
||||||
|
python -m tools.api_server --listen 0.0.0.0:6006
|
||||||
|
```
|
||||||
|
|
||||||
|
然后用浏览器去到aotodl实例页面
|
||||||
|
```
|
||||||
|
https://autodl.com/console/instance/list
|
||||||
|
```
|
||||||
|
|
||||||
|
如下图点击你刚才机器的`自定义服务`按钮,开启端口转发服务
|
||||||
|

|
||||||
|
|
||||||
|
端口转发服务设置完成后,你本地电脑打开网址`http://localhost:6006/`,就可以访问fish-speech的接口了
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
如果你是单模块部署,核心配置如下
|
||||||
|
```
|
||||||
|
selected_module:
|
||||||
|
TTS: FishSpeech
|
||||||
|
TTS:
|
||||||
|
FishSpeech:
|
||||||
|
reference_audio: ["config/assets/wakeup_words.wav",]
|
||||||
|
reference_text: ["哈啰啊,我是小智啦,声音好听的台湾女孩一枚,超开心认识你耶,最近在忙啥,别忘了给我来点有趣的料哦,我超爱听八卦的啦",]
|
||||||
|
api_key: "123"
|
||||||
|
api_url: "http://127.0.0.1:6006/v1/tts"
|
||||||
|
```
|
||||||
|
|
||||||
|
然后重启服务
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
# ESP32设备与HomeAssistant集成指南
|
# 小智ESP32-开源服务端与HomeAssistant集成指南
|
||||||
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
@@ -7,26 +11,58 @@
|
|||||||
## 前提条件
|
## 前提条件
|
||||||
|
|
||||||
- 已安装并配置好`HomeAssistant`
|
- 已安装并配置好`HomeAssistant`
|
||||||
- 已经在HomeAssistant中集成`Xiaomi Home`,并将米家的设备导入进`HomeAssistant`
|
|
||||||
- `xiaozhi-esp32-server智控台`能正常使用
|
|
||||||
- 本次我选择的模型是:免费的ChatGLM,它支持functioncall函数调用
|
- 本次我选择的模型是:免费的ChatGLM,它支持functioncall函数调用
|
||||||
|
|
||||||
## 网络环境
|
## 开始前的操作(必要)
|
||||||
|
|
||||||
|
### 1. 获取HA的网络网络地址信息
|
||||||
|
|
||||||
|
请访问你Home Assistant的网络地址,例如,我的HA的地址是192.168.4.7,端口则是默认的8123,则在浏览器打开
|
||||||
|
|
||||||
1、我的`HomeAssistant`部署在下面,版本是`2025.3.4`
|
|
||||||
```
|
```
|
||||||
http://192.168.4.7:8123
|
http://192.168.4.7:8123
|
||||||
```
|
```
|
||||||
|
|
||||||
2、我的`xiaozhi-esp32-server智控台`和`HomeAssistant`部署在同一台机器的另一个端口,版本是`0.3.10`
|
> 手动查询 HA 的 IP 地址方法**(仅限小智esp32-server和HA部署在同一个网络设备[例如同一个wifi]下)**:
|
||||||
|
>
|
||||||
|
> 1. 进入 Home Assistant(前端)。
|
||||||
|
>
|
||||||
|
> 2. 点击左下角 **设置(Settings)** → **系统(System)** → **网络(Network)**。
|
||||||
|
>
|
||||||
|
> 3. 滑到最底部`Home Assistant 网址(Home Assistant website)`区域,在`本地网络(local network)`中,点击`眼睛`按钮,可以看到当前使用的 IP 地址(如 `192.168.1.10`)和网络接口。点击`复制连接(copy link)`可以直接复制。
|
||||||
|
>
|
||||||
|
> 
|
||||||
|
|
||||||
|
或,您已经设置了直接可以访问的Home Assistant的OAuth地址,您也可以在浏览器内直接访问
|
||||||
|
|
||||||
```
|
```
|
||||||
http://192.168.4.7:8002
|
http://homeassistant.local:8123
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 2. 登录`Home Assistant`拿到开发密钥
|
||||||
|
|
||||||
## 配置步骤
|
登录`HomeAssistant`,点击`左下角头像 -> 个人`,切换`安全`导航栏,划到底部`长期访问令牌`生成api_key,并复制保存,后续的方法都需要使用这个api key且仅出现一次(小tips: 您可以保存生成的二维码图像,后续可以扫描二维码再此提取api key)。
|
||||||
|
|
||||||
### 1. 登录`HomeAssistant`整理需要控制的设备清单
|
## 方法1:小智社区共建的HA调用功能
|
||||||
|
|
||||||
|
### 功能描述
|
||||||
|
|
||||||
|
- 如您后续需要增加新的设备,该方法需要手动重启`xiaozhi-esp32-server服务端`以此更新设备信息**(重要**)。
|
||||||
|
|
||||||
|
- 需要您确保已经在HomeAssistant中集成`Xiaomi Home`,并将米家的设备导入进`HomeAssistant`。
|
||||||
|
|
||||||
|
- 需要您确保`xiaozhi-esp32-server智控台`能正常使用。
|
||||||
|
|
||||||
|
- 我的`xiaozhi-esp32-server智控台`和`HomeAssistant`部署在同一台机器的另一个端口,版本是`0.3.10`
|
||||||
|
|
||||||
|
```
|
||||||
|
http://192.168.4.7:8002
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 配置步骤
|
||||||
|
|
||||||
|
#### 1. 登录`HomeAssistant`整理需要控制的设备清单
|
||||||
|
|
||||||
登录`HomeAssistant`,点击`左下角的设置`,然后进入`设备与服务`,再点击顶部的`实体`。
|
登录`HomeAssistant`,点击`左下角的设置`,然后进入`设备与服务`,再点击顶部的`实体`。
|
||||||
|
|
||||||
@@ -56,12 +92,7 @@ http://192.168.4.7:8002
|
|||||||
这段字符,我们成为“设备清单字符”需要保存好,等一下有用。
|
这段字符,我们成为“设备清单字符”需要保存好,等一下有用。
|
||||||
|
|
||||||
|
|
||||||
### 2. 登录`HomeAssistant`拿到开发密钥
|
#### 2. 登录`智控台`
|
||||||
|
|
||||||
登录`HomeAssistant`,点击`左下角个人`,切换`安全`导航栏,划到底部`长期访问令牌`生成api_key。
|
|
||||||
|
|
||||||
|
|
||||||
### 3. 登录`智控台`
|
|
||||||
|
|
||||||
使用管理员账号,登录`智控台`。点击顶部菜单`参数管理`,搜索`plugins.home_assistant.`,会有三条结果出来
|
使用管理员账号,登录`智控台`。点击顶部菜单`参数管理`,搜索`plugins.home_assistant.`,会有三条结果出来
|
||||||
|
|
||||||
@@ -77,7 +108,7 @@ http://192.168.4.7:8123
|
|||||||
编辑`plugins.home_assistant.api_key`,把你从`HomeAssistant`复制过来的密钥,粘贴进去
|
编辑`plugins.home_assistant.api_key`,把你从`HomeAssistant`复制过来的密钥,粘贴进去
|
||||||
|
|
||||||
|
|
||||||
### 4. 设置`意图识别`函数
|
#### 3. 设置`意图识别`函数
|
||||||
|
|
||||||
在智控台,点击顶部菜单“模型配置”,在左侧栏,找到“意图识别”,找到id为`Intent_function_call`的意图,点击编辑
|
在智控台,点击顶部菜单“模型配置”,在左侧栏,找到“意图识别”,找到id为`Intent_function_call`的意图,点击编辑
|
||||||
|
|
||||||
@@ -94,18 +125,132 @@ change_role;get_weather;get_news;play_music
|
|||||||
change_role;get_weather;get_news;play_music;hass_get_state;hass_set_state
|
change_role;get_weather;get_news;play_music;hass_get_state;hass_set_state
|
||||||
```
|
```
|
||||||
|
|
||||||
### 6. 手动重启xiaozhi-server
|
#### 4. 手动重启xiaozhi-server
|
||||||
|
|
||||||
重启xiaozhi-server程序
|
重启xiaozhi-server程序
|
||||||
|
|
||||||
|
|
||||||
### 5. 确认角色配置是否设置了函数意图识别
|
#### 5. 确认角色配置是否设置了函数意图识别
|
||||||
|
|
||||||
在智控台,点击顶部菜单“智能体管理”,找到设备所在的智能体,点击“配置角色”
|
在智控台,点击顶部菜单“智能体管理”,找到设备所在的智能体,点击“配置角色”
|
||||||
|
|
||||||
确认意图识别(Intent),是否选择“函数调用意图识别”
|
确认意图识别(Intent),是否选择“函数调用意图识别”
|
||||||
|
|
||||||
|
|
||||||
### 6. 唤醒设别进行控制
|
#### 6. 唤醒设别进行控制
|
||||||
|
|
||||||
尝试和esp32说,“打开XXX灯”
|
尝试和esp32说,“打开XXX灯”
|
||||||
|
|
||||||
|
## 方法2:小智将Home Assistant的语音助手作为LLM工具
|
||||||
|
|
||||||
|
### 功能描述
|
||||||
|
|
||||||
|
- 该方法有一个比较严重的缺点——**该方法无法使用小智开源生态的function_call插件功能的能力**,因为使用Home Assistant作为小智的LLM工具会将意图识别能力转让给Home Assistant。但是**这个方法是能体验到原生的Home Assistant操作功能,且小智的聊天能力不变**。如实在介意可以使用同样是Home Assistant支持的[方法3](##方法3:使用Home Assistant的MCP服务(推荐)),能够最大程度体验到Home Assistant的功能。
|
||||||
|
|
||||||
|
### 配置步骤:
|
||||||
|
|
||||||
|
#### 1. 配置Home Assistant的大模型语音助手。
|
||||||
|
|
||||||
|
**需要您提前配置好Home Assistant的语音助手或大模型工具。**
|
||||||
|
|
||||||
|
#### 2. 获取Home Assistant的语言助手的Agent ID.
|
||||||
|
|
||||||
|
1. 进入Home Assistant页面内。左侧点击`开发者助手`。
|
||||||
|
2. 在打开的`开发者助手`内,点击`动作`选项卡(如图示操作1),在页面内的选项栏`动作`中,找到或输入`conversation.process(对话-处理)`并选择`对话(conversation): 处理`(如图示操作2)。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3. 在页面内勾选`代理(agent)`选项,在变成常亮的`对话代理(conversation agent)`内选择您步骤一配置好的语音助手名称,如图示,我这边配置好的是`ZhipuAi`并选择。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4. 选中后,点击表单左下方的`进入YAML模式`。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5. 复制其中的agent-id的值,例如图示中我的是`01JP2DYMBDF7F4ZA2DMCF2AGX2`(仅供参考)。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
6. 切换到小智开源服务端`xiaozhi-esp32-server`的`config.yaml`文件内,在LLM配置中,找到Home Assistant,设置您的Home Assistant的网络地址,Api key和刚刚查询到的agent_id。
|
||||||
|
7. 修改`config.yaml`文件内的`selected_module`属性的`LLM`为`HomeAssistant`,`Intent`为`nointent`。
|
||||||
|
8. 重启小智开源服务端`xiaozhi-esp32-server`即可正常使用。
|
||||||
|
|
||||||
|
## 方法3:使用Home Assistant的MCP服务(推荐)
|
||||||
|
|
||||||
|
### 功能描述
|
||||||
|
|
||||||
|
- 需要您提前在Home Assistant内集成并安装好HA集成——[Model Context Protocol Server](https://www.home-assistant.io/integrations/mcp_server/)。
|
||||||
|
|
||||||
|
- 这个方法与方法2都是HA官方提供的解决方法,与方法2不同的是,您可以正常使用小智开源服务端`xiaozhi-esp32-server`的开源共建的插件,同时允许您随意使用任何一个支持function_call功能的LLM大模型。
|
||||||
|
|
||||||
|
### 配置步骤
|
||||||
|
|
||||||
|
#### 1. 安装Home Assistant的MCP服务集成。
|
||||||
|
|
||||||
|
集成官方网址——[Model Context Protocol Server](https://www.home-assistant.io/integrations/mcp_server/)。。
|
||||||
|
|
||||||
|
或跟随以下手动操作。
|
||||||
|
|
||||||
|
> - 前往Home Assistant页面的**[设置 > 设备和服务(Settings > Devices & Services.)](https://my.home-assistant.io/redirect/integrations)**。
|
||||||
|
>
|
||||||
|
> - 在右下角,选择 **[添加集成(Add Integration)](https://my.home-assistant.io/redirect/config_flow_start?domain=mcp_server)**按钮。
|
||||||
|
>
|
||||||
|
> - 从列表中选择**模型上下文协议服务器(Model Context Protocol Server)**。
|
||||||
|
>
|
||||||
|
> - 按照屏幕上的说明完成设置。
|
||||||
|
|
||||||
|
#### 2. 配置小智开源服务端MCP配置信息
|
||||||
|
|
||||||
|
|
||||||
|
进入`data`目录,找到`.mcp_server_settings.json`文件。
|
||||||
|
|
||||||
|
如果你的`data`目录下没有`.mcp_server_settings.json`文件,
|
||||||
|
- 请把在`xiaozhi-server`文件夹根目录的`mcp_server_settings.json`文件复制到`data`目录下,并重命名为`.mcp_server_settings.json`
|
||||||
|
- 或[下载这个文件](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/main/xiaozhi-server/mcp_server_settings.json),下载到`data`目录下,并重命名为`.mcp_server_settings.json`
|
||||||
|
|
||||||
|
|
||||||
|
修改`"mcpServers"`里的这部分的内容:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"Home Assistant": {
|
||||||
|
"command": "mcp-proxy",
|
||||||
|
"args": [
|
||||||
|
"http://YOUR_HA_HOST/mcp_server/sse"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"API_ACCESS_TOKEN": "YOUR_API_ACCESS_TOKEN"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
注意:
|
||||||
|
|
||||||
|
1. **替换配置:**
|
||||||
|
- 替换`args`内的`YOUR_HA_HOST`为您的HA服务地址,如果你的服务地址已经包含了https/http字样(例如`http://192.168.1.101:8123`),则只需要填入`192.168.1.101:8123`即可。
|
||||||
|
- 将`env`内`API_ACCESS_TOKEN`的`YOUR_API_ACCESS_TOKEN`替换成您之前获取到的开发密钥api key。
|
||||||
|
2. **如果你添加配置是在`"mcpServers"`的括号内后续没有新的`mcpServers`的配置时,需要把最后的逗号`,`移除**,否则可能会解析失败。
|
||||||
|
|
||||||
|
**最后效果参考以下(参考如下)**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"mcpServers": {
|
||||||
|
"Home Assistant": {
|
||||||
|
"command": "mcp-proxy",
|
||||||
|
"args": [
|
||||||
|
"http://192.168.1.101:8123/mcp_server/sse"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"API_ACCESS_TOKEN": "abcd.efghi.jkl"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. 配置小智开源服务端的系统配置
|
||||||
|
|
||||||
|
1. **选择任意一款支持function_call的LLM大模型作为小智的LLM聊天助手(但不要选择Home Assistant作为LLM工具)**,本次我选择的模型是:免费的ChatGLM,它支持functioncall函数调用,但部分时候调用不太稳定,如果像追求稳定建议把LLM设置成:DoubaoLLM,使用的具体model_name是:doubao-1-5-pro-32k-250115。
|
||||||
|
|
||||||
|
2. 切换到小智开源服务端`xiaozhi-esp32-server`的`config.yaml`文件内,设置您的LLM大模型配置,并且将`selected_module`配置的`Intent`调整为`function_call`。
|
||||||
|
|
||||||
|
3. 重启小智开源服务端`xiaozhi-esp32-server`即可正常使用。
|
||||||
|
After Width: | Height: | Size: 133 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 109 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 386 KiB |
|
After Width: | Height: | Size: 518 KiB |
|
After Width: | Height: | Size: 361 KiB |
|
After Width: | Height: | Size: 205 KiB |
|
After Width: | Height: | Size: 429 KiB |
|
After Width: | Height: | Size: 248 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,171 @@
|
|||||||
|
# 视觉模型使用指南
|
||||||
|
本教程分为两部分:
|
||||||
|
- 第一部分:单模块运行xiaozhi-server开启视觉模型
|
||||||
|
- 第二部分:全模块运行时,如何开启视觉模型
|
||||||
|
|
||||||
|
开启视觉模型前,你需要准备三件事:
|
||||||
|
- 你需要准备一台带摄像头的设备,而且这台设备已经在虾哥仓库里,实现了调用摄像头功能。例如`立创·实战派ESP32-S3开发板`
|
||||||
|
- 你设备固件的版本升级到1.6.6及以上
|
||||||
|
- 你已经成功跑通基础对话模块
|
||||||
|
|
||||||
|
## 单模块运行xiaozhi-server开启视觉模型
|
||||||
|
|
||||||
|
### 第一步确认网络
|
||||||
|
由于视觉模型会默认启动8003端口。
|
||||||
|
|
||||||
|
如果你是docker运行,请确认一下你的`docker-compose.yml`是否放了`8003`端口,如果没有就更新最新的`docker-compose.yml`文件
|
||||||
|
|
||||||
|
如果你是源码运行,确认防火墙是否放行`8003`端口
|
||||||
|
|
||||||
|
### 第二步选择你的视觉模型
|
||||||
|
打开你的`data/.config.yaml`文件,设置你的`selected_module.VLLM`设置为某个视觉模型。目前我们已经支持`openai`类型接口的视觉模型。`ChatGLMVLLM`就是其中一款兼容`openai`的模型。
|
||||||
|
|
||||||
|
```
|
||||||
|
selected_module:
|
||||||
|
VAD: ..
|
||||||
|
ASR: ..
|
||||||
|
LLM: ..
|
||||||
|
VLLM: ChatGLMVLLM
|
||||||
|
TTS: ..
|
||||||
|
Memory: ..
|
||||||
|
Intent: ..
|
||||||
|
```
|
||||||
|
|
||||||
|
假设我们使用`ChatGLMVLLM`作为视觉模型,那我们需要先登录[智谱AI](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)网站,申请密钥。如果你之前已经申请过了密钥,可以复用这个密钥。
|
||||||
|
|
||||||
|
在你的配置文件中,增加这个配置,如果已经有了这个配置,就设置好你的api_key。
|
||||||
|
|
||||||
|
```
|
||||||
|
VLLM:
|
||||||
|
ChatGLMVLLM:
|
||||||
|
api_key: 你的api_key
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第三步启动xiaozhi-server服务
|
||||||
|
如果你是源码,就输入命令启动
|
||||||
|
```
|
||||||
|
python app.py
|
||||||
|
```
|
||||||
|
如果你是docker运行,就重启容器
|
||||||
|
```
|
||||||
|
docker restart xiaozhi-esp32-server
|
||||||
|
```
|
||||||
|
|
||||||
|
启动后会输出以下内容的日志。
|
||||||
|
|
||||||
|
```
|
||||||
|
2025-06-01 **** - OTA接口是 http://192.168.4.7:8003/xiaozhi/ota/
|
||||||
|
2025-06-01 **** - 视觉分析接口是 http://192.168.4.7:8003/mcp/vision/explain
|
||||||
|
2025-06-01 **** - Websocket地址是 ws://192.168.4.7:8000/xiaozhi/v1/
|
||||||
|
2025-06-01 **** - =======上面的地址是websocket协议地址,请勿用浏览器访问=======
|
||||||
|
2025-06-01 **** - 如想测试websocket请用谷歌浏览器打开test目录下的test_page.html
|
||||||
|
2025-06-01 **** - =============================================================
|
||||||
|
```
|
||||||
|
|
||||||
|
启动后,使用使用浏览器打开日志里`视觉分析接口`连接。看看输出了什么?如果你是linux,没有浏览器,你可以执行这个命令:
|
||||||
|
```
|
||||||
|
curl -i 你的视觉分析接口
|
||||||
|
```
|
||||||
|
|
||||||
|
正常来说会这样显示
|
||||||
|
```
|
||||||
|
MCP Vision 接口运行正常,视觉解释接口地址是:http://xxxx:8003/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
请注意,如果你是公网部署,或者docker部署,一定要改一下你的`data/.config.yaml`里这个配置
|
||||||
|
```
|
||||||
|
server:
|
||||||
|
vision_explain: http://你的ip或者域名:端口号/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
为什么呢?因为视觉解释接口需要下发到设备,如果你的地址是局域网地址,或者是docker内部地址,设备是无法访问的。
|
||||||
|
|
||||||
|
假设你的公网地址是`111.111.111.111`,那么`vision_explain`应该这么配
|
||||||
|
|
||||||
|
```
|
||||||
|
server:
|
||||||
|
vision_explain: http://111.111.111.111:8003/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你的MCP Vision 接口运行正常,且你也试着用浏览器访问正常打开下发的`视觉解释接口地址`,请继续下一步
|
||||||
|
|
||||||
|
### 第四步 设备唤醒开启
|
||||||
|
|
||||||
|
对设备说“请打开摄像头,说你你看到了什么”
|
||||||
|
|
||||||
|
留意xiaozhi-server的日志输出,看看有没有报错。
|
||||||
|
|
||||||
|
|
||||||
|
## 全模块运行时,如何开启视觉模型
|
||||||
|
|
||||||
|
### 第一步 确认网络
|
||||||
|
由于视觉模型会默认启动8003端口。
|
||||||
|
|
||||||
|
如果你是docker运行,请确认一下你的`docker-compose_all.yml`是否映射了`8003`端口,如果没有就更新最新的`docker-compose_all.yml`文件
|
||||||
|
|
||||||
|
如果你是源码运行,确认防火墙是否放行`8003`端口
|
||||||
|
|
||||||
|
### 第二步 确认你配置文件
|
||||||
|
|
||||||
|
打开你的`data/.config.yaml`文件,确认一下你的配置文件的结构,是否和`data/config_from_api.yaml`一样。如果不一样,或缺少某项,请补齐。
|
||||||
|
|
||||||
|
### 第三步 配置视觉模型密钥
|
||||||
|
|
||||||
|
那我们需要先登录[智谱AI](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)网站,申请密钥。如果你之前已经申请过了密钥,可以复用这个密钥。
|
||||||
|
|
||||||
|
登录`智控台`,顶部菜单点击`模型配置`,在左侧栏点击`视觉打语言模型`,找到`VLLM_ChatGLMVLLM`,点击修改按钮,在弹框中,在`API密钥`输入你密钥,点击保存。
|
||||||
|
|
||||||
|
保存成功后,去到你需要测试的智能体哪里,点击`配置角色`,在打开的内容里,查看`视觉大语言模型(VLLM)`是否选择了刚才的视觉模型。点击保存。
|
||||||
|
|
||||||
|
### 第三步 启动xiaozhi-server模块
|
||||||
|
如果你是源码,就输入命令启动
|
||||||
|
```
|
||||||
|
python app.py
|
||||||
|
```
|
||||||
|
如果你是docker运行,就重启容器
|
||||||
|
```
|
||||||
|
docker restart xiaozhi-esp32-server
|
||||||
|
```
|
||||||
|
|
||||||
|
启动后会输出以下内容的日志。
|
||||||
|
|
||||||
|
```
|
||||||
|
2025-06-01 **** - 视觉分析接口是 http://192.168.4.7:8003/mcp/vision/explain
|
||||||
|
2025-06-01 **** - Websocket地址是 ws://192.168.4.7:8000/xiaozhi/v1/
|
||||||
|
2025-06-01 **** - =======上面的地址是websocket协议地址,请勿用浏览器访问=======
|
||||||
|
2025-06-01 **** - 如想测试websocket请用谷歌浏览器打开test目录下的test_page.html
|
||||||
|
2025-06-01 **** - =============================================================
|
||||||
|
```
|
||||||
|
|
||||||
|
启动后,使用使用浏览器打开日志里`视觉分析接口`连接。看看输出了什么?如果你是linux,没有浏览器,你可以执行这个命令:
|
||||||
|
```
|
||||||
|
curl -i 你的视觉分析接口
|
||||||
|
```
|
||||||
|
|
||||||
|
正常来说会这样显示
|
||||||
|
```
|
||||||
|
MCP Vision 接口运行正常,视觉解释接口地址是:http://xxxx:8003/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
请注意,如果你是公网部署,或者docker部署,一定要改一下你的`data/.config.yaml`里这个配置
|
||||||
|
```
|
||||||
|
server:
|
||||||
|
vision_explain: http://你的ip或者域名:端口号/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
为什么呢?因为视觉解释接口需要下发到设备,如果你的地址是局域网地址,或者是docker内部地址,设备是无法访问的。
|
||||||
|
|
||||||
|
假设你的公网地址是`111.111.111.111`,那么`vision_explain`应该这么配
|
||||||
|
|
||||||
|
```
|
||||||
|
server:
|
||||||
|
vision_explain: http://111.111.111.111:8003/mcp/vision/explain
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你的MCP Vision 接口运行正常,且你也试着用浏览器访问正常打开下发的`视觉解释接口地址`,请继续下一步
|
||||||
|
|
||||||
|
### 第四步 设备唤醒开启
|
||||||
|
|
||||||
|
对设备说“请打开摄像头,说你你看到了什么”
|
||||||
|
|
||||||
|
留意xiaozhi-server的日志输出,看看有没有报错。
|
||||||
@@ -28,6 +28,8 @@
|
|||||||
<captcha.version>1.6.2</captcha.version>
|
<captcha.version>1.6.2</captcha.version>
|
||||||
<guava.version>33.0.0-jre</guava.version>
|
<guava.version>33.0.0-jre</guava.version>
|
||||||
<liquibase-core.version>4.20.0</liquibase-core.version>
|
<liquibase-core.version>4.20.0</liquibase-core.version>
|
||||||
|
<aliyun-sms-version>4.1.0</aliyun-sms-version>
|
||||||
|
<okio-version>3.4.0</okio-version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -37,6 +39,7 @@
|
|||||||
<classifier>jakarta</classifier>
|
<classifier>jakarta</classifier>
|
||||||
<version>${shiro.version}</version>
|
<version>${shiro.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shiro</groupId>
|
<groupId>org.apache.shiro</groupId>
|
||||||
<artifactId>shiro-spring</artifactId>
|
<artifactId>shiro-spring</artifactId>
|
||||||
@@ -201,6 +204,18 @@
|
|||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 阿里云短信sdk -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>dysmsapi20170525</artifactId>
|
||||||
|
<version>${aliyun-sms-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 阿里云短信sdk使用的okio:1.15.0版本有安全漏洞:GHSA-w33c-445m-f8w7 现在升级成3.4.0安全版本-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okio</groupId>
|
||||||
|
<artifactId>okio</artifactId>
|
||||||
|
<version>${okio-version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- 阿里云maven仓库 -->
|
<!-- 阿里云maven仓库 -->
|
||||||
@@ -243,4 +258,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package xiaozhi.common.config;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAsync
|
||||||
|
@EnableAspectJAutoProxy(exposeProxy = true)
|
||||||
|
public class AsyncConfig {
|
||||||
|
|
||||||
|
@Bean(name = "taskExecutor")
|
||||||
|
public Executor taskExecutor() {
|
||||||
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
executor.setCorePoolSize(2);
|
||||||
|
executor.setMaxPoolSize(4);
|
||||||
|
executor.setQueueCapacity(1000);
|
||||||
|
executor.setThreadNamePrefix("AsyncThread-");
|
||||||
|
// 设置拒绝策略:由调用线程执行
|
||||||
|
executor.setRejectedExecutionHandler(new RejectedExecutionHandler() {
|
||||||
|
@Override
|
||||||
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||||
|
try {
|
||||||
|
// 如果线程池已满,则由调用线程执行
|
||||||
|
r.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("执行异步任务失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
executor.initialize();
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package xiaozhi.common.constant;
|
package xiaozhi.common.constant;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 常量
|
* 常量
|
||||||
* Copyright (c) 人人开源 All rights reserved.
|
* Copyright (c) 人人开源 All rights reserved.
|
||||||
@@ -109,31 +111,24 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String FILE_EXTENSION_SEG = ".";
|
String FILE_EXTENSION_SEG = ".";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无记忆
|
||||||
|
*/
|
||||||
|
String MEMORY_NO_MEM = "Memory_nomem";
|
||||||
|
|
||||||
enum SysBaseParam {
|
enum SysBaseParam {
|
||||||
/**
|
/**
|
||||||
* 系统全称
|
* ICP备案号
|
||||||
*/
|
*/
|
||||||
SYS_NAME("SYS_NAME"),
|
BEIAN_ICP_NUM("server.beian_icp_num"),
|
||||||
/**
|
/**
|
||||||
* 系统简称
|
* GA备案号
|
||||||
*/
|
*/
|
||||||
SYS_SHORT_NAME("SYS_SHORT_NAME"),
|
BEIAN_GA_NUM("server.beian_ga_num"),
|
||||||
/**
|
/**
|
||||||
* 系统描述
|
* 系统名称
|
||||||
*/
|
*/
|
||||||
SYS_DES("SYS_DES"),
|
SERVER_NAME("server.name");
|
||||||
/**
|
|
||||||
* 登录失败几次锁定
|
|
||||||
*/
|
|
||||||
LOGIN_LOCK_COUNT("LOGIN_LOCK_COUNT"),
|
|
||||||
/**
|
|
||||||
* 账号失败锁定分钟数
|
|
||||||
*/
|
|
||||||
LOGIN_LOCK_TIME("LOGIN_LOCK_TIME"),
|
|
||||||
/**
|
|
||||||
* TOKEN强验证
|
|
||||||
*/
|
|
||||||
SYS_TOKEN_SECURITY("SYS_TOKEN_SECURITY");
|
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
@@ -146,6 +141,46 @@ public interface Constant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统短信
|
||||||
|
*/
|
||||||
|
enum SysMSMParam {
|
||||||
|
/**
|
||||||
|
* 阿里云授权keyID
|
||||||
|
*/
|
||||||
|
ALIYUN_SMS_ACCESS_KEY_ID("aliyun.sms.access_key_id"),
|
||||||
|
/**
|
||||||
|
* 阿里云授权密钥
|
||||||
|
*/
|
||||||
|
ALIYUN_SMS_ACCESS_KEY_SECRET("aliyun.sms.access_key_secret"),
|
||||||
|
/**
|
||||||
|
* 阿里云短信签名
|
||||||
|
*/
|
||||||
|
ALIYUN_SMS_SIGN_NAME("aliyun.sms.sign_name"),
|
||||||
|
/**
|
||||||
|
* 阿里云短信模板
|
||||||
|
*/
|
||||||
|
ALIYUN_SMS_SMS_CODE_TEMPLATE_CODE("aliyun.sms.sms_code_template_code"),
|
||||||
|
/**
|
||||||
|
* 单号码最大短信发送条数
|
||||||
|
*/
|
||||||
|
SERVER_SMS_MAX_SEND_COUNT("server.sms_max_send_count"),
|
||||||
|
/**
|
||||||
|
* 是否开启手机注册
|
||||||
|
*/
|
||||||
|
SERVER_ENABLE_MOBILE_REGISTER("server.enable_mobile_register");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
SysMSMParam(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据状态
|
* 数据状态
|
||||||
*/
|
*/
|
||||||
@@ -174,8 +209,48 @@ public interface Constant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
enum ChatHistoryConfEnum {
|
||||||
|
IGNORE(0, "不记录"),
|
||||||
|
RECORD_TEXT(1, "记录文本"),
|
||||||
|
RECORD_TEXT_AUDIO(2, "文本音频都记录");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
ChatHistoryConfEnum(int code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本号
|
* 版本号
|
||||||
*/
|
*/
|
||||||
public static final String VERSION = "0.4.2";
|
public static final String VERSION = "0.5.4";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无效固件URL
|
||||||
|
*/
|
||||||
|
String INVALID_FIRMWARE_URL = "http://xiaozhi.server.com:8002/xiaozhi/otaMag/download/NOT_ACTIVATED_FIRMWARE_THIS_IS_A_INVALID_URL";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型
|
||||||
|
*/
|
||||||
|
enum DictType {
|
||||||
|
/**
|
||||||
|
* 手机区号
|
||||||
|
*/
|
||||||
|
MOBILE_AREA("MOBILE_AREA");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
DictType(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ public interface ErrorCode {
|
|||||||
int ACCOUNT_DISABLE = 10005;
|
int ACCOUNT_DISABLE = 10005;
|
||||||
int IDENTIFIER_NOT_NULL = 10006;
|
int IDENTIFIER_NOT_NULL = 10006;
|
||||||
int CAPTCHA_ERROR = 10007;
|
int CAPTCHA_ERROR = 10007;
|
||||||
int SUB_MENU_EXIST = 10008;
|
int PHONE_NOT_NULL = 10008;
|
||||||
int PASSWORD_ERROR = 10009;
|
int PASSWORD_ERROR = 10009;
|
||||||
|
|
||||||
int SUPERIOR_DEPT_ERROR = 10011;
|
int SUPERIOR_DEPT_ERROR = 10011;
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package xiaozhi.common.exception;
|
package xiaozhi.common.exception;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.shiro.authz.UnauthorizedException;
|
import org.apache.shiro.authz.UnauthorizedException;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.validation.ObjectError;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||||
@@ -60,4 +65,20 @@ public class RenExceptionHandler {
|
|||||||
return new Result<Void>().error(404, "资源不存在");
|
return new Result<Void>().error(404, "资源不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
public Result<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
|
||||||
|
List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
|
||||||
|
String errorMsg = allErrors.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(err -> {
|
||||||
|
String msg = err.getDefaultMessage();
|
||||||
|
return (msg != null && !msg.trim().isEmpty()) ? msg : null;
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("请求参数错误!");
|
||||||
|
|
||||||
|
return new Result<Void>().error(ErrorCode.PARAM_VALUE_NULL, errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -117,4 +117,26 @@ public class RedisKeys {
|
|||||||
public static String getAgentAudioIdKey(String uuid) {
|
public static String getAgentAudioIdKey(String uuid) {
|
||||||
return "agent:audio:id:" + uuid;
|
return "agent:audio:id:" + uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取短信验证码的缓存key
|
||||||
|
*/
|
||||||
|
public static String getSMSValidateCodeKey(String phone) {
|
||||||
|
return "sms:Validate:Code:" + phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取短信验证码最后发送时间的缓存key
|
||||||
|
*/
|
||||||
|
public static String getSMSLastSendTimeKey(String phone) {
|
||||||
|
return "sms:Validate:Code:" + phone + ":last_send_time";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取短信验证码今日发送次数的缓存key
|
||||||
|
*/
|
||||||
|
public static String getSMSTodayCountKey(String phone) {
|
||||||
|
return "sms:Validate:Code:" + phone + ":today_count";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.HashOperations;
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import xiaozhi.common.utils.ResourcesUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis工具类
|
* Redis工具类
|
||||||
@@ -23,6 +25,9 @@ public class RedisUtils {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ResourcesUtils resourceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认过期时长为24小时,单位:秒
|
* 默认过期时长为24小时,单位:秒
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +45,24 @@ public class RedisUtils {
|
|||||||
*/
|
*/
|
||||||
public final static long NOT_EXPIRE = -1L;
|
public final static long NOT_EXPIRE = -1L;
|
||||||
|
|
||||||
|
public Long increment(String key, long expire) {
|
||||||
|
Long increment = redisTemplate.opsForValue().increment(key, 1L);
|
||||||
|
if (expire != NOT_EXPIRE) {
|
||||||
|
expire(key, expire);
|
||||||
|
}
|
||||||
|
return increment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long increment(String key) {
|
||||||
|
return redisTemplate.opsForValue().increment(key, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long decrement(String key) {
|
||||||
|
return redisTemplate.opsForValue().decrement(key, 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void set(String key, Object value, long expire) {
|
public void set(String key, Object value, long expire) {
|
||||||
redisTemplate.opsForValue().set(key, value);
|
redisTemplate.opsForValue().set(key, value);
|
||||||
if (expire != NOT_EXPIRE) {
|
if (expire != NOT_EXPIRE) {
|
||||||
@@ -134,7 +157,7 @@ public class RedisUtils {
|
|||||||
*/
|
*/
|
||||||
public void emptyAll() {
|
public void emptyAll() {
|
||||||
// Lua 脚本 FLUSHALL是redis清空所有库的命令
|
// Lua 脚本 FLUSHALL是redis清空所有库的命令
|
||||||
String luaScript ="redis.call('FLUSHALL')";
|
String luaScript =resourceUtils.loadString("lua/emptyAll.lua");
|
||||||
|
|
||||||
// 创建 DefaultRedisScript 对象
|
// 创建 DefaultRedisScript 对象
|
||||||
DefaultRedisScript<Void> redisScript = new DefaultRedisScript<>();
|
DefaultRedisScript<Void> redisScript = new DefaultRedisScript<>();
|
||||||
@@ -147,4 +170,26 @@ public class RedisUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取在redis指定key的值,如果值为空,着设置key的默认值
|
||||||
|
* @param key redis的key
|
||||||
|
* @param defaultValue 默认值
|
||||||
|
* @param expiresInSecond 过期时间
|
||||||
|
* @return 返回key的值
|
||||||
|
*/
|
||||||
|
public String getKeyOrCreate(String key, String defaultValue,Long expiresInSecond) {
|
||||||
|
// Lua 脚本
|
||||||
|
String luaScript = resourceUtils.loadString("lua/getKeyOrCreate.lua");
|
||||||
|
|
||||||
|
DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
|
||||||
|
redisScript.setScriptText(luaScript);
|
||||||
|
redisScript.setResultType(String.class);
|
||||||
|
|
||||||
|
// 执行 Lua 脚本
|
||||||
|
List<String> keys = Collections.singletonList(key);
|
||||||
|
return redisTemplate.execute(redisScript, keys, defaultValue,expiresInSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.common.service.impl;
|
package xiaozhi.common.service.impl;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -18,6 +19,7 @@ import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
@@ -45,6 +47,12 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
|
|||||||
* @param params 分页查询参数
|
* @param params 分页查询参数
|
||||||
* @param defaultOrderField 默认排序字段
|
* @param defaultOrderField 默认排序字段
|
||||||
* @param isAsc 排序方式
|
* @param isAsc 排序方式
|
||||||
|
* @see xiaozhi.common.constant.Constant
|
||||||
|
* params.put(Constant.PAGE, "1");
|
||||||
|
* params.put(Constant.LIMIT, "10");
|
||||||
|
* params.put(Constant.ORDER_FIELD, "field"); // 单个字段
|
||||||
|
* params.put(Constant.ORDER_FIELD, List.of("field1", "field2")); // 多个字段
|
||||||
|
* params.put(Constant.ORDER, "asc");
|
||||||
*/
|
*/
|
||||||
protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) {
|
protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) {
|
||||||
// 分页参数
|
// 分页参数
|
||||||
@@ -65,28 +73,34 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
|
|||||||
params.put(Constant.PAGE, page);
|
params.put(Constant.PAGE, page);
|
||||||
|
|
||||||
// 排序字段
|
// 排序字段
|
||||||
String orderField = (String) params.get(Constant.ORDER_FIELD);
|
Object orderField = params.get(Constant.ORDER_FIELD);
|
||||||
String order = (String) params.get(Constant.ORDER);
|
String order = (String) params.get(Constant.ORDER);
|
||||||
|
|
||||||
// 前端字段排序
|
List<String> orderFields = new ArrayList<>();
|
||||||
if (StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)) {
|
|
||||||
if (Constant.ASC.equalsIgnoreCase(order)) {
|
// 处理排序字段
|
||||||
return page.addOrder(OrderItem.asc(orderField));
|
if (orderField instanceof String) {
|
||||||
|
orderFields.add((String) orderField);
|
||||||
|
} else if (orderField instanceof List) {
|
||||||
|
orderFields.addAll((List<String>) orderField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 有排序字段则排序
|
||||||
|
if (CollectionUtils.isNotEmpty(orderFields)) {
|
||||||
|
if (StringUtils.isNotBlank(order) && Constant.ASC.equalsIgnoreCase(order)) {
|
||||||
|
return page.addOrder(OrderItem.ascs(orderFields.toArray(new String[0])));
|
||||||
} else {
|
} else {
|
||||||
return page.addOrder(OrderItem.desc(orderField));
|
return page.addOrder(OrderItem.descs(orderFields.toArray(new String[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 没有排序字段,则不排序
|
// 没有排序字段,使用默认排序
|
||||||
if (StringUtils.isBlank(defaultOrderField)) {
|
if (StringUtils.isNotBlank(defaultOrderField)) {
|
||||||
return page;
|
if (isAsc) {
|
||||||
}
|
page.addOrder(OrderItem.asc(defaultOrderField));
|
||||||
|
} else {
|
||||||
// 默认排序
|
page.addOrder(OrderItem.desc(defaultOrderField));
|
||||||
if (isAsc) {
|
}
|
||||||
page.addOrder(OrderItem.asc(defaultOrderField));
|
|
||||||
} else {
|
|
||||||
page.addOrder(OrderItem.desc(defaultOrderField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class DateUtils {
|
|||||||
* 时间格式(yyyy-MM-dd HH:mm:ss)
|
* 时间格式(yyyy-MM-dd HH:mm:ss)
|
||||||
*/
|
*/
|
||||||
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
public final static String DATE_TIME_MILLIS_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日期格式化 日期格式为:yyyy-MM-dd
|
* 日期格式化 日期格式为:yyyy-MM-dd
|
||||||
@@ -63,6 +65,19 @@ public class DateUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getDateTimeNow() {
|
||||||
|
return getDateTimeNow(DATE_TIME_PATTERN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDateTimeNow(String pattern) {
|
||||||
|
return format(new Date(), pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String millsToSecond(long mills) {
|
||||||
|
return String.format("%.3f", mills / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取简短的时间字符串:10秒前返回刚刚,多少秒前,几小时前,超过一周返回年月日时分秒
|
* 获取简短的时间字符串:10秒前返回刚刚,多少秒前,几小时前,超过一周返回年月日时分秒
|
||||||
* @param date
|
* @param date
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package xiaozhi.common.utils;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源处理工具
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class ResourcesUtils {
|
||||||
|
private ResourceLoader resourceLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取资源,返回字符串
|
||||||
|
* @param fileName 资源路径:resources下开始
|
||||||
|
* @return 字符串
|
||||||
|
*/
|
||||||
|
public String loadString(String fileName) {
|
||||||
|
Resource resource = resourceLoader.getResource("classpath:" + fileName);
|
||||||
|
StringBuilder luaScriptBuilder = new StringBuilder();
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(resource.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
luaScriptBuilder.append(line).append("\n");
|
||||||
|
}
|
||||||
|
} catch (IOException e){
|
||||||
|
log.error("方法:loadString()读取资源失败--{}",e.getMessage());
|
||||||
|
throw new RenException("读取资源失败");
|
||||||
|
}
|
||||||
|
return luaScriptBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package xiaozhi.common.validator;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
@@ -45,4 +46,32 @@ public class ValidatorUtils {
|
|||||||
throw new RenException(constraint.getMessage());
|
throw new RenException(constraint.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国际手机号正则表达式
|
||||||
|
* 要求必须带国际区号,格式:+[国家代码][手机号]
|
||||||
|
* 例如:
|
||||||
|
* - +8613800138000
|
||||||
|
* - +12345678900
|
||||||
|
* - +447123456789
|
||||||
|
*/
|
||||||
|
private static final String INTERNATIONAL_PHONE_REGEX = "^\\+[1-9]\\d{0,3}[1-9]\\d{4,14}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验手机号是否有效
|
||||||
|
* 要求必须带国际区号,格式:+[国家代码][手机号]
|
||||||
|
* 例如:+8613800138000
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean isValidPhone(String phone) {
|
||||||
|
if (phone == null || phone.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证必须带国际区号的手机号格式
|
||||||
|
Pattern pattern = Pattern.compile(INTERNATIONAL_PHONE_REGEX);
|
||||||
|
return pattern.matcher(phone).matches();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ import xiaozhi.modules.agent.dto.AgentChatHistoryDTO;
|
|||||||
import xiaozhi.modules.agent.dto.AgentChatSessionDTO;
|
import xiaozhi.modules.agent.dto.AgentChatSessionDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentCreateDTO;
|
import xiaozhi.modules.agent.dto.AgentCreateDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentDTO;
|
import xiaozhi.modules.agent.dto.AgentDTO;
|
||||||
|
import xiaozhi.modules.agent.dto.AgentMemoryDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
|
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
|
||||||
import xiaozhi.modules.agent.entity.AgentEntity;
|
import xiaozhi.modules.agent.entity.AgentEntity;
|
||||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||||
@@ -46,6 +47,7 @@ import xiaozhi.modules.agent.service.AgentChatAudioService;
|
|||||||
import xiaozhi.modules.agent.service.AgentChatHistoryService;
|
import xiaozhi.modules.agent.service.AgentChatHistoryService;
|
||||||
import xiaozhi.modules.agent.service.AgentService;
|
import xiaozhi.modules.agent.service.AgentService;
|
||||||
import xiaozhi.modules.agent.service.AgentTemplateService;
|
import xiaozhi.modules.agent.service.AgentTemplateService;
|
||||||
|
import xiaozhi.modules.device.entity.DeviceEntity;
|
||||||
import xiaozhi.modules.device.service.DeviceService;
|
import xiaozhi.modules.device.service.DeviceService;
|
||||||
import xiaozhi.modules.security.user.SecurityUser;
|
import xiaozhi.modules.security.user.SecurityUser;
|
||||||
|
|
||||||
@@ -109,6 +111,8 @@ public class AgentController {
|
|||||||
entity.setMemModelId(template.getMemModelId());
|
entity.setMemModelId(template.getMemModelId());
|
||||||
entity.setIntentModelId(template.getIntentModelId());
|
entity.setIntentModelId(template.getIntentModelId());
|
||||||
entity.setSystemPrompt(template.getSystemPrompt());
|
entity.setSystemPrompt(template.getSystemPrompt());
|
||||||
|
entity.setSummaryMemory(template.getSummaryMemory());
|
||||||
|
entity.setChatHistoryConf(template.getChatHistoryConf());
|
||||||
entity.setLangCode(template.getLangCode());
|
entity.setLangCode(template.getLangCode());
|
||||||
entity.setLanguage(template.getLanguage());
|
entity.setLanguage(template.getLanguage());
|
||||||
}
|
}
|
||||||
@@ -125,10 +129,26 @@ public class AgentController {
|
|||||||
return new Result<String>().ok(entity.getId());
|
return new Result<String>().ok(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/saveMemory/{macAddress}")
|
||||||
|
@Operation(summary = "根据设备id更新智能体")
|
||||||
|
public Result<Void> updateByDeviceId(@PathVariable String macAddress, @RequestBody @Valid AgentMemoryDTO dto) {
|
||||||
|
DeviceEntity device = deviceService.getDeviceByMacAddress(macAddress);
|
||||||
|
if (device == null) {
|
||||||
|
return new Result<>();
|
||||||
|
}
|
||||||
|
AgentUpdateDTO agentUpdateDTO = new AgentUpdateDTO();
|
||||||
|
agentUpdateDTO.setSummaryMemory(dto.getSummaryMemory());
|
||||||
|
return updateAgentById(device.getAgentId(), agentUpdateDTO);
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@Operation(summary = "更新智能体")
|
@Operation(summary = "更新智能体")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:normal")
|
||||||
public Result<Void> update(@PathVariable String id, @RequestBody @Valid AgentUpdateDTO dto) {
|
public Result<Void> update(@PathVariable String id, @RequestBody @Valid AgentUpdateDTO dto) {
|
||||||
|
return updateAgentById(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result<Void> updateAgentById(String id, AgentUpdateDTO dto) {
|
||||||
// 先查询现有实体
|
// 先查询现有实体
|
||||||
AgentEntity existingEntity = agentService.getAgentById(id);
|
AgentEntity existingEntity = agentService.getAgentById(id);
|
||||||
if (existingEntity == null) {
|
if (existingEntity == null) {
|
||||||
@@ -151,6 +171,9 @@ public class AgentController {
|
|||||||
if (dto.getLlmModelId() != null) {
|
if (dto.getLlmModelId() != null) {
|
||||||
existingEntity.setLlmModelId(dto.getLlmModelId());
|
existingEntity.setLlmModelId(dto.getLlmModelId());
|
||||||
}
|
}
|
||||||
|
if (dto.getVllmModelId() != null) {
|
||||||
|
existingEntity.setVllmModelId(dto.getVllmModelId());
|
||||||
|
}
|
||||||
if (dto.getTtsModelId() != null) {
|
if (dto.getTtsModelId() != null) {
|
||||||
existingEntity.setTtsModelId(dto.getTtsModelId());
|
existingEntity.setTtsModelId(dto.getTtsModelId());
|
||||||
}
|
}
|
||||||
@@ -166,6 +189,12 @@ public class AgentController {
|
|||||||
if (dto.getSystemPrompt() != null) {
|
if (dto.getSystemPrompt() != null) {
|
||||||
existingEntity.setSystemPrompt(dto.getSystemPrompt());
|
existingEntity.setSystemPrompt(dto.getSystemPrompt());
|
||||||
}
|
}
|
||||||
|
if (dto.getSummaryMemory() != null) {
|
||||||
|
existingEntity.setSummaryMemory(dto.getSummaryMemory());
|
||||||
|
}
|
||||||
|
if (dto.getChatHistoryConf() != null) {
|
||||||
|
existingEntity.setChatHistoryConf(dto.getChatHistoryConf());
|
||||||
|
}
|
||||||
if (dto.getLangCode() != null) {
|
if (dto.getLangCode() != null) {
|
||||||
existingEntity.setLangCode(dto.getLangCode());
|
existingEntity.setLangCode(dto.getLangCode());
|
||||||
}
|
}
|
||||||
@@ -181,8 +210,16 @@ public class AgentController {
|
|||||||
existingEntity.setUpdater(user.getId());
|
existingEntity.setUpdater(user.getId());
|
||||||
existingEntity.setUpdatedAt(new Date());
|
existingEntity.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
// 更新记忆策略
|
||||||
|
if (existingEntity.getMemModelId() == null || existingEntity.getMemModelId().equals(Constant.MEMORY_NO_MEM)) {
|
||||||
|
// 删除所有记录
|
||||||
|
agentChatHistoryService.deleteByAgentId(existingEntity.getId(), true, true);
|
||||||
|
existingEntity.setSummaryMemory("");
|
||||||
|
} else if (existingEntity.getChatHistoryConf() != null && existingEntity.getChatHistoryConf() == 1) {
|
||||||
|
// 删除音频数据
|
||||||
|
agentChatHistoryService.deleteByAgentId(existingEntity.getId(), true, false);
|
||||||
|
}
|
||||||
agentService.updateById(existingEntity);
|
agentService.updateById(existingEntity);
|
||||||
|
|
||||||
return new Result<>();
|
return new Result<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +230,7 @@ public class AgentController {
|
|||||||
// 先删除关联的设备
|
// 先删除关联的设备
|
||||||
deviceService.deleteByAgentId(id);
|
deviceService.deleteByAgentId(id);
|
||||||
// 删除关联的聊天记录
|
// 删除关联的聊天记录
|
||||||
agentChatHistoryService.deleteByAgentId(id);
|
agentChatHistoryService.deleteByAgentId(id, true, true);
|
||||||
// 再删除智能体
|
// 再删除智能体
|
||||||
agentService.deleteById(id);
|
agentService.deleteById(id);
|
||||||
return new Result<>();
|
return new Result<>();
|
||||||
|
|||||||
@@ -28,4 +28,11 @@ public interface AiAgentChatHistoryDao extends BaseMapper<AgentChatHistoryEntity
|
|||||||
* @param agentId 智能体ID
|
* @param agentId 智能体ID
|
||||||
*/
|
*/
|
||||||
void deleteHistoryByAgentId(String agentId);
|
void deleteHistoryByAgentId(String agentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据智能体ID删除音频ID
|
||||||
|
*
|
||||||
|
* @param agentId 智能体ID
|
||||||
|
*/
|
||||||
|
void deleteAudioIdByAgentId(String agentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ public class AgentChatHistoryReportDTO {
|
|||||||
private String content;
|
private String content;
|
||||||
@Schema(description = "base64编码的opus音频数据", example = "")
|
@Schema(description = "base64编码的opus音频数据", example = "")
|
||||||
private String audioBase64;
|
private String audioBase64;
|
||||||
|
@Schema(description = "上报时间,十位时间戳,空时默认使用当前时间", example = "1745657732")
|
||||||
|
private Long reportTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,19 @@ public class AgentDTO {
|
|||||||
@Schema(description = "大语言模型名称", example = "llm_model_01")
|
@Schema(description = "大语言模型名称", example = "llm_model_01")
|
||||||
private String llmModelName;
|
private String llmModelName;
|
||||||
|
|
||||||
|
@Schema(description = "视觉模型名称", example = "vllm_model_01")
|
||||||
|
private String vllmModelName;
|
||||||
|
|
||||||
|
@Schema(description = "记忆模型ID", example = "mem_model_01")
|
||||||
|
private String memModelId;
|
||||||
|
|
||||||
@Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题并提供帮助")
|
@Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题并提供帮助")
|
||||||
private String systemPrompt;
|
private String systemPrompt;
|
||||||
|
|
||||||
|
@Schema(description = "总结记忆", example = "构建可生长的动态记忆网络,在有限空间内保留关键信息的同时,智能维护信息演变轨迹\n" +
|
||||||
|
"根据对话记录,总结user的重要信息,以便在未来的对话中提供更个性化的服务", required = false)
|
||||||
|
private String summaryMemory;
|
||||||
|
|
||||||
@Schema(description = "最后连接时间", example = "2024-03-20 10:00:00")
|
@Schema(description = "最后连接时间", example = "2024-03-20 10:00:00")
|
||||||
private Date lastConnectedAt;
|
private Date lastConnectedAt;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package xiaozhi.modules.agent.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 智能体记忆更新DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "智能体记忆更新对象")
|
||||||
|
public class AgentMemoryDTO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "总结记忆", example = "构建可生长的动态记忆网络,在有限空间内保留关键信息的同时,智能维护信息演变轨迹\n" +
|
||||||
|
"根据对话记录,总结user的重要信息,以便在未来的对话中提供更个性化的服务", required = false)
|
||||||
|
private String summaryMemory;
|
||||||
|
}
|
||||||
@@ -30,6 +30,9 @@ public class AgentUpdateDTO implements Serializable {
|
|||||||
@Schema(description = "大语言模型标识", example = "llm_model_02", required = false)
|
@Schema(description = "大语言模型标识", example = "llm_model_02", required = false)
|
||||||
private String llmModelId;
|
private String llmModelId;
|
||||||
|
|
||||||
|
@Schema(description = "VLLM模型标识", example = "vllm_model_02", required = false)
|
||||||
|
private String vllmModelId;
|
||||||
|
|
||||||
@Schema(description = "语音合成模型标识", example = "tts_model_02", required = false)
|
@Schema(description = "语音合成模型标识", example = "tts_model_02", required = false)
|
||||||
private String ttsModelId;
|
private String ttsModelId;
|
||||||
|
|
||||||
@@ -45,6 +48,13 @@ public class AgentUpdateDTO implements Serializable {
|
|||||||
@Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题并提供帮助", required = false)
|
@Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题并提供帮助", required = false)
|
||||||
private String systemPrompt;
|
private String systemPrompt;
|
||||||
|
|
||||||
|
@Schema(description = "总结记忆", example = "构建可生长的动态记忆网络,在有限空间内保留关键信息的同时,智能维护信息演变轨迹\n" +
|
||||||
|
"根据对话记录,总结user的重要信息,以便在未来的对话中提供更个性化的服务", required = false)
|
||||||
|
private String summaryMemory;
|
||||||
|
|
||||||
|
@Schema(description = "聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)", example = "3", required = false)
|
||||||
|
private Integer chatHistoryConf;
|
||||||
|
|
||||||
@Schema(description = "语言编码", example = "zh_CN", required = false)
|
@Schema(description = "语言编码", example = "zh_CN", required = false)
|
||||||
private String langCode;
|
private String langCode;
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public class AgentEntity {
|
|||||||
@Schema(description = "大语言模型标识")
|
@Schema(description = "大语言模型标识")
|
||||||
private String llmModelId;
|
private String llmModelId;
|
||||||
|
|
||||||
|
@Schema(description = "VLLM模型标识")
|
||||||
|
private String vllmModelId;
|
||||||
|
|
||||||
@Schema(description = "语音合成模型标识")
|
@Schema(description = "语音合成模型标识")
|
||||||
private String ttsModelId;
|
private String ttsModelId;
|
||||||
|
|
||||||
@@ -48,9 +51,16 @@ public class AgentEntity {
|
|||||||
@Schema(description = "意图模型标识")
|
@Schema(description = "意图模型标识")
|
||||||
private String intentModelId;
|
private String intentModelId;
|
||||||
|
|
||||||
|
@Schema(description = "聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)")
|
||||||
|
private Integer chatHistoryConf;
|
||||||
|
|
||||||
@Schema(description = "角色设定参数")
|
@Schema(description = "角色设定参数")
|
||||||
private String systemPrompt;
|
private String systemPrompt;
|
||||||
|
|
||||||
|
@Schema(description = "总结记忆", example = "构建可生长的动态记忆网络,在有限空间内保留关键信息的同时,智能维护信息演变轨迹\n" +
|
||||||
|
"根据对话记录,总结user的重要信息,以便在未来的对话中提供更个性化的服务", required = false)
|
||||||
|
private String summaryMemory;
|
||||||
|
|
||||||
@Schema(description = "语言编码")
|
@Schema(description = "语言编码")
|
||||||
private String langCode;
|
private String langCode;
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ public class AgentTemplateEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String llmModelId;
|
private String llmModelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VLLM模型标识
|
||||||
|
*/
|
||||||
|
private String vllmModelId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音合成模型标识
|
* 语音合成模型标识
|
||||||
*/
|
*/
|
||||||
@@ -69,11 +74,20 @@ public class AgentTemplateEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String intentModelId;
|
private String intentModelId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)
|
||||||
|
*/
|
||||||
|
private Integer chatHistoryConf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色设定参数
|
* 角色设定参数
|
||||||
*/
|
*/
|
||||||
private String systemPrompt;
|
private String systemPrompt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总结记忆
|
||||||
|
*/
|
||||||
|
private String summaryMemory;
|
||||||
/**
|
/**
|
||||||
* 语言编码
|
* 语言编码
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ public interface AgentChatAudioService extends IService<AgentChatAudioEntity> {
|
|||||||
* @return 音频数据
|
* @return 音频数据
|
||||||
*/
|
*/
|
||||||
byte[] getAudio(String audioId);
|
byte[] getAudio(String audioId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ public interface AgentChatHistoryService extends IService<AgentChatHistoryEntity
|
|||||||
/**
|
/**
|
||||||
* 根据智能体ID删除聊天记录
|
* 根据智能体ID删除聊天记录
|
||||||
*
|
*
|
||||||
* @param agentId 智能体ID
|
* @param agentId 智能体ID
|
||||||
|
* @param deleteAudio 是否删除音频
|
||||||
|
* @param deleteText 是否删除文本
|
||||||
*/
|
*/
|
||||||
void deleteByAgentId(String agentId);
|
void deleteByAgentId(String agentId, Boolean deleteAudio, Boolean deleteText);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package xiaozhi.modules.agent.service.biz.impl;
|
|||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.redis.RedisKeys;
|
import xiaozhi.common.redis.RedisKeys;
|
||||||
import xiaozhi.common.redis.RedisUtils;
|
import xiaozhi.common.redis.RedisUtils;
|
||||||
import xiaozhi.modules.agent.dto.AgentChatHistoryReportDTO;
|
import xiaozhi.modules.agent.dto.AgentChatHistoryReportDTO;
|
||||||
@@ -45,10 +47,36 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic
|
|||||||
public Boolean report(AgentChatHistoryReportDTO report) {
|
public Boolean report(AgentChatHistoryReportDTO report) {
|
||||||
String macAddress = report.getMacAddress();
|
String macAddress = report.getMacAddress();
|
||||||
Byte chatType = report.getChatType();
|
Byte chatType = report.getChatType();
|
||||||
log.info("小智设备聊天上报请求: macAddress={}, type={}", macAddress, chatType);
|
Long reportTimeMillis = null != report.getReportTime() ? report.getReportTime() * 1000 : System.currentTimeMillis();
|
||||||
|
log.info("小智设备聊天上报请求: macAddress={}, type={} reportTime={}", macAddress, chatType, reportTimeMillis);
|
||||||
|
|
||||||
// 1. base64解码report.getOpusDataBase64(),存入ai_agent_chat_audio表
|
// 根据设备MAC地址查询对应的默认智能体,判断是否需要上报
|
||||||
|
AgentEntity agentEntity = agentService.getDefaultAgentByMacAddress(macAddress);
|
||||||
|
if (agentEntity == null) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer chatHistoryConf = agentEntity.getChatHistoryConf();
|
||||||
|
String agentId = agentEntity.getId();
|
||||||
|
|
||||||
|
if (Objects.equals(chatHistoryConf, Constant.ChatHistoryConfEnum.RECORD_TEXT.getCode())) {
|
||||||
|
saveChatText(report, agentId, macAddress, null, reportTimeMillis);
|
||||||
|
} else if (Objects.equals(chatHistoryConf, Constant.ChatHistoryConfEnum.RECORD_TEXT_AUDIO.getCode())) {
|
||||||
|
String audioId = saveChatAudio(report);
|
||||||
|
saveChatText(report, agentId, macAddress, audioId, reportTimeMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新设备最后对话时间
|
||||||
|
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date());
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* base64解码report.getOpusDataBase64(),存入ai_agent_chat_audio表
|
||||||
|
*/
|
||||||
|
private String saveChatAudio(AgentChatHistoryReportDTO report) {
|
||||||
String audioId = null;
|
String audioId = null;
|
||||||
|
|
||||||
if (report.getAudioBase64() != null && !report.getAudioBase64().isEmpty()) {
|
if (report.getAudioBase64() != null && !report.getAudioBase64().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
byte[] audioData = Base64.getDecoder().decode(report.getAudioBase64());
|
byte[] audioData = Base64.getDecoder().decode(report.getAudioBase64());
|
||||||
@@ -56,20 +84,17 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic
|
|||||||
log.info("音频数据保存成功,audioId={}", audioId);
|
log.info("音频数据保存成功,audioId={}", audioId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("音频数据保存失败", e);
|
log.error("音频数据保存失败", e);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return audioId;
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 组装上报数据
|
/**
|
||||||
// 2.1 根据设备MAC地址查询对应的默认智能体,判断是否需要上报
|
* 组装上报数据
|
||||||
AgentEntity agentEntity = agentService.getDefaultAgentByMacAddress(macAddress);
|
*/
|
||||||
if (agentEntity == null) {
|
private void saveChatText(AgentChatHistoryReportDTO report, String agentId, String macAddress, String audioId, Long reportTime) {
|
||||||
return false;
|
// 构建聊天记录实体
|
||||||
}
|
|
||||||
String agentId = agentEntity.getId();
|
|
||||||
log.info("设备 {} 对应智能体 {} 上报", macAddress, agentEntity.getId());
|
|
||||||
|
|
||||||
// 2.2 构建聊天记录实体
|
|
||||||
AgentChatHistoryEntity entity = AgentChatHistoryEntity.builder()
|
AgentChatHistoryEntity entity = AgentChatHistoryEntity.builder()
|
||||||
.macAddress(macAddress)
|
.macAddress(macAddress)
|
||||||
.agentId(agentId)
|
.agentId(agentId)
|
||||||
@@ -77,12 +102,13 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic
|
|||||||
.chatType(report.getChatType())
|
.chatType(report.getChatType())
|
||||||
.content(report.getContent())
|
.content(report.getContent())
|
||||||
.audioId(audioId)
|
.audioId(audioId)
|
||||||
|
.createdAt(new Date(reportTime))
|
||||||
|
// NOTE(haotian): 2025/5/26 updateAt可以不设置,重点是createAt,而且这样可以看到上报延迟
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 3. 保存数据
|
// 保存数据
|
||||||
agentChatHistoryService.save(entity);
|
agentChatHistoryService.save(entity);
|
||||||
// 4. 更新设备最后对话时间
|
|
||||||
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date());
|
log.info("设备 {} 对应智能体 {} 上报成功", macAddress, agentId);
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,4 @@ public class AgentChatAudioServiceImpl extends ServiceImpl<AiAgentChatAudioDao,
|
|||||||
AgentChatAudioEntity entity = getById(audioId);
|
AgentChatAudioEntity entity = getById(audioId);
|
||||||
return entity != null ? entity.getAudio() : null;
|
return entity != null ? entity.getAudio() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,16 @@ public class AgentChatHistoryServiceImpl extends ServiceImpl<AiAgentChatHistoryD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteByAgentId(String agentId) {
|
public void deleteByAgentId(String agentId, Boolean deleteAudio, Boolean deleteText) {
|
||||||
baseMapper.deleteAudioByAgentId(agentId);
|
if (deleteAudio) {
|
||||||
baseMapper.deleteHistoryByAgentId(agentId);
|
baseMapper.deleteAudioByAgentId(agentId);
|
||||||
|
}
|
||||||
|
if (deleteAudio && !deleteText) {
|
||||||
|
baseMapper.deleteAudioIdByAgentId(agentId);
|
||||||
|
}
|
||||||
|
if (deleteText) {
|
||||||
|
baseMapper.deleteHistoryByAgentId(agentId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.page.PageData;
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.common.redis.RedisKeys;
|
import xiaozhi.common.redis.RedisKeys;
|
||||||
import xiaozhi.common.redis.RedisUtils;
|
import xiaozhi.common.redis.RedisUtils;
|
||||||
@@ -46,7 +47,15 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AgentEntity getAgentById(String id) {
|
public AgentEntity getAgentById(String id) {
|
||||||
return agentDao.selectById(id);
|
AgentEntity agent = agentDao.selectById(id);
|
||||||
|
if (agent != null && agent.getMemModelId() != null && agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)) {
|
||||||
|
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.IGNORE.getCode());
|
||||||
|
} else if (agent != null && agent.getMemModelId() != null
|
||||||
|
&& !agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)
|
||||||
|
&& agent.getChatHistoryConf() == null) {
|
||||||
|
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.RECORD_TEXT_AUDIO.getCode());
|
||||||
|
}
|
||||||
|
return agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,6 +102,12 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
// 获取 LLM 模型名称
|
// 获取 LLM 模型名称
|
||||||
dto.setLlmModelName(modelConfigService.getModelNameById(agent.getLlmModelId()));
|
dto.setLlmModelName(modelConfigService.getModelNameById(agent.getLlmModelId()));
|
||||||
|
|
||||||
|
// 获取 VLLM 模型名称
|
||||||
|
dto.setVllmModelName(modelConfigService.getModelNameById(agent.getVllmModelId()));
|
||||||
|
|
||||||
|
// 获取记忆模型名称
|
||||||
|
dto.setMemModelId(agent.getMemModelId());
|
||||||
|
|
||||||
// 获取 TTS 音色名称
|
// 获取 TTS 音色名称
|
||||||
dto.setTtsVoiceName(timbreModelService.getTimbreNameById(agent.getTtsVoiceId()));
|
dto.setTtsVoiceName(timbreModelService.getTimbreNameById(agent.getTtsVoiceId()));
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
import xiaozhi.common.exception.RenException;
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.redis.RedisKeys;
|
import xiaozhi.common.redis.RedisKeys;
|
||||||
@@ -64,12 +65,14 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
agent.getVadModelId(),
|
agent.getVadModelId(),
|
||||||
agent.getAsrModelId(),
|
agent.getAsrModelId(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
result,
|
result,
|
||||||
isCache);
|
isCache);
|
||||||
|
|
||||||
@@ -108,6 +111,17 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
// 获取单台设备每天最多输出字数
|
// 获取单台设备每天最多输出字数
|
||||||
String deviceMaxOutputSize = sysParamsService.getValue("device_max_output_size", true);
|
String deviceMaxOutputSize = sysParamsService.getValue("device_max_output_size", true);
|
||||||
result.put("device_max_output_size", deviceMaxOutputSize);
|
result.put("device_max_output_size", deviceMaxOutputSize);
|
||||||
|
|
||||||
|
// 获取聊天记录配置
|
||||||
|
Integer chatHistoryConf = agent.getChatHistoryConf();
|
||||||
|
if (agent.getMemModelId() != null && agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)) {
|
||||||
|
chatHistoryConf = Constant.ChatHistoryConfEnum.IGNORE.getCode();
|
||||||
|
} else if (agent.getMemModelId() != null
|
||||||
|
&& !agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)
|
||||||
|
&& agent.getChatHistoryConf() == null) {
|
||||||
|
chatHistoryConf = Constant.ChatHistoryConfEnum.RECORD_TEXT_AUDIO.getCode();
|
||||||
|
}
|
||||||
|
result.put("chat_history_conf", chatHistoryConf);
|
||||||
// 如果客户端已实例化模型,则不返回
|
// 如果客户端已实例化模型,则不返回
|
||||||
String alreadySelectedVadModelId = (String) selectedModule.get("VAD");
|
String alreadySelectedVadModelId = (String) selectedModule.get("VAD");
|
||||||
if (alreadySelectedVadModelId != null && alreadySelectedVadModelId.equals(agent.getVadModelId())) {
|
if (alreadySelectedVadModelId != null && alreadySelectedVadModelId.equals(agent.getVadModelId())) {
|
||||||
@@ -122,10 +136,12 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
buildModuleConfig(
|
buildModuleConfig(
|
||||||
agent.getAgentName(),
|
agent.getAgentName(),
|
||||||
agent.getSystemPrompt(),
|
agent.getSystemPrompt(),
|
||||||
|
agent.getSummaryMemory(),
|
||||||
voice,
|
voice,
|
||||||
agent.getVadModelId(),
|
agent.getVadModelId(),
|
||||||
agent.getAsrModelId(),
|
agent.getAsrModelId(),
|
||||||
agent.getLlmModelId(),
|
agent.getLlmModelId(),
|
||||||
|
agent.getVllmModelId(),
|
||||||
agent.getTtsModelId(),
|
agent.getTtsModelId(),
|
||||||
agent.getMemModelId(),
|
agent.getMemModelId(),
|
||||||
agent.getIntentModelId(),
|
agent.getIntentModelId(),
|
||||||
@@ -222,10 +238,12 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
private void buildModuleConfig(
|
private void buildModuleConfig(
|
||||||
String assistantName,
|
String assistantName,
|
||||||
String prompt,
|
String prompt,
|
||||||
|
String summaryMemory,
|
||||||
String voice,
|
String voice,
|
||||||
String vadModelId,
|
String vadModelId,
|
||||||
String asrModelId,
|
String asrModelId,
|
||||||
String llmModelId,
|
String llmModelId,
|
||||||
|
String vllmModelId,
|
||||||
String ttsModelId,
|
String ttsModelId,
|
||||||
String memModelId,
|
String memModelId,
|
||||||
String intentModelId,
|
String intentModelId,
|
||||||
@@ -233,9 +251,10 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
boolean isCache) {
|
boolean isCache) {
|
||||||
Map<String, String> selectedModule = new HashMap<>();
|
Map<String, String> selectedModule = new HashMap<>();
|
||||||
|
|
||||||
String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM" };
|
String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM", "VLLM" };
|
||||||
String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId };
|
String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId, vllmModelId };
|
||||||
String intentLLMModelId = null;
|
String intentLLMModelId = null;
|
||||||
|
String memLocalShortLLMModelId = null;
|
||||||
|
|
||||||
for (int i = 0; i < modelIds.length; i++) {
|
for (int i = 0; i < modelIds.length; i++) {
|
||||||
if (modelIds[i] == null) {
|
if (modelIds[i] == null) {
|
||||||
@@ -254,7 +273,7 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
||||||
if ("intent_llm".equals(map.get("type"))) {
|
if ("intent_llm".equals(map.get("type"))) {
|
||||||
intentLLMModelId = (String) map.get("llm");
|
intentLLMModelId = (String) map.get("llm");
|
||||||
if (intentLLMModelId != null && intentLLMModelId.equals(llmModelId)) {
|
if (StringUtils.isNotBlank(intentLLMModelId) && intentLLMModelId.equals(llmModelId)) {
|
||||||
intentLLMModelId = null;
|
intentLLMModelId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,10 +285,31 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ("Memory".equals(modelTypes[i])) {
|
||||||
|
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
||||||
|
if ("mem_local_short".equals(map.get("type"))) {
|
||||||
|
memLocalShortLLMModelId = (String) map.get("llm");
|
||||||
|
if (StringUtils.isNotBlank(memLocalShortLLMModelId)
|
||||||
|
&& memLocalShortLLMModelId.equals(llmModelId)) {
|
||||||
|
memLocalShortLLMModelId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 如果是LLM类型,且intentLLMModelId不为空,则添加附加模型
|
// 如果是LLM类型,且intentLLMModelId不为空,则添加附加模型
|
||||||
if ("LLM".equals(modelTypes[i]) && intentLLMModelId != null) {
|
if ("LLM".equals(modelTypes[i])) {
|
||||||
ModelConfigEntity intentLLM = modelConfigService.getModelById(intentLLMModelId, isCache);
|
if (StringUtils.isNotBlank(intentLLMModelId)) {
|
||||||
typeConfig.put(intentLLM.getId(), intentLLM.getConfigJson());
|
if (!typeConfig.containsKey(intentLLMModelId)) {
|
||||||
|
ModelConfigEntity intentLLM = modelConfigService.getModelById(intentLLMModelId, isCache);
|
||||||
|
typeConfig.put(intentLLM.getId(), intentLLM.getConfigJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(memLocalShortLLMModelId)) {
|
||||||
|
if (!typeConfig.containsKey(memLocalShortLLMModelId)) {
|
||||||
|
ModelConfigEntity memLocalShortLLM = modelConfigService
|
||||||
|
.getModelById(memLocalShortLLMModelId, isCache);
|
||||||
|
typeConfig.put(memLocalShortLLM.getId(), memLocalShortLLM.getConfigJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.put(modelTypes[i], typeConfig);
|
result.put(modelTypes[i], typeConfig);
|
||||||
@@ -282,5 +322,6 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
prompt = prompt.replace("{{assistant_name}}", StringUtils.isBlank(assistantName) ? "小智" : assistantName);
|
prompt = prompt.replace("{{assistant_name}}", StringUtils.isBlank(assistantName) ? "小智" : assistantName);
|
||||||
}
|
}
|
||||||
result.put("prompt", prompt);
|
result.put("prompt", prompt);
|
||||||
|
result.put("summaryMemory", summaryMemory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import java.util.TimeZone;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.aop.framework.AopContext;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
@@ -54,6 +56,24 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
private final OtaService otaService;
|
private final OtaService otaService;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void updateDeviceConnectionInfo(String agentId, String deviceId, String appVersion) {
|
||||||
|
try {
|
||||||
|
DeviceEntity device = new DeviceEntity();
|
||||||
|
device.setId(deviceId);
|
||||||
|
device.setLastConnectedAt(new Date());
|
||||||
|
if (StringUtils.isNotBlank(appVersion)) {
|
||||||
|
device.setAppVersion(appVersion);
|
||||||
|
}
|
||||||
|
deviceDao.updateById(device);
|
||||||
|
if (StringUtils.isNotBlank(agentId)) {
|
||||||
|
redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("异步更新设备连接信息失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean deviceActivation(String agentId, String activationCode) {
|
public Boolean deviceActivation(String agentId, String activationCode) {
|
||||||
if (StringUtils.isBlank(activationCode)) {
|
if (StringUtils.isBlank(activationCode)) {
|
||||||
@@ -118,14 +138,20 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
|
|
||||||
DeviceEntity deviceById = getDeviceByMacAddress(macAddress);
|
DeviceEntity deviceById = getDeviceByMacAddress(macAddress);
|
||||||
|
|
||||||
// 只有在设备已绑定且autoUpdate不为0的情况下才返回固件升级信息
|
// 设备未绑定,则返回当前上传的固件信息(不更新)以此兼容旧固件版本
|
||||||
if (deviceById != null && deviceById.getAutoUpdate() != 0) {
|
if (deviceById == null) {
|
||||||
String type = deviceReport.getBoard() == null ? null : deviceReport.getBoard().getType();
|
DeviceReportRespDTO.Firmware firmware = new DeviceReportRespDTO.Firmware();
|
||||||
DeviceReportRespDTO.Firmware firmware = buildFirmwareInfo(type,
|
firmware.setVersion(deviceReport.getApplication().getVersion());
|
||||||
deviceReport.getApplication() == null ? null : deviceReport.getApplication().getVersion());
|
firmware.setUrl(Constant.INVALID_FIRMWARE_URL);
|
||||||
response.setFirmware(firmware);
|
response.setFirmware(firmware);
|
||||||
} else {
|
} else {
|
||||||
response.setFirmware(null);
|
// 只有在设备已绑定且autoUpdate不为0的情况下才返回固件升级信息
|
||||||
|
if (deviceById.getAutoUpdate() != 0) {
|
||||||
|
String type = deviceReport.getBoard() == null ? null : deviceReport.getBoard().getType();
|
||||||
|
DeviceReportRespDTO.Firmware firmware = buildFirmwareInfo(type,
|
||||||
|
deviceReport.getApplication() == null ? null : deviceReport.getApplication().getVersion());
|
||||||
|
response.setFirmware(firmware);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加WebSocket配置
|
// 添加WebSocket配置
|
||||||
@@ -150,13 +176,12 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
response.setWebsocket(websocket);
|
response.setWebsocket(websocket);
|
||||||
|
|
||||||
if (deviceById != null) {
|
if (deviceById != null) {
|
||||||
// 如果设备存在,则更新上次连接时间
|
// 如果设备存在,则异步更新上次连接时间和版本信息
|
||||||
deviceById.setLastConnectedAt(new Date());
|
String appVersion = deviceReport.getApplication() != null ? deviceReport.getApplication().getVersion()
|
||||||
if (deviceReport.getApplication() != null
|
: null;
|
||||||
&& StringUtils.isNotBlank(deviceReport.getApplication().getVersion())) {
|
// 通过Spring代理调用异步方法
|
||||||
deviceById.setAppVersion(deviceReport.getApplication().getVersion());
|
((DeviceServiceImpl) AopContext.currentProxy()).updateDeviceConnectionInfo(deviceById.getAgentId(),
|
||||||
}
|
deviceById.getId(), appVersion);
|
||||||
deviceDao.updateById(deviceById);
|
|
||||||
} else {
|
} else {
|
||||||
// 如果设备不存在,则生成激活码
|
// 如果设备不存在,则生成激活码
|
||||||
DeviceReportRespDTO.Activation code = buildActivation(macAddress, deviceReport);
|
DeviceReportRespDTO.Activation code = buildActivation(macAddress, deviceReport);
|
||||||
@@ -353,7 +378,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
}
|
}
|
||||||
|
|
||||||
firmware.setVersion(ota == null ? currentVersion : ota.getVersion());
|
firmware.setVersion(ota == null ? currentVersion : ota.getVersion());
|
||||||
firmware.setUrl(downloadUrl == null ? "" : downloadUrl);
|
firmware.setUrl(downloadUrl == null ? Constant.INVALID_FIRMWARE_URL : downloadUrl);
|
||||||
return firmware;
|
return firmware;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,4 +410,4 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package xiaozhi.modules.model.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import xiaozhi.common.page.PageData;
|
||||||
|
import xiaozhi.common.utils.Result;
|
||||||
|
import xiaozhi.common.validator.group.UpdateGroup;
|
||||||
|
import xiaozhi.modules.model.dto.ModelProviderDTO;
|
||||||
|
import xiaozhi.modules.model.service.ModelProviderService;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/models/provider")
|
||||||
|
@Tag(name = "模型供应器")
|
||||||
|
public class ModelProviderController {
|
||||||
|
|
||||||
|
private final ModelProviderService modelProviderService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@Operation(summary = "获取模型供应器列表")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<PageData<ModelProviderDTO>> getListPage(ModelProviderDTO modelProviderDTO,
|
||||||
|
@RequestParam(required = true, defaultValue = "0") String page,
|
||||||
|
@RequestParam(required = true, defaultValue = "10") String limit) {
|
||||||
|
return new Result<PageData<ModelProviderDTO>>()
|
||||||
|
.ok(modelProviderService.getListPage(modelProviderDTO, page, limit));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "新增模型供应器")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<ModelProviderDTO> add(@RequestBody @Validated ModelProviderDTO modelProviderDTO) {
|
||||||
|
ModelProviderDTO resp = modelProviderService.add(modelProviderDTO);
|
||||||
|
return new Result<ModelProviderDTO>().ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
@Operation(summary = "修改模型供应器")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<ModelProviderDTO> edit(@RequestBody @Validated(UpdateGroup.class) ModelProviderDTO modelProviderDTO) {
|
||||||
|
ModelProviderDTO resp = modelProviderService.edit(modelProviderDTO);
|
||||||
|
return new Result<ModelProviderDTO>().ok(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@Operation(summary = "删除模型供应器")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
@Parameter(name = "ids", description = "ID数组", required = true)
|
||||||
|
public Result<Void> delete(@RequestBody List<String> ids) {
|
||||||
|
modelProviderService.delete(ids);
|
||||||
|
return new Result<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,29 +8,37 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import xiaozhi.common.validator.group.UpdateGroup;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "模型供应器/商")
|
@Schema(description = "模型供应器/商")
|
||||||
public class ModelProviderDTO implements Serializable {
|
public class ModelProviderDTO implements Serializable {
|
||||||
//
|
@Schema(description = "主键")
|
||||||
// @Schema(description = "主键")
|
@NotBlank(message = "id不能为空", groups = UpdateGroup.class)
|
||||||
// private Long id;
|
private String id;
|
||||||
|
|
||||||
@Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)")
|
@Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)")
|
||||||
|
@NotBlank(message = "modelType不能为空")
|
||||||
private String modelType;
|
private String modelType;
|
||||||
|
|
||||||
@Schema(description = "供应器类型")
|
@Schema(description = "供应器类型")
|
||||||
|
@NotBlank(message = "providerCode不能为空")
|
||||||
private String providerCode;
|
private String providerCode;
|
||||||
|
|
||||||
@Schema(description = "供应器名称")
|
@Schema(description = "供应器名称")
|
||||||
|
@NotBlank(message = "name不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "供应器字段列表(JSON格式)")
|
@Schema(description = "供应器字段列表(JSON格式)")
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
@NotBlank(message = "fields(JSON格式)不能为空")
|
||||||
private String fields;
|
private String fields;
|
||||||
|
|
||||||
@Schema(description = "排序")
|
@Schema(description = "排序")
|
||||||
|
@NotNull(message = "sort不能为空")
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
@Schema(description = "更新者")
|
@Schema(description = "更新者")
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ package xiaozhi.modules.model.entity;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -30,7 +28,6 @@ public class ModelProviderEntity {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "供应器字段列表(JSON格式)")
|
@Schema(description = "供应器字段列表(JSON格式)")
|
||||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
|
||||||
private String fields;
|
private String fields;
|
||||||
|
|
||||||
@Schema(description = "排序")
|
@Schema(description = "排序")
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package xiaozhi.modules.model.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.modules.model.dto.ModelProviderDTO;
|
import xiaozhi.modules.model.dto.ModelProviderDTO;
|
||||||
import xiaozhi.modules.model.entity.ModelProviderEntity;
|
|
||||||
|
|
||||||
public interface ModelProviderService {
|
public interface ModelProviderService {
|
||||||
|
|
||||||
@@ -11,11 +11,15 @@ public interface ModelProviderService {
|
|||||||
|
|
||||||
List<ModelProviderDTO> getListByModelType(String modelType);
|
List<ModelProviderDTO> getListByModelType(String modelType);
|
||||||
|
|
||||||
ModelProviderDTO add(ModelProviderEntity modelProviderEntity);
|
ModelProviderDTO add(ModelProviderDTO modelProviderDTO);
|
||||||
|
|
||||||
ModelProviderDTO edit(ModelProviderEntity modelProviderEntity);
|
ModelProviderDTO edit(ModelProviderDTO modelProviderDTO);
|
||||||
|
|
||||||
void delete();
|
void delete(String id);
|
||||||
|
|
||||||
|
void delete(List<String> id);
|
||||||
|
|
||||||
|
PageData<ModelProviderDTO> getListPage(ModelProviderDTO modelProviderDTO, String page, String limit);
|
||||||
|
|
||||||
List<ModelProviderDTO> getList(String modelType, String provideCode);
|
List<ModelProviderDTO> getList(String modelType, String provideCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
package xiaozhi.modules.model.service.impl;
|
package xiaozhi.modules.model.service.impl;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.common.service.impl.BaseServiceImpl;
|
import xiaozhi.common.service.impl.BaseServiceImpl;
|
||||||
|
import xiaozhi.common.user.UserDetail;
|
||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.modules.model.dao.ModelProviderDao;
|
import xiaozhi.modules.model.dao.ModelProviderDao;
|
||||||
import xiaozhi.modules.model.dto.ModelProviderDTO;
|
import xiaozhi.modules.model.dto.ModelProviderDTO;
|
||||||
import xiaozhi.modules.model.entity.ModelProviderEntity;
|
import xiaozhi.modules.model.entity.ModelProviderEntity;
|
||||||
import xiaozhi.modules.model.service.ModelProviderService;
|
import xiaozhi.modules.model.service.ModelProviderService;
|
||||||
|
import xiaozhi.modules.security.user.SecurityUser;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -32,18 +42,78 @@ public class ModelProviderServiceImpl extends BaseServiceImpl<ModelProviderDao,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelProviderDTO add(ModelProviderEntity modelProviderEntity) {
|
public PageData<ModelProviderDTO> getListPage(ModelProviderDTO modelProviderDTO, String page, String limit) {
|
||||||
return null;
|
|
||||||
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
params.put(Constant.PAGE, page);
|
||||||
|
params.put(Constant.LIMIT, limit);
|
||||||
|
params.put(Constant.ORDER_FIELD, List.of("model_type", "sort"));
|
||||||
|
params.put(Constant.ORDER, "asc");
|
||||||
|
|
||||||
|
IPage<ModelProviderEntity> pageParam = getPage(params, null, true);
|
||||||
|
|
||||||
|
QueryWrapper<ModelProviderEntity> wrapper = new QueryWrapper<ModelProviderEntity>();
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(modelProviderDTO.getModelType())) {
|
||||||
|
wrapper.eq("model_type", modelProviderDTO.getModelType());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(modelProviderDTO.getName())) {
|
||||||
|
wrapper.and(w -> w.like("name", modelProviderDTO.getName())
|
||||||
|
.or()
|
||||||
|
.like("provider_code", modelProviderDTO.getName()));
|
||||||
|
}
|
||||||
|
return getPageData(modelProviderDao.selectPage(pageParam, wrapper), ModelProviderDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String jsonString = "\"[]\"";
|
||||||
|
JSONArray jsonArray = new JSONArray(jsonString);
|
||||||
|
System.out.println("字符串转 JSONArray: " + jsonArray.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelProviderDTO edit(ModelProviderEntity modelProviderEntity) {
|
public ModelProviderDTO add(ModelProviderDTO modelProviderDTO) {
|
||||||
return null;
|
UserDetail user = SecurityUser.getUser();
|
||||||
|
modelProviderDTO.setCreator(user.getId());
|
||||||
|
modelProviderDTO.setUpdater(user.getId());
|
||||||
|
modelProviderDTO.setCreateDate(new Date());
|
||||||
|
modelProviderDTO.setUpdateDate(new Date());
|
||||||
|
// 去除Fields左右的双引号
|
||||||
|
|
||||||
|
modelProviderDTO.setFields(modelProviderDTO.getFields());
|
||||||
|
ModelProviderEntity entity = ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderEntity.class);
|
||||||
|
if (modelProviderDao.insert(entity) == 0) {
|
||||||
|
throw new RenException("新增数据失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public ModelProviderDTO edit(ModelProviderDTO modelProviderDTO) {
|
||||||
|
UserDetail user = SecurityUser.getUser();
|
||||||
|
modelProviderDTO.setUpdater(user.getId());
|
||||||
|
modelProviderDTO.setUpdateDate(new Date());
|
||||||
|
if (modelProviderDao
|
||||||
|
.updateById(ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderEntity.class)) == 0) {
|
||||||
|
throw new RenException("修改数据失败");
|
||||||
|
}
|
||||||
|
return ConvertUtils.sourceToTarget(modelProviderDTO, ModelProviderDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
if (modelProviderDao.deleteById(id) == 0) {
|
||||||
|
throw new RenException("删除数据失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(List<String> ids) {
|
||||||
|
if (modelProviderDao.deleteBatchIds(ids) == 0) {
|
||||||
|
throw new RenException("删除数据失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -80,12 +80,15 @@ public class ShiroConfig {
|
|||||||
filterMap.put("/doc.html", "anon");
|
filterMap.put("/doc.html", "anon");
|
||||||
filterMap.put("/favicon.ico", "anon");
|
filterMap.put("/favicon.ico", "anon");
|
||||||
filterMap.put("/user/captcha", "anon");
|
filterMap.put("/user/captcha", "anon");
|
||||||
|
filterMap.put("/user/smsVerification", "anon");
|
||||||
filterMap.put("/user/login", "anon");
|
filterMap.put("/user/login", "anon");
|
||||||
filterMap.put("/user/pub-config", "anon");
|
filterMap.put("/user/pub-config", "anon");
|
||||||
filterMap.put("/user/register", "anon");
|
filterMap.put("/user/register", "anon");
|
||||||
|
filterMap.put("/user/retrieve-password", "anon");
|
||||||
// 将config路径使用server服务过滤器
|
// 将config路径使用server服务过滤器
|
||||||
filterMap.put("/config/**", "server");
|
filterMap.put("/config/**", "server");
|
||||||
filterMap.put("/agent/chat-history/report", "server");
|
filterMap.put("/agent/chat-history/report", "server");
|
||||||
|
filterMap.put("/agent/saveMemory/**", "server");
|
||||||
filterMap.put("/agent/play/**", "anon");
|
filterMap.put("/agent/play/**", "anon");
|
||||||
filterMap.put("/**", "oauth2");
|
filterMap.put("/**", "oauth2");
|
||||||
shiroFilter.setFilterChainDefinitionMap(filterMap);
|
shiroFilter.setFilterChainDefinitionMap(filterMap);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package xiaozhi.modules.security.controller;
|
package xiaozhi.modules.security.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -24,13 +26,18 @@ import xiaozhi.common.utils.Result;
|
|||||||
import xiaozhi.common.validator.AssertUtils;
|
import xiaozhi.common.validator.AssertUtils;
|
||||||
import xiaozhi.common.validator.ValidatorUtils;
|
import xiaozhi.common.validator.ValidatorUtils;
|
||||||
import xiaozhi.modules.security.dto.LoginDTO;
|
import xiaozhi.modules.security.dto.LoginDTO;
|
||||||
|
import xiaozhi.modules.security.dto.SmsVerificationDTO;
|
||||||
import xiaozhi.modules.security.password.PasswordUtils;
|
import xiaozhi.modules.security.password.PasswordUtils;
|
||||||
import xiaozhi.modules.security.service.CaptchaService;
|
import xiaozhi.modules.security.service.CaptchaService;
|
||||||
import xiaozhi.modules.security.service.SysUserTokenService;
|
import xiaozhi.modules.security.service.SysUserTokenService;
|
||||||
import xiaozhi.modules.security.user.SecurityUser;
|
import xiaozhi.modules.security.user.SecurityUser;
|
||||||
import xiaozhi.modules.sys.dto.PasswordDTO;
|
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||||
|
import xiaozhi.modules.sys.dto.RetrievePasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
|
import xiaozhi.modules.sys.service.SysDictDataService;
|
||||||
|
import xiaozhi.modules.sys.service.SysParamsService;
|
||||||
import xiaozhi.modules.sys.service.SysUserService;
|
import xiaozhi.modules.sys.service.SysUserService;
|
||||||
|
import xiaozhi.modules.sys.vo.SysDictDataItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录控制层
|
* 登录控制层
|
||||||
@@ -43,24 +50,43 @@ public class LoginController {
|
|||||||
private final SysUserService sysUserService;
|
private final SysUserService sysUserService;
|
||||||
private final SysUserTokenService sysUserTokenService;
|
private final SysUserTokenService sysUserTokenService;
|
||||||
private final CaptchaService captchaService;
|
private final CaptchaService captchaService;
|
||||||
|
private final SysParamsService sysParamsService;
|
||||||
|
private final SysDictDataService sysDictDataService;
|
||||||
|
|
||||||
@GetMapping("/captcha")
|
@GetMapping("/captcha")
|
||||||
@Operation(summary = "验证码")
|
@Operation(summary = "验证码")
|
||||||
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
||||||
// uuid不能为空
|
// uuid不能为空
|
||||||
AssertUtils.isBlank(uuid, ErrorCode.IDENTIFIER_NOT_NULL);
|
AssertUtils.isBlank(uuid, ErrorCode.IDENTIFIER_NOT_NULL);
|
||||||
|
|
||||||
// 生成验证码
|
// 生成验证码
|
||||||
captchaService.create(response, uuid);
|
captchaService.create(response, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/smsVerification")
|
||||||
|
@Operation(summary = "短信验证码")
|
||||||
|
public Result<Void> smsVerification(@RequestBody SmsVerificationDTO dto) {
|
||||||
|
// 验证图形验证码
|
||||||
|
boolean validate = captchaService.validate(dto.getCaptchaId(), dto.getCaptcha(), true);
|
||||||
|
if (!validate) {
|
||||||
|
throw new RenException("图形验证码错误");
|
||||||
|
}
|
||||||
|
Boolean isMobileRegister = sysParamsService
|
||||||
|
.getValueObject(Constant.SysMSMParam.SERVER_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
|
||||||
|
if (!isMobileRegister) {
|
||||||
|
throw new RenException("没有开启手机注册,没法使用短信验证码功能");
|
||||||
|
}
|
||||||
|
// 发送短信验证码
|
||||||
|
captchaService.sendSMSValidateCode(dto.getPhone());
|
||||||
|
return new Result<>();
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@Operation(summary = "登录")
|
@Operation(summary = "登录")
|
||||||
public Result<TokenDTO> login(@RequestBody LoginDTO login) {
|
public Result<TokenDTO> login(@RequestBody LoginDTO login) {
|
||||||
// 验证是否正确输入验证码
|
// 验证是否正确输入验证码
|
||||||
boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha());
|
boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha(), true);
|
||||||
if (!validate) {
|
if (!validate) {
|
||||||
throw new RenException("验证码错误,请重新获取");
|
throw new RenException("图形验证码错误,请重新获取");
|
||||||
}
|
}
|
||||||
// 按照用户名获取用户
|
// 按照用户名获取用户
|
||||||
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
||||||
@@ -81,11 +107,29 @@ public class LoginController {
|
|||||||
if (!sysUserService.getAllowUserRegister()) {
|
if (!sysUserService.getAllowUserRegister()) {
|
||||||
throw new RenException("当前不允许普通用户注册");
|
throw new RenException("当前不允许普通用户注册");
|
||||||
}
|
}
|
||||||
// 验证是否正确输入验证码
|
// 是否开启手机注册
|
||||||
boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha());
|
Boolean isMobileRegister = sysParamsService
|
||||||
if (!validate) {
|
.getValueObject(Constant.SysMSMParam.SERVER_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
|
||||||
throw new RenException("验证码错误,请重新获取");
|
boolean validate;
|
||||||
|
if (isMobileRegister) {
|
||||||
|
// 验证用户是否是手机号码
|
||||||
|
boolean validPhone = ValidatorUtils.isValidPhone(login.getUsername());
|
||||||
|
if (!validPhone) {
|
||||||
|
throw new RenException("用户名不是手机号码,请重新输入");
|
||||||
|
}
|
||||||
|
// 验证短信验证码是否正常
|
||||||
|
validate = captchaService.validateSMSValidateCode(login.getUsername(), login.getMobileCaptcha(), false);
|
||||||
|
if (!validate) {
|
||||||
|
throw new RenException("手机验证码错误,请重新获取");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 验证是否正确输入验证码
|
||||||
|
validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha(), true);
|
||||||
|
if (!validate) {
|
||||||
|
throw new RenException("图形验证码错误,请重新获取");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照用户名获取用户
|
// 按照用户名获取用户
|
||||||
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
||||||
if (userDTO != null) {
|
if (userDTO != null) {
|
||||||
@@ -96,7 +140,6 @@ public class LoginController {
|
|||||||
userDTO.setPassword(login.getPassword());
|
userDTO.setPassword(login.getPassword());
|
||||||
sysUserService.save(userDTO);
|
sysUserService.save(userDTO);
|
||||||
return new Result<>();
|
return new Result<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/info")
|
@GetMapping("/info")
|
||||||
@@ -118,12 +161,54 @@ public class LoginController {
|
|||||||
return new Result<>();
|
return new Result<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/retrieve-password")
|
||||||
|
@Operation(summary = "找回密码")
|
||||||
|
public Result<?> retrievePassword(@RequestBody RetrievePasswordDTO dto) {
|
||||||
|
// 是否开启手机注册
|
||||||
|
Boolean isMobileRegister = sysParamsService
|
||||||
|
.getValueObject(Constant.SysMSMParam.SERVER_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class);
|
||||||
|
if (!isMobileRegister) {
|
||||||
|
throw new RenException("没有开启手机注册,没法使用找回密码功能");
|
||||||
|
}
|
||||||
|
// 判断非空
|
||||||
|
ValidatorUtils.validateEntity(dto);
|
||||||
|
// 验证用户是否是手机号码
|
||||||
|
boolean validPhone = ValidatorUtils.isValidPhone(dto.getPhone());
|
||||||
|
if (!validPhone) {
|
||||||
|
throw new RenException("输入的手机号码格式不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照用户名获取用户
|
||||||
|
SysUserDTO userDTO = sysUserService.getByUsername(dto.getPhone());
|
||||||
|
if (userDTO == null) {
|
||||||
|
throw new RenException("输入的手机号码未注册");
|
||||||
|
}
|
||||||
|
// 验证短信验证码是否正常
|
||||||
|
boolean validate = captchaService.validateSMSValidateCode(dto.getPhone(), dto.getCode(), false);
|
||||||
|
// 判断是否通过验证
|
||||||
|
if (!validate) {
|
||||||
|
throw new RenException("输入的手机验证码错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
sysUserService.changePasswordDirectly(userDTO.getId(), dto.getPassword());
|
||||||
|
return new Result<>();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/pub-config")
|
@GetMapping("/pub-config")
|
||||||
@Operation(summary = "公共配置")
|
@Operation(summary = "公共配置")
|
||||||
public Result<Map<String, Object>> pubConfig() {
|
public Result<Map<String, Object>> pubConfig() {
|
||||||
Map<String, Object> config = new HashMap<>();
|
Map<String, Object> config = new HashMap<>();
|
||||||
|
config.put("enableMobileRegister", sysParamsService
|
||||||
|
.getValueObject(Constant.SysMSMParam.SERVER_ENABLE_MOBILE_REGISTER.getValue(), Boolean.class));
|
||||||
config.put("version", Constant.VERSION);
|
config.put("version", Constant.VERSION);
|
||||||
|
config.put("year", "©" + Calendar.getInstance().get(Calendar.YEAR));
|
||||||
config.put("allowUserRegister", sysUserService.getAllowUserRegister());
|
config.put("allowUserRegister", sysUserService.getAllowUserRegister());
|
||||||
|
List<SysDictDataItem> list = sysDictDataService.getDictDataByType(Constant.DictType.MOBILE_AREA.getValue());
|
||||||
|
config.put("mobileAreaList", list);
|
||||||
|
config.put("beianIcpNum", sysParamsService.getValue(Constant.SysBaseParam.BEIAN_ICP_NUM.getValue(), true));
|
||||||
|
config.put("beianGaNum", sysParamsService.getValue(Constant.SysBaseParam.BEIAN_GA_NUM.getValue(), true));
|
||||||
|
config.put("name", sysParamsService.getValue(Constant.SysBaseParam.SERVER_NAME.getValue(), true));
|
||||||
|
|
||||||
return new Result<Map<String, Object>>().ok(config);
|
return new Result<Map<String, Object>>().ok(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,9 @@ public class LoginDTO implements Serializable {
|
|||||||
@NotBlank(message = "{sysuser.captcha.require}")
|
@NotBlank(message = "{sysuser.captcha.require}")
|
||||||
private String captcha;
|
private String captcha;
|
||||||
|
|
||||||
|
@Schema(description = "手机验证码")
|
||||||
|
private String mobileCaptcha;
|
||||||
|
|
||||||
@Schema(description = "唯一标识")
|
@Schema(description = "唯一标识")
|
||||||
@NotBlank(message = "{sysuser.uuid.require}")
|
@NotBlank(message = "{sysuser.uuid.require}")
|
||||||
private String captchaId;
|
private String captchaId;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package xiaozhi.modules.security.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码请求DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "短信验证码请求")
|
||||||
|
public class SmsVerificationDTO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "手机号码")
|
||||||
|
@NotBlank(message = "{sysuser.username.require}")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Schema(description = "验证码")
|
||||||
|
@NotBlank(message = "{sysuser.captcha.require}")
|
||||||
|
private String captcha;
|
||||||
|
|
||||||
|
@Schema(description = "唯一标识")
|
||||||
|
@NotBlank(message = "{sysuser.uuid.require}")
|
||||||
|
private String captchaId;
|
||||||
|
}
|
||||||
@@ -18,10 +18,28 @@ public interface CaptchaService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码效验
|
* 验证码效验
|
||||||
*
|
*
|
||||||
* @param uuid uuid
|
* @param uuid uuid
|
||||||
* @param code 验证码
|
* @param code 验证码
|
||||||
|
* @param delete 是否删除验证码
|
||||||
* @return true:成功 false:失败
|
* @return true:成功 false:失败
|
||||||
*/
|
*/
|
||||||
boolean validate(String uuid, String code);
|
boolean validate(String uuid, String code, Boolean delete);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送短信验证码
|
||||||
|
*
|
||||||
|
* @param phone 手机
|
||||||
|
*/
|
||||||
|
void sendSMSValidateCode(String phone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证短信验证码
|
||||||
|
*
|
||||||
|
* @param phone 手机
|
||||||
|
* @param code 验证码
|
||||||
|
* @param delete 是否删除验证码
|
||||||
|
* @return true:成功 false:失败
|
||||||
|
*/
|
||||||
|
boolean validateSMSValidateCode(String phone, String code, Boolean delete);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.security.service.impl;
|
package xiaozhi.modules.security.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -14,9 +15,13 @@ import com.wf.captcha.base.Captcha;
|
|||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.redis.RedisKeys;
|
import xiaozhi.common.redis.RedisKeys;
|
||||||
import xiaozhi.common.redis.RedisUtils;
|
import xiaozhi.common.redis.RedisUtils;
|
||||||
import xiaozhi.modules.security.service.CaptchaService;
|
import xiaozhi.modules.security.service.CaptchaService;
|
||||||
|
import xiaozhi.modules.sms.service.SmsService;
|
||||||
|
import xiaozhi.modules.sys.service.SysParamsService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码
|
* 验证码
|
||||||
@@ -25,6 +30,10 @@ import xiaozhi.modules.security.service.CaptchaService;
|
|||||||
public class CaptchaServiceImpl implements CaptchaService {
|
public class CaptchaServiceImpl implements CaptchaService {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtils redisUtils;
|
private RedisUtils redisUtils;
|
||||||
|
@Resource
|
||||||
|
private SmsService smsService;
|
||||||
|
@Resource
|
||||||
|
private SysParamsService sysParamsService;
|
||||||
@Value("${renren.redis.open}")
|
@Value("${renren.redis.open}")
|
||||||
private boolean open;
|
private boolean open;
|
||||||
/**
|
/**
|
||||||
@@ -51,12 +60,12 @@ public class CaptchaServiceImpl implements CaptchaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validate(String uuid, String code) {
|
public boolean validate(String uuid, String code, Boolean delete) {
|
||||||
if (StringUtils.isBlank(code)) {
|
if (StringUtils.isBlank(code)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 获取验证码
|
// 获取验证码
|
||||||
String captcha = getCache(uuid);
|
String captcha = getCache(uuid, delete);
|
||||||
|
|
||||||
// 效验成功
|
// 效验成功
|
||||||
if (code.equalsIgnoreCase(captcha)) {
|
if (code.equalsIgnoreCase(captcha)) {
|
||||||
@@ -66,21 +75,97 @@ public class CaptchaServiceImpl implements CaptchaService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendSMSValidateCode(String phone) {
|
||||||
|
// 检查发送间隔
|
||||||
|
String lastSendTimeKey = RedisKeys.getSMSLastSendTimeKey(phone);
|
||||||
|
// 获取是否发送过,如果没有设置最后发送时间(60秒)
|
||||||
|
String lastSendTime = redisUtils
|
||||||
|
.getKeyOrCreate(lastSendTimeKey,
|
||||||
|
String.valueOf(System.currentTimeMillis()), 60L);
|
||||||
|
if (lastSendTime != null) {
|
||||||
|
long lastSendTimeLong = Long.parseLong(lastSendTime);
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
long timeDiff = currentTime - lastSendTimeLong;
|
||||||
|
if (timeDiff < 60000) {
|
||||||
|
throw new RenException("发送太频繁,请" + (60000 - timeDiff) / 1000 + "秒后再试");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查今日发送次数
|
||||||
|
String todayCountKey = RedisKeys.getSMSTodayCountKey(phone);
|
||||||
|
Integer todayCount = (Integer) redisUtils.get(todayCountKey);
|
||||||
|
if (todayCount == null) {
|
||||||
|
todayCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取最大发送次数限制
|
||||||
|
Integer maxSendCount = sysParamsService.getValueObject(
|
||||||
|
Constant.SysMSMParam.SERVER_SMS_MAX_SEND_COUNT.getValue(),
|
||||||
|
Integer.class);
|
||||||
|
if (maxSendCount == null) {
|
||||||
|
maxSendCount = 5; // 默认值
|
||||||
|
}
|
||||||
|
|
||||||
|
if (todayCount >= maxSendCount) {
|
||||||
|
throw new RenException("今日发送次数已达上限");
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = RedisKeys.getSMSValidateCodeKey(phone);
|
||||||
|
String validateCodes = generateValidateCode(6);
|
||||||
|
|
||||||
|
// 设置验证码
|
||||||
|
setCache(key, validateCodes);
|
||||||
|
|
||||||
|
// 更新今日发送次数
|
||||||
|
if (todayCount == 0) {
|
||||||
|
redisUtils.increment(todayCountKey, RedisUtils.DEFAULT_EXPIRE);
|
||||||
|
} else {
|
||||||
|
redisUtils.increment(todayCountKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送验证码短信
|
||||||
|
smsService.sendVerificationCodeSms(phone, validateCodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateSMSValidateCode(String phone, String code, Boolean delete) {
|
||||||
|
String key = RedisKeys.getSMSValidateCodeKey(phone);
|
||||||
|
return validate(key, code, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成指定数量的随机数验证码
|
||||||
|
*
|
||||||
|
* @param length 数量
|
||||||
|
* @return 随机码
|
||||||
|
*/
|
||||||
|
private String generateValidateCode(Integer length) {
|
||||||
|
String chars = "0123456789"; // 字符范围可以自定义:数字
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder code = new StringBuilder();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
code.append(chars.charAt(random.nextInt(chars.length())));
|
||||||
|
}
|
||||||
|
return code.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private void setCache(String key, String value) {
|
private void setCache(String key, String value) {
|
||||||
if (open) {
|
if (open) {
|
||||||
key = RedisKeys.getCaptchaKey(key);
|
key = RedisKeys.getCaptchaKey(key);
|
||||||
|
// 设置5分钟过期
|
||||||
redisUtils.set(key, value, 300);
|
redisUtils.set(key, value, 300);
|
||||||
} else {
|
} else {
|
||||||
localCache.put(key, value);
|
localCache.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCache(String key) {
|
private String getCache(String key, Boolean delete) {
|
||||||
if (open) {
|
if (open) {
|
||||||
key = RedisKeys.getCaptchaKey(key);
|
key = RedisKeys.getCaptchaKey(key);
|
||||||
String captcha = (String) redisUtils.get(key);
|
String captcha = (String) redisUtils.get(key);
|
||||||
// 删除验证码
|
// 删除验证码
|
||||||
if (captcha != null) {
|
if (captcha != null && delete) {
|
||||||
redisUtils.delete(key);
|
redisUtils.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package xiaozhi.modules.sms.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信服务的方法定义接口
|
||||||
|
*
|
||||||
|
* @author zjy
|
||||||
|
* @since 2025-05-12
|
||||||
|
*/
|
||||||
|
public interface SmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送验证码短信
|
||||||
|
* @param phone 手机号码
|
||||||
|
* @param VerificationCode 验证码
|
||||||
|
*/
|
||||||
|
void sendVerificationCodeSms(String phone, String VerificationCode) ;
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package xiaozhi.modules.sms.service.imp;
|
||||||
|
|
||||||
|
import com.aliyun.dysmsapi20170525.Client;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||||
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
import xiaozhi.common.redis.RedisKeys;
|
||||||
|
import xiaozhi.common.redis.RedisUtils;
|
||||||
|
import xiaozhi.modules.sms.service.SmsService;
|
||||||
|
import xiaozhi.modules.sys.service.SysParamsService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class ALiYunSmsService implements SmsService {
|
||||||
|
private final SysParamsService sysParamsService;
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendVerificationCodeSms(String phone, String VerificationCode) {
|
||||||
|
Client client = createClient();
|
||||||
|
String SignName = sysParamsService.getValue(Constant.SysMSMParam
|
||||||
|
.ALIYUN_SMS_SIGN_NAME.getValue(),true);
|
||||||
|
String TemplateCode = sysParamsService.getValue(Constant.SysMSMParam
|
||||||
|
.ALIYUN_SMS_SMS_CODE_TEMPLATE_CODE.getValue(),true);
|
||||||
|
try {
|
||||||
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||||
|
.setSignName(SignName)
|
||||||
|
.setTemplateCode(TemplateCode)
|
||||||
|
.setPhoneNumbers(phone)
|
||||||
|
.setTemplateParam(String.format("{\"code\":\"%s\"}", VerificationCode));
|
||||||
|
RuntimeOptions runtime = new RuntimeOptions();
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
||||||
|
log.info("发送短信响应的requestID: {}", sendSmsResponse.getBody().getRequestId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果发送失败了退还这次发送数
|
||||||
|
String todayCountKey = RedisKeys.getSMSTodayCountKey(phone);
|
||||||
|
redisUtils.delete(todayCountKey);
|
||||||
|
// 错误 message
|
||||||
|
log.error(e.getMessage());
|
||||||
|
throw new RenException("短信发送失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建阿里云连接
|
||||||
|
* @return 返回连接对象
|
||||||
|
*/
|
||||||
|
private Client createClient(){
|
||||||
|
String ACCESS_KEY_ID = sysParamsService.getValue(Constant.SysMSMParam
|
||||||
|
.ALIYUN_SMS_ACCESS_KEY_ID.getValue(),true);
|
||||||
|
String ACCESS_KEY_SECRET = sysParamsService.getValue(Constant.SysMSMParam
|
||||||
|
.ALIYUN_SMS_ACCESS_KEY_SECRET.getValue(),true);
|
||||||
|
try {
|
||||||
|
Config config = new Config()
|
||||||
|
.setAccessKeyId(ACCESS_KEY_ID)
|
||||||
|
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||||
|
// 配置 Endpoint。中国站请使用dysmsapi.aliyuncs.com
|
||||||
|
config.endpoint = "dysmsapi.aliyuncs.com";
|
||||||
|
return new Client(config);
|
||||||
|
}catch (Exception e){
|
||||||
|
// 错误 message
|
||||||
|
log.error(e.getMessage());
|
||||||
|
throw new RenException("短信连接建立失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package xiaozhi.modules.sys.controller;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import xiaozhi.common.annotation.LogOperation;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
import xiaozhi.common.utils.Result;
|
||||||
|
import xiaozhi.modules.sys.dto.EmitSeverActionDTO;
|
||||||
|
import xiaozhi.modules.sys.dto.ServerActionPayloadDTO;
|
||||||
|
import xiaozhi.modules.sys.dto.ServerActionResponseDTO;
|
||||||
|
import xiaozhi.modules.sys.enums.ServerActionEnum;
|
||||||
|
import xiaozhi.modules.sys.service.SysParamsService;
|
||||||
|
import xiaozhi.modules.sys.utils.WebSocketClientManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端管理控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/server")
|
||||||
|
@Tag(name = "服务端管理")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ServerSideManageController {
|
||||||
|
private final SysParamsService sysParamsService;
|
||||||
|
private static final ObjectMapper objectMapper;
|
||||||
|
static {
|
||||||
|
objectMapper = new ObjectMapper();
|
||||||
|
// 忽略json字符串中存在,但pojo中不存在对应字段的情况
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取Ws服务端列表")
|
||||||
|
@GetMapping("/server-list")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<List<String>> getWsServerList() {
|
||||||
|
String wsText = sysParamsService.getValue(Constant.SERVER_WEBSOCKET, true);
|
||||||
|
if (StringUtils.isBlank(wsText)) {
|
||||||
|
return new Result<List<String>>().ok(Collections.emptyList());
|
||||||
|
}
|
||||||
|
return new Result<List<String>>().ok(Arrays.asList(wsText.split(";")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "通知python服务端更新配置")
|
||||||
|
@PostMapping("/emit-action")
|
||||||
|
@LogOperation("通知python服务端更新配置")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<Boolean> emitServerAction(@RequestBody @Valid EmitSeverActionDTO emitSeverActionDTO) {
|
||||||
|
if (emitSeverActionDTO.getAction() == null) {
|
||||||
|
throw new RenException("无效服务端操作");
|
||||||
|
}
|
||||||
|
String wsText = sysParamsService.getValue(Constant.SERVER_WEBSOCKET, true);
|
||||||
|
if (StringUtils.isBlank(wsText)) {
|
||||||
|
throw new RenException("未配置服务端WebSocket地址");
|
||||||
|
}
|
||||||
|
String targetWs = emitSeverActionDTO.getTargetWs();
|
||||||
|
String[] wsList = wsText.split(";");
|
||||||
|
// 找到需要发起的
|
||||||
|
if (StringUtils.isBlank(targetWs) || !Arrays.asList(wsList).contains(targetWs)) {
|
||||||
|
throw new RenException("目标WebSocket地址不存在");
|
||||||
|
}
|
||||||
|
return new Result<Boolean>().ok(emitServerActionByWs(targetWs, emitSeverActionDTO.getAction()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean emitServerActionByWs(String targetWsUri, ServerActionEnum actionEnum) {
|
||||||
|
if (StringUtils.isBlank(targetWsUri) || actionEnum == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String serverSK = sysParamsService.getValue(Constant.SERVER_SECRET, true);
|
||||||
|
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||||
|
headers.add("device-id", UUID.randomUUID().toString());
|
||||||
|
headers.add("client-id", UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
try (WebSocketClientManager client = new WebSocketClientManager.Builder()
|
||||||
|
.connectTimeout(3, TimeUnit.SECONDS)
|
||||||
|
.maxSessionDuration(120, TimeUnit.SECONDS)
|
||||||
|
.uri(targetWsUri)
|
||||||
|
.headers(headers)
|
||||||
|
.build()) {
|
||||||
|
// 如果连接成功则发送一个json数据包并等待服务端响应
|
||||||
|
client.sendJson(
|
||||||
|
ServerActionPayloadDTO.build(
|
||||||
|
actionEnum,
|
||||||
|
Map.of("secret", serverSK)));
|
||||||
|
// 等待服务端响应并持续监听信息
|
||||||
|
client.listener((jsonText) -> {
|
||||||
|
if (StringUtils.isBlank(jsonText)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ServerActionResponseDTO response = objectMapper.readValue(jsonText, ServerActionResponseDTO.class);
|
||||||
|
Boolean isSuccess = ServerActionResponseDTO.isSuccess(response);
|
||||||
|
return isSuccess;
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 捕获全部错误,由全局异常处理器返回
|
||||||
|
throw new RenException("WebSocket连接失败或连接超时");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ public class SysParamsController {
|
|||||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", in = ParameterIn.QUERY, required = true, ref = "int"),
|
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", in = ParameterIn.QUERY, required = true, ref = "int"),
|
||||||
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段", in = ParameterIn.QUERY, ref = "String"),
|
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段", in = ParameterIn.QUERY, ref = "String"),
|
||||||
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref = "String"),
|
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)", in = ParameterIn.QUERY, ref = "String"),
|
||||||
@Parameter(name = "paramCode", description = "参数编码", in = ParameterIn.QUERY, ref = "String")
|
@Parameter(name = "paramCode", description = "参数编码或参数备注", in = ParameterIn.QUERY, ref = "String")
|
||||||
})
|
})
|
||||||
@RequiresPermissions("sys:role:superAdmin")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<PageData<SysParamsDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
public Result<PageData<SysParamsDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
||||||
@@ -111,7 +111,7 @@ public class SysParamsController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证WebSocket地址列表
|
* 验证WebSocket地址列表
|
||||||
*
|
*
|
||||||
* @param urls WebSocket地址列表,以分号分隔
|
* @param urls WebSocket地址列表,以分号分隔
|
||||||
* @return 验证结果
|
* @return 验证结果
|
||||||
*/
|
*/
|
||||||
@@ -143,6 +143,19 @@ public class SysParamsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
@LogOperation("删除")
|
||||||
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
|
public Result<Void> delete(@RequestBody String[] ids) {
|
||||||
|
// 效验数据
|
||||||
|
AssertUtils.isArrayEmpty(ids, "id");
|
||||||
|
|
||||||
|
sysParamsService.delete(ids);
|
||||||
|
configService.getConfig(false);
|
||||||
|
return new Result<Void>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证OTA地址
|
* 验证OTA地址
|
||||||
*/
|
*/
|
||||||
@@ -182,17 +195,4 @@ public class SysParamsController {
|
|||||||
throw new RenException("OTA接口验证失败:" + e.getMessage());
|
throw new RenException("OTA接口验证失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/delete")
|
|
||||||
@Operation(summary = "删除")
|
|
||||||
@LogOperation("删除")
|
|
||||||
@RequiresPermissions("sys:role:superAdmin")
|
|
||||||
public Result<Void> delete(@RequestBody String[] ids) {
|
|
||||||
// 效验数据
|
|
||||||
AssertUtils.isArrayEmpty(ids, "id");
|
|
||||||
|
|
||||||
sysParamsService.delete(ids);
|
|
||||||
configService.getConfig(false);
|
|
||||||
return new Result<Void>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package xiaozhi.modules.sys.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import xiaozhi.modules.sys.enums.ServerActionEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送python服务端操作DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EmitSeverActionDTO
|
||||||
|
{
|
||||||
|
@Schema(description = "目标ws地址")
|
||||||
|
@NotEmpty(message = "目标ws地址不能为空")
|
||||||
|
private String targetWs;
|
||||||
|
|
||||||
|
@Schema(description = "指定操作")
|
||||||
|
@NotNull(message = "操作不能为空")
|
||||||
|
private ServerActionEnum action;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package xiaozhi.modules.sys.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 找回密码DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "找回密码")
|
||||||
|
public class RetrievePasswordDTO implements Serializable {
|
||||||
|
|
||||||
|
@Schema(description = "手机号码")
|
||||||
|
@NotBlank(message = "{sysuser.password.require}")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@Schema(description = "验证码")
|
||||||
|
@NotBlank(message = "{sysuser.password.require}")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Schema(description = "新密码")
|
||||||
|
@NotBlank(message = "{sysuser.password.require}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package xiaozhi.modules.sys.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import xiaozhi.modules.sys.enums.ServerActionEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端动作DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ServerActionPayloadDTO
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 类型(智控台发往服务端的都是server)
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
/**
|
||||||
|
* 动作
|
||||||
|
*/
|
||||||
|
private ServerActionEnum action;
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
private Map<String, Object> content;
|
||||||
|
|
||||||
|
public static ServerActionPayloadDTO build(ServerActionEnum action, Map<String, Object> content) {
|
||||||
|
ServerActionPayloadDTO serverActionPayloadDTO = new ServerActionPayloadDTO();
|
||||||
|
serverActionPayloadDTO.setAction(action);
|
||||||
|
serverActionPayloadDTO.setContent(content);
|
||||||
|
serverActionPayloadDTO.setType("server");
|
||||||
|
return serverActionPayloadDTO;
|
||||||
|
}
|
||||||
|
// 私有化
|
||||||
|
private ServerActionPayloadDTO() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package xiaozhi.modules.sys.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import xiaozhi.modules.sys.enums.ServerActionResponseEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端动作响应体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ServerActionResponseDTO
|
||||||
|
{
|
||||||
|
private ServerActionResponseEnum status;
|
||||||
|
private String message;
|
||||||
|
private String type;
|
||||||
|
private Map<String, Object> content; // 后续这个字段可以移除,并把这个类作为基类,针对业务写自己的content类型
|
||||||
|
public static final String DEFAULT_TYPE_FORM_SERVER = "server";
|
||||||
|
|
||||||
|
public static Boolean isSuccess(ServerActionResponseDTO actionResponseDTO) {
|
||||||
|
System.out.println(actionResponseDTO);
|
||||||
|
if (actionResponseDTO == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (actionResponseDTO.getStatus() == null || !actionResponseDTO.getStatus().equals(ServerActionResponseEnum.SUCCESS)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Object actionType = actionResponseDTO.getContent().get("action");
|
||||||
|
if (actionType == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return actionResponseDTO.getType() != null && actionResponseDTO.getType().equals(DEFAULT_TYPE_FORM_SERVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package xiaozhi.modules.sys.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端动作枚举
|
||||||
|
*/
|
||||||
|
public enum ServerActionEnum
|
||||||
|
{
|
||||||
|
RESTART("restart"),
|
||||||
|
UPDATE_CONFIG("update_config");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
ServerActionEnum(String value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static ServerActionEnum fromValue(String value)
|
||||||
|
{
|
||||||
|
for (ServerActionEnum action : ServerActionEnum.values())
|
||||||
|
{
|
||||||
|
if (action.value.equalsIgnoreCase(value))
|
||||||
|
{
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package xiaozhi.modules.sys.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端调用响应枚举
|
||||||
|
*/
|
||||||
|
public enum ServerActionResponseEnum
|
||||||
|
{
|
||||||
|
SUCCESS("success"), FAIL("fail");
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
ServerActionResponseEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static ServerActionResponseEnum fromValue(String value) {
|
||||||
|
ServerActionResponseEnum byValue = getByValue(value);
|
||||||
|
if (byValue == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown enum value: " + value);
|
||||||
|
}
|
||||||
|
return byValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerActionResponseEnum getByValue(String value) {
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (ServerActionResponseEnum action : ServerActionResponseEnum.values()) {
|
||||||
|
if (action.value.equals(value)) {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package xiaozhi.modules.sys.service.impl;
|
package xiaozhi.modules.sys.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -55,7 +56,9 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
|||||||
|
|
||||||
QueryWrapper<SysParamsEntity> wrapper = new QueryWrapper<>();
|
QueryWrapper<SysParamsEntity> wrapper = new QueryWrapper<>();
|
||||||
wrapper.eq("param_type", 1);
|
wrapper.eq("param_type", 1);
|
||||||
wrapper.like(StringUtils.isNotBlank(paramCode), "param_code", paramCode);
|
wrapper.nested(StringUtils.isNotBlank(paramCode), i -> i.like("param_code", paramCode)
|
||||||
|
.or()
|
||||||
|
.like("remark", paramCode));
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
@@ -82,7 +85,7 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(SysParamsDTO dto) {
|
public void update(SysParamsDTO dto) {
|
||||||
validateParamValue(dto);
|
validateParamValue(dto);
|
||||||
|
detectingSMSParameters(dto.getParamCode(), dto.getParamValue());
|
||||||
SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class);
|
SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class);
|
||||||
updateById(entity);
|
updateById(entity);
|
||||||
|
|
||||||
@@ -204,4 +207,41 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
|||||||
updateValueByCode(Constant.SERVER_SECRET, newSecret);
|
updateValueByCode(Constant.SERVER_SECRET, newSecret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测短信参数是否符合要求
|
||||||
|
*
|
||||||
|
* @param paramCode 参数编码
|
||||||
|
* @param paramValue 参数值
|
||||||
|
* @return 是否通过
|
||||||
|
*/
|
||||||
|
private boolean detectingSMSParameters(String paramCode, String paramValue) {
|
||||||
|
// 判断是否是开启手机注册的参数编码,如果不是参数编码,着不需要检测其他短信参数,直接返回true
|
||||||
|
if (!Constant.SysMSMParam.SERVER_ENABLE_MOBILE_REGISTER.getValue().equals(paramCode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 判断是否为关闭,如果是关闭短信注册,着不需要检测其他短信参数,直接返回true
|
||||||
|
if ("false".equalsIgnoreCase(paramValue)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 检测短信关联参数是否为空
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
list.add(Constant.SysMSMParam.SERVER_SMS_MAX_SEND_COUNT.getValue());
|
||||||
|
list.add(Constant.SysMSMParam.ALIYUN_SMS_ACCESS_KEY_ID.getValue());
|
||||||
|
list.add(Constant.SysMSMParam.ALIYUN_SMS_ACCESS_KEY_SECRET.getValue());
|
||||||
|
list.add(Constant.SysMSMParam.ALIYUN_SMS_SIGN_NAME.getValue());
|
||||||
|
list.add(Constant.SysMSMParam.ALIYUN_SMS_SMS_CODE_TEMPLATE_CODE.getValue());
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
list.forEach(item -> {
|
||||||
|
if (!StringUtils.isNoneBlank(item)) {
|
||||||
|
str.append(",").append(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!str.isEmpty()) {
|
||||||
|
String promptStr = "%s这些参数不可以为空";
|
||||||
|
String substring = str.substring(1, str.length());
|
||||||
|
throw new RenException(promptStr.formatted(substring));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +133,10 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void changePasswordDirectly(Long userId, String password) {
|
public void changePasswordDirectly(Long userId, String password) {
|
||||||
|
// 新密码强度
|
||||||
|
if (!isStrongPassword(password)) {
|
||||||
|
throw new RenException(ErrorCode.PASSWORD_WEAK_ERROR);
|
||||||
|
}
|
||||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||||
sysUserEntity.setId(userId);
|
sysUserEntity.setId(userId);
|
||||||
sysUserEntity.setPassword(PasswordUtils.encode(password));
|
sysUserEntity.setPassword(PasswordUtils.encode(password));
|
||||||
@@ -159,7 +163,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||||||
params.put(Constant.LIMIT, dto.getLimit());
|
params.put(Constant.LIMIT, dto.getLimit());
|
||||||
IPage<SysUserEntity> page = baseDao.selectPage(
|
IPage<SysUserEntity> page = baseDao.selectPage(
|
||||||
getPage(params, "id", true),
|
getPage(params, "id", true),
|
||||||
new QueryWrapper<SysUserEntity>().eq(StringUtils.isNotBlank(dto.getMobile()), "username",
|
new QueryWrapper<SysUserEntity>().like(StringUtils.isNotBlank(dto.getMobile()), "username",
|
||||||
dto.getMobile()));
|
dto.getMobile()));
|
||||||
// 循环处理page获取回来的数据,返回需要的字段
|
// 循环处理page获取回来的数据,返回需要的字段
|
||||||
List<AdminPageUserVO> list = page.getRecords().stream().map(user -> {
|
List<AdminPageUserVO> list = page.getRecords().stream().map(user -> {
|
||||||
|
|||||||
@@ -0,0 +1,315 @@
|
|||||||
|
package xiaozhi.modules.sys.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.web.socket.*;
|
||||||
|
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||||
|
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||||
|
import xiaozhi.common.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocketClientResource:支持 try-with-resources 模式
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class WebSocketClientManager implements Closeable
|
||||||
|
{
|
||||||
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
|
// 全局回调线程池
|
||||||
|
private static final ExecutorService CALLBACK_EXECUTOR = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
|
||||||
|
private final AtomicInteger cnt = new AtomicInteger();
|
||||||
|
|
||||||
|
public Thread newThread(Runnable r)
|
||||||
|
{
|
||||||
|
Thread t = new Thread(r, "ws-callback-" + cnt.getAndIncrement());
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private volatile WebSocketSession session;
|
||||||
|
private final BlockingQueue<String> textMessageQueue;
|
||||||
|
private final BlockingQueue<byte[]> binaryMessageQueue;
|
||||||
|
private final CompletableFuture<Void> errorFuture;
|
||||||
|
private final long maxSessionDuration;
|
||||||
|
private final TimeUnit maxSessionDurationUnit;
|
||||||
|
|
||||||
|
private volatile Consumer<String> onText;
|
||||||
|
private volatile Consumer<byte[]> onBinary;
|
||||||
|
private volatile Consumer<Throwable> onError;
|
||||||
|
|
||||||
|
private final String uri;
|
||||||
|
private final WebSocketHttpHeaders headers;
|
||||||
|
private final long connectTimeout;
|
||||||
|
private final TimeUnit connectUnit;
|
||||||
|
private final int queueCapacity;
|
||||||
|
|
||||||
|
// 私有构造,仅由 Builder 调用
|
||||||
|
private WebSocketClientManager(Builder b) {
|
||||||
|
this.uri = b.uri;
|
||||||
|
this.headers = b.headers != null ? b.headers : new WebSocketHttpHeaders();
|
||||||
|
this.connectTimeout = b.connectTimeout;
|
||||||
|
this.connectUnit = b.connectUnit;
|
||||||
|
this.maxSessionDuration = b.maxSessionDuration;
|
||||||
|
this.maxSessionDurationUnit = b.maxSessionDurationUnit;
|
||||||
|
this.queueCapacity = b.queueCapacity;
|
||||||
|
this.textMessageQueue = new LinkedBlockingQueue<>(queueCapacity);
|
||||||
|
this.binaryMessageQueue = new LinkedBlockingQueue<>(queueCapacity);
|
||||||
|
this.errorFuture = new CompletableFuture<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebSocketClientManager build(Builder b) throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
|
WebSocketClientManager ws = new WebSocketClientManager(b);
|
||||||
|
StandardWebSocketClient client = new StandardWebSocketClient();
|
||||||
|
CompletableFuture<WebSocketSession> future = client.execute(ws.new InternalHandler(b.uri), b.headers, URI.create(b.uri));
|
||||||
|
WebSocketSession sess = future.get(b.connectTimeout, b.connectUnit);
|
||||||
|
if (sess == null || !sess.isOpen())
|
||||||
|
{
|
||||||
|
throw new IOException("握手失败或会话未打开");
|
||||||
|
}
|
||||||
|
ws.session = sess;
|
||||||
|
return ws;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送 Text
|
||||||
|
*/
|
||||||
|
public void sendText(String text) throws IOException {
|
||||||
|
session.sendMessage(new TextMessage(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBinary(byte[] data) throws IOException {
|
||||||
|
session.sendMessage(new BinaryMessage(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendJson(Object payload) throws IOException {
|
||||||
|
String json = OBJECT_MAPPER.writeValueAsString(payload);
|
||||||
|
session.sendMessage(new TextMessage(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private <T> List<T> listenerCustom(
|
||||||
|
BlockingQueue<T> queue,
|
||||||
|
Predicate<T> predicate)
|
||||||
|
throws InterruptedException, TimeoutException, ExecutionException
|
||||||
|
{
|
||||||
|
List<T> collected = new ArrayList<>();
|
||||||
|
long deadline = System.currentTimeMillis() + maxSessionDurationUnit.toMillis(maxSessionDuration);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (errorFuture.isDone()) {
|
||||||
|
errorFuture.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
long remaining = deadline - System.currentTimeMillis();
|
||||||
|
if (remaining <= 0) {
|
||||||
|
throw new TimeoutException("等待批量消息超时");
|
||||||
|
}
|
||||||
|
|
||||||
|
T msg = queue.poll(remaining, TimeUnit.MILLISECONDS);
|
||||||
|
if (msg == null) {
|
||||||
|
throw new TimeoutException("等待批量消息超时");
|
||||||
|
}
|
||||||
|
|
||||||
|
collected.add(msg);
|
||||||
|
if (predicate.test(msg)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return collected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步接收多条消息,直到 predicate 为 true 或超时抛异常;
|
||||||
|
* @return 返回监听期间的所有消息列表
|
||||||
|
*/
|
||||||
|
public List<String> listener(Predicate<String> predicate)
|
||||||
|
throws InterruptedException, TimeoutException, ExecutionException
|
||||||
|
{
|
||||||
|
return listenerCustom(textMessageQueue, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> listenerBinary(Predicate<byte[]> predicate)
|
||||||
|
throws InterruptedException, TimeoutException, ExecutionException
|
||||||
|
{
|
||||||
|
return listenerCustom(binaryMessageQueue, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册文本回调
|
||||||
|
*/
|
||||||
|
public WebSocketClientManager onText(Consumer<String> c) {
|
||||||
|
this.onText = c;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册二进制回调
|
||||||
|
*/
|
||||||
|
public WebSocketClientManager onBinary(Consumer<byte[]> c) {
|
||||||
|
this.onBinary = c;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册错误回调
|
||||||
|
*/
|
||||||
|
public WebSocketClientManager onError(Consumer<Throwable> c) {
|
||||||
|
this.onError = c;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭会话,try-with-resources / finally 自动调用
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
try {
|
||||||
|
if (session != null && session.isOpen()) {
|
||||||
|
session.close(CloseStatus.NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ignored) {}
|
||||||
|
textMessageQueue.clear();
|
||||||
|
binaryMessageQueue.clear();
|
||||||
|
errorFuture.completeExceptionally(new IOException("WebSocket 已关闭"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InternalHandler extends AbstractWebSocketHandler {
|
||||||
|
private final String targetUri;
|
||||||
|
private final StopWatch stopWatch;
|
||||||
|
|
||||||
|
InternalHandler(String targetUri) {
|
||||||
|
this.targetUri = targetUri;
|
||||||
|
this.stopWatch = new StopWatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接建立时回调
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
|
// 保存会话
|
||||||
|
WebSocketClientManager.this.session = session;
|
||||||
|
this.stopWatch.start();
|
||||||
|
log.info("ws连接成功, 目标URI: {}, 连接时间: {}", targetUri, DateUtils.getDateTimeNow(DateUtils.DATE_TIME_MILLIS_PATTERN));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文本消息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||||
|
String payload = message.getPayload();
|
||||||
|
// 入队
|
||||||
|
textMessageQueue.offer(payload);
|
||||||
|
// 回调用户注册的 onText
|
||||||
|
if (onText != null) {
|
||||||
|
CALLBACK_EXECUTOR.submit(() -> onText.accept(payload));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理二进制消息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
|
||||||
|
ByteBuffer buf = message.getPayload();
|
||||||
|
byte[] data = new byte[buf.remaining()];
|
||||||
|
buf.get(data);
|
||||||
|
// 入队
|
||||||
|
binaryMessageQueue.offer(data);
|
||||||
|
// 回调用户注册的 onBinary
|
||||||
|
if (onBinary != null) {
|
||||||
|
CALLBACK_EXECUTOR.submit(() -> onBinary.accept(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传输错误时回调
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
|
||||||
|
super.handleTransportError(session, exception);
|
||||||
|
// 保持原有逻辑:完成 errorFuture、回调 onError、关闭会话、异步通知连接失败
|
||||||
|
errorFuture.completeExceptionally(exception);
|
||||||
|
if (onError != null) {
|
||||||
|
CALLBACK_EXECUTOR.submit(() -> onError.accept(exception));
|
||||||
|
}
|
||||||
|
session.close(CloseStatus.SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接关闭时回调
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
||||||
|
super.afterConnectionClosed(session, status);
|
||||||
|
if (stopWatch.isRunning()) {
|
||||||
|
stopWatch.stop();
|
||||||
|
}
|
||||||
|
log.info("ws连接关闭, 目标URI: {}, 关闭时间: {}, 连接总时长: {}s",
|
||||||
|
targetUri, DateUtils.getDateTimeNow(DateUtils.DATE_TIME_MILLIS_PATTERN), DateUtils.millsToSecond(stopWatch.getTotalTimeMillis()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private String uri; // 目标 WS URI
|
||||||
|
private long connectTimeout = 3; // 请求连接等待时间
|
||||||
|
private TimeUnit connectUnit = TimeUnit.SECONDS; // 请求连接等待时间单位
|
||||||
|
private long maxSessionDuration = 5; // 最大连线时间,默认5秒
|
||||||
|
private TimeUnit maxSessionDurationUnit = TimeUnit.SECONDS; // 最大连线时间单位
|
||||||
|
private int queueCapacity = 100; // 消息队列容量
|
||||||
|
private WebSocketHttpHeaders headers; // 请求头
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目标 WS URI
|
||||||
|
*/
|
||||||
|
public Builder uri(String uri) {
|
||||||
|
this.uri = Objects.requireNonNull(uri);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder headers(WebSocketHttpHeaders h) {
|
||||||
|
this.headers = h;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder connectTimeout(long t, TimeUnit u) {
|
||||||
|
this.connectTimeout = t;
|
||||||
|
this.connectUnit = u;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder maxSessionDuration(long t, TimeUnit u) {
|
||||||
|
this.maxSessionDuration = t;
|
||||||
|
this.maxSessionDurationUnit = u;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder queueCapacity(int c) {
|
||||||
|
this.queueCapacity = c;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebSocketClientManager build() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
|
return WebSocketClientManager.build(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,4 +48,4 @@ spring:
|
|||||||
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
||||||
max-idle: 8 # 连接池中的最大空闲连接
|
max-idle: 8 # 连接池中的最大空闲连接
|
||||||
min-idle: 0 # 连接池中的最小空闲连接
|
min-idle: 0 # 连接池中的最小空闲连接
|
||||||
shutdown-timeout: 100ms # 客户端优雅关闭的等待时间
|
shutdown-timeout: 100ms # 客户端优雅关闭的等待时间
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
-- 更新模型供应器表
|
||||||
|
UPDATE `ai_model_provider` SET fields = '[{"key": "host", "type": "string", "label": "服务地址"}, {"key": "port", "type": "number", "label": "端口号"}, {"key": "type", "type": "string", "label": "服务类型"}, {"key": "is_ssl", "type": "boolean", "label": "是否使用SSL"}, {"key": "api_key", "type": "string", "label": "API密钥"}, {"key": "output_dir", "type": "string", "label": "输出目录"}]' WHERE id = 'SYSTEM_ASR_FunASRServer';
|
||||||
|
|
||||||
|
-- 更新模型配置表
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
config_json = '{"host": "127.0.0.1", "port": 10096, "type": "fun_server", "is_ssl": true, "api_key": "none", "output_dir": "tmp/"}',
|
||||||
|
`doc_link` = 'https://github.com/modelscope/FunASR/blob/main/runtime/docs/SDK_advanced_guide_online_zh.md',
|
||||||
|
`remark` = '独立部署FunASR,使用FunASR的API服务,只需要五句话
|
||||||
|
第一句:mkdir -p ./funasr-runtime-resources/models
|
||||||
|
第二句:sudo docker run -p 10096:10095 -it --privileged=true -v $PWD/funasr-runtime-resources/models:/workspace/models registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-online-cpu-0.1.12
|
||||||
|
上一句话执行后会进入到容器,继续第三句:cd FunASR/runtime
|
||||||
|
不要退出容器,继续在容器中执行第四句:nohup bash run_server_2pass.sh --download-model-dir /workspace/models --vad-dir damo/speech_fsmn_vad_zh-cn-16k-common-onnx --model-dir damo/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-onnx --online-model-dir damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx --punc-dir damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx --lm-dir damo/speech_ngram_lm_zh-cn-ai-wesp-fst --itn-dir thuduj12/fst_itn_zh --hotword /workspace/models/hotwords.txt > log.txt 2>&1 &
|
||||||
|
上一句话执行后会进入到容器,继续第五句:tail -f log.txt
|
||||||
|
第五句话执行完后,会看到模型下载日志,下载完后就可以连接使用了
|
||||||
|
以上是使用CPU推理,如果有GPU,详细参考:https://github.com/modelscope/FunASR/blob/main/runtime/docs/SDK_advanced_guide_online_zh.md' WHERE `id` = 'ASR_FunASRServer';
|
||||||
|
|
||||||
|
-- FishSpeech配置说明
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/docs/fish-speech-integration.md',
|
||||||
|
`remark` = 'FishSpeech配置说明:
|
||||||
|
1. 需要本地部署FishSpeech服务
|
||||||
|
2. 支持自定义音色
|
||||||
|
3. 本地推理,无需网络连接
|
||||||
|
4. 输出文件保存在tmp/目录
|
||||||
|
5. 可参照教程https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/docs/fish-speech-integration.md' WHERE `id` = 'TTS_FishSpeech';
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 添加聊天记录配置字段
|
||||||
|
ALTER TABLE `ai_agent`
|
||||||
|
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
|
||||||
|
|
||||||
|
ALTER TABLE `ai_agent_template`
|
||||||
|
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 添加总结记忆字段
|
||||||
|
ALTER TABLE `ai_agent`
|
||||||
|
ADD COLUMN `summary_memory` text COMMENT '总结记忆' AFTER `system_prompt`;
|
||||||
|
|
||||||
|
ALTER TABLE `ai_agent_template`
|
||||||
|
ADD COLUMN `summary_memory` text COMMENT '总结记忆' AFTER `system_prompt`;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
update ai_agent_template set system_prompt = replace(system_prompt, '我是', '你是');
|
||||||
|
|
||||||
|
delete from sys_params where id in (500,501,402);
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (500, 'end_prompt.enable', 'true', 'boolean', 1, '是否开启结束语');
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (501, 'end_prompt.prompt', '请你以“时间过得真快”未来头,用富有感情、依依不舍的话来结束这场对话吧!', 'string', 1, '结束提示词');
|
||||||
|
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (402, 'plugins.get_weather.api_host', 'mj7p3y7naa.re.qweatherapi.com', 'string', 1, '开发者apihost');
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
-- 修改自定义TTS接口请求定义
|
||||||
|
update `ai_model_provider` set `fields` =
|
||||||
|
'[{"key":"url","label":"服务地址","type":"string"},{"key":"method","label":"请求方式","type":"string"},{"key":"params","label":"请求参数","type":"dict","dict_name":"params"},{"key":"headers","label":"请求头","type":"dict","dict_name":"headers"},{"key":"format","label":"音频格式","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"}]'
|
||||||
|
where `id` = 'SYSTEM_TTS_custom';
|
||||||
|
|
||||||
|
-- 修改自定义TTS配置说明
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = NULL,
|
||||||
|
`remark` = '自定义TTS配置说明:
|
||||||
|
1. 自定义的TTS接口服务,请求参数可自定义,可接入众多TTS服务
|
||||||
|
2. 以本地部署的KokoroTTS为例
|
||||||
|
3. 如果只有cpu运行:docker run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu:latest
|
||||||
|
4. 如果只有gpu运行:docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest
|
||||||
|
配置说明:
|
||||||
|
1. 在params中配置请求参数,使用JSON格式
|
||||||
|
例如KokoroTTS:{ "input": "{prompt_text}", "speed": 1, "voice": "zm_yunxi", "stream": true, "download_format": "mp3", "response_format": "mp3", "return_download_link": true }
|
||||||
|
2. 在headers中配置请求头
|
||||||
|
3. 设置返回音频格式' WHERE `id` = 'TTS_CustomTTS';
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
-- 添加手机短信注册功能的需要的参数
|
||||||
|
delete from sys_params where id in (108, 109, 110, 111, 112, 113, 114, 115);
|
||||||
|
delete from sys_params where id in (610, 611, 612, 613);
|
||||||
|
INSERT INTO sys_params
|
||||||
|
(id, param_code, param_value, value_type, param_type, remark, creator, create_date, updater, update_date)
|
||||||
|
VALUES
|
||||||
|
(108, 'server.name', 'xiaozhi-esp32-server', 'string', 1, '系统名称', NULL, NULL, NULL, NULL),
|
||||||
|
(109, 'server.beian_icp_num', 'null', 'string', 1, 'icp备案号,填写null则不设置', NULL, NULL, NULL, NULL),
|
||||||
|
(110, 'server.beian_ga_num', 'null', 'string', 1, '公安备案号,填写null则不设置', NULL, NULL, NULL, NULL),
|
||||||
|
(111, 'server.enable_mobile_register', 'false', 'boolean', 1, '是否开启手机注册', NULL, NULL, NULL, NULL),
|
||||||
|
(112, 'server.sms_max_send_count', '10', 'number', 1, '单号码单日最大短信发送条数', NULL, NULL, NULL, NULL),
|
||||||
|
(610, 'aliyun.sms.access_key_id', '', 'string', 1, '阿里云平台access_key', NULL, NULL, NULL, NULL),
|
||||||
|
(611, 'aliyun.sms.access_key_secret', '', 'string', 1, '阿里云平台access_key_secret', NULL, NULL, NULL, NULL),
|
||||||
|
(612, 'aliyun.sms.sign_name', '', 'string', 1, '阿里云短信签名', NULL, NULL, NULL, NULL),
|
||||||
|
(613, 'aliyun.sms.sms_code_template_code', '', 'string', 1, '阿里云短信模板', NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
update sys_params set remark = '是否允许管理员以外的人注册' where param_code = 'server.allow_user_register';
|
||||||
|
|
||||||
|
-- 增加手机区域字典
|
||||||
|
-- 插入固件类型字典类型
|
||||||
|
delete from `sys_dict_type` where `id` = 102;
|
||||||
|
INSERT INTO `sys_dict_type` (`id`, `dict_type`, `dict_name`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
|
||||||
|
(102, 'MOBILE_AREA', '手机区域', '手机区域字典', 0, 1, NOW(), 1, NOW());
|
||||||
|
|
||||||
|
-- 插入固件类型字典数据
|
||||||
|
delete from `sys_dict_data` where `dict_type_id` = 102;
|
||||||
|
INSERT INTO `sys_dict_data` (`id`, `dict_type_id`, `dict_label`, `dict_value`, `remark`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
|
||||||
|
(102001, 102, '中国大陆', '+86', '中国大陆', 1, 1, NOW(), 1, NOW()),
|
||||||
|
(102002, 102, '中国香港', '+852', '中国香港', 2, 1, NOW(), 1, NOW()),
|
||||||
|
(102003, 102, '中国澳门', '+853', '中国澳门', 3, 1, NOW(), 1, NOW()),
|
||||||
|
(102004, 102, '中国台湾', '+886', '中国台湾', 4, 1, NOW(), 1, NOW()),
|
||||||
|
(102005, 102, '美国/加拿大', '+1', '美国/加拿大', 5, 1, NOW(), 1, NOW()),
|
||||||
|
(102006, 102, '英国', '+44', '英国', 6, 1, NOW(), 1, NOW()),
|
||||||
|
(102007, 102, '法国', '+33', '法国', 7, 1, NOW(), 1, NOW()),
|
||||||
|
(102008, 102, '意大利', '+39', '意大利', 8, 1, NOW(), 1, NOW()),
|
||||||
|
(102009, 102, '德国', '+49', '德国', 9, 1, NOW(), 1, NOW()),
|
||||||
|
(102010, 102, '波兰', '+48', '波兰', 10, 1, NOW(), 1, NOW()),
|
||||||
|
(102011, 102, '瑞士', '+41', '瑞士', 11, 1, NOW(), 1, NOW()),
|
||||||
|
(102012, 102, '西班牙', '+34', '西班牙', 12, 1, NOW(), 1, NOW()),
|
||||||
|
(102013, 102, '丹麦', '+45', '丹麦', 13, 1, NOW(), 1, NOW()),
|
||||||
|
(102014, 102, '马来西亚', '+60', '马来西亚', 14, 1, NOW(), 1, NOW()),
|
||||||
|
(102015, 102, '澳大利亚', '+61', '澳大利亚', 15, 1, NOW(), 1, NOW()),
|
||||||
|
(102016, 102, '印度尼西亚', '+62', '印度尼西亚', 16, 1, NOW(), 1, NOW()),
|
||||||
|
(102017, 102, '菲律宾', '+63', '菲律宾', 17, 1, NOW(), 1, NOW()),
|
||||||
|
(102018, 102, '新西兰', '+64', '新西兰', 18, 1, NOW(), 1, NOW()),
|
||||||
|
(102019, 102, '新加坡', '+65', '新加坡', 19, 1, NOW(), 1, NOW()),
|
||||||
|
(102020, 102, '泰国', '+66', '泰国', 20, 1, NOW(), 1, NOW()),
|
||||||
|
(102021, 102, '日本', '+81', '日本', 21, 1, NOW(), 1, NOW()),
|
||||||
|
(102022, 102, '韩国', '+82', '韩国', 22, 1, NOW(), 1, NOW()),
|
||||||
|
(102023, 102, '越南', '+84', '越南', 23, 1, NOW(), 1, NOW()),
|
||||||
|
(102024, 102, '印度', '+91', '印度', 24, 1, NOW(), 1, NOW()),
|
||||||
|
(102025, 102, '巴基斯坦', '+92', '巴基斯坦', 25, 1, NOW(), 1, NOW()),
|
||||||
|
(102026, 102, '尼日利亚', '+234', '尼日利亚', 26, 1, NOW(), 1, NOW()),
|
||||||
|
(102027, 102, '孟加拉国', '+880', '孟加拉国', 27, 1, NOW(), 1, NOW()),
|
||||||
|
(102028, 102, '沙特阿拉伯', '+966', '沙特阿拉伯', 28, 1, NOW(), 1, NOW()),
|
||||||
|
(102029, 102, '阿联酋', '+971', '阿联酋', 29, 1, NOW(), 1, NOW()),
|
||||||
|
(102030, 102, '巴西', '+55', '巴西', 30, 1, NOW(), 1, NOW()),
|
||||||
|
(102031, 102, '墨西哥', '+52', '墨西哥', 31, 1, NOW(), 1, NOW()),
|
||||||
|
(102032, 102, '智利', '+56', '智利', 32, 1, NOW(), 1, NOW()),
|
||||||
|
(102033, 102, '阿根廷', '+54', '阿根廷', 33, 1, NOW(), 1, NOW()),
|
||||||
|
(102034, 102, '埃及', '+20', '埃及', 34, 1, NOW(), 1, NOW()),
|
||||||
|
(102035, 102, '南非', '+27', '南非', 35, 1, NOW(), 1, NOW()),
|
||||||
|
(102036, 102, '肯尼亚', '+254', '肯尼亚', 36, 1, NOW(), 1, NOW()),
|
||||||
|
(102037, 102, '坦桑尼亚', '+255', '坦桑尼亚', 37, 1, NOW(), 1, NOW()),
|
||||||
|
(102038, 102, '哈萨克斯坦', '+7', '哈萨克斯坦', 38, 1, NOW(), 1, NOW());
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- 更新ai_model_provider的fields字段,将type为dict的改为string
|
||||||
|
update ai_model_provider set fields = replace(fields, '"type": "dict"', '"type": "string"') where id not in ('SYSTEM_LLM_fastgpt', 'SYSTEM_TTS_custom');
|
||||||
|
update ai_model_provider set fields = replace(fields, '"type":"dict"', '"type": "string"') where id not in ('SYSTEM_LLM_fastgpt', 'SYSTEM_TTS_custom');
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
-- 本地短期记忆配置可以设置独立的LLM
|
||||||
|
update `ai_model_provider` set fields = '[{"key":"llm","label":"LLM模型","type":"string"}]' where id = 'SYSTEM_Memory_mem_local_short';
|
||||||
|
update `ai_model_config` set config_json = '{\"type\": \"mem_local_short\", \"llm\": \"LLM_ChatGLMLLM\"}' where id = 'Memory_mem_local_short';
|
||||||
|
|
||||||
|
-- 增加火山双流式TTS供应器和模型配置
|
||||||
|
delete from `ai_model_provider` where id = 'SYSTEM_TTS_HSDSTTS';
|
||||||
|
INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
|
||||||
|
('SYSTEM_TTS_HSDSTTS', 'TTS', 'huoshan_double_stream', '火山双流式语音合成', '[{"key":"ws_url","label":"WebSocket地址","type":"string"},{"key":"appid","label":"应用ID","type":"string"},{"key":"access_token","label":"访问令牌","type":"string"},{"key":"resource_id","label":"资源ID","type":"string"},{"key":"speaker","label":"默认音色","type":"string"}]', 13, 1, NOW(), 1, NOW());
|
||||||
|
|
||||||
|
delete from `ai_model_config` where id = 'TTS_HuoshanDoubleStreamTTS';
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('TTS_HuoshanDoubleStreamTTS', 'TTS', 'HuoshanDoubleStreamTTS', '火山双流式语音合成', 0, 1, '{\"type\": \"huoshan_double_stream\", \"ws_url\": \"wss://openspeech.bytedance.com/api/v3/tts/bidirection\", \"appid\": \"你的火山引擎语音合成服务appid\", \"access_token\": \"你的火山引擎语音合成服务access_token\", \"resource_id\": \"volc.service_type.10029\", \"speaker\": \"zh_female_wanwanxiaohe_moon_bigtts\"}', NULL, NULL, 16, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
-- 火山双流式TT模型配置说明文档
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://console.volcengine.com/speech/service/10007',
|
||||||
|
`remark` = '火山引擎语音合成服务配置说明:
|
||||||
|
1. 访问 https://www.volcengine.com/ 注册并开通火山引擎账号
|
||||||
|
2. 访问 https://console.volcengine.com/speech/service/10007 开通语音合成大模型,购买音色
|
||||||
|
3. 在页面底部获取appid和access_token
|
||||||
|
5. 资源ID固定为:volc.service_type.10029(大模型语音合成及混音)
|
||||||
|
6. 填入配置文件中' WHERE `id` = 'TTS_HuoshanDoubleStreamTTS';
|
||||||
|
|
||||||
|
|
||||||
|
-- 添加火山双流式TTS音色
|
||||||
|
delete from `ai_tts_voice` where tts_model_id = 'TTS_HuoshanDoubleStreamTTS';
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0001', 'TTS_HuoshanDoubleStreamTTS', '爽快思思/Skye', 'zh_female_shuangkuaisisi_moon_bigtts', '中文、英文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Skye.mp3', NULL, 1, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0002', 'TTS_HuoshanDoubleStreamTTS', '温暖阿虎/Alvin', 'zh_male_wennuanahu_moon_bigtts', '中文、英文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Alvin.mp3', NULL, 2, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0003', 'TTS_HuoshanDoubleStreamTTS', '少年梓辛/Brayan', 'zh_male_shaonianzixin_moon_bigtts', '中文、英文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Brayan.mp3', NULL, 3, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0004', 'TTS_HuoshanDoubleStreamTTS', '邻家女孩', 'zh_female_linjianvhai_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E9%82%BB%E5%AE%B6%E5%A5%B3%E5%AD%A9.mp3', NULL, 4, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0005', 'TTS_HuoshanDoubleStreamTTS', '渊博小叔', 'zh_male_yuanboxiaoshu_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%B8%8A%E5%8D%9A%E5%B0%8F%E5%8F%94.mp3', NULL, 5, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0006', 'TTS_HuoshanDoubleStreamTTS', '阳光青年', 'zh_male_yangguangqingnian_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E9%98%B3%E5%85%89%E9%9D%92%E5%B9%B4.mp3', NULL, 6, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0007', 'TTS_HuoshanDoubleStreamTTS', '京腔侃爷/Harmony', 'zh_male_jingqiangkanye_moon_bigtts', '中文、英文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Harmony.mp3', NULL, 7, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0008', 'TTS_HuoshanDoubleStreamTTS', '湾湾小何', 'zh_female_wanwanxiaohe_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%B9%BE%E6%B9%BE%E5%B0%8F%E4%BD%95.mp3', NULL, 8, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0009', 'TTS_HuoshanDoubleStreamTTS', '湾区大叔', 'zh_female_wanqudashu_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%B9%BE%E5%8C%BA%E5%A4%A7%E5%8F%94.mp3', NULL, 9, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0010', 'TTS_HuoshanDoubleStreamTTS', '呆萌川妹', 'zh_female_daimengchuanmei_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%91%86%E8%90%8C%E5%B7%9D%E5%A6%B9.mp3', NULL, 10, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0011', 'TTS_HuoshanDoubleStreamTTS', '广州德哥', 'zh_male_guozhoudege_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%B9%BF%E5%B7%9E%E5%BE%B7%E5%93%A5.mp3', NULL, 11, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0012', 'TTS_HuoshanDoubleStreamTTS', '北京小爷', 'zh_male_beijingxiaoye_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%8C%97%E4%BA%AC%E5%B0%8F%E7%88%B7.mp3', NULL, 12, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0013', 'TTS_HuoshanDoubleStreamTTS', '浩宇小哥', 'zh_male_haoyuxiaoge_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%B5%A9%E5%AE%87%E5%B0%8F%E5%93%A5.mp3', NULL, 13, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0014', 'TTS_HuoshanDoubleStreamTTS', '广西远舟', 'zh_male_guangxiyuanzhou_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%B9%BF%E8%A5%BF%E8%BF%9C%E8%88%9F.mp3', NULL, 14, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0015', 'TTS_HuoshanDoubleStreamTTS', '妹坨洁儿', 'zh_female_meituojieer_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%A6%B9%E5%9D%A8%E6%B4%81%E5%84%BF.mp3', NULL, 15, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0016', 'TTS_HuoshanDoubleStreamTTS', '豫州子轩', 'zh_male_yuzhouzixuan_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E8%B1%AB%E5%B7%9E%E5%AD%90%E8%BD%A9.mp3', NULL, 16, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0017', 'TTS_HuoshanDoubleStreamTTS', '高冷御姐', 'zh_female_gaolengyujie_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E9%AB%98%E5%86%B7%E5%BE%A1%E5%A7%90.mp3', NULL, 17, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0018', 'TTS_HuoshanDoubleStreamTTS', '傲娇霸总', 'zh_male_aojiaobazong_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E5%82%B2%E5%A8%87%E9%9C%B8%E6%80%BB.mp3', NULL, 18, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0019', 'TTS_HuoshanDoubleStreamTTS', '魅力女友', 'zh_female_meilinvyou_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E9%AD%85%E5%8A%9B%E5%A5%B3%E5%8F%8B.mp3', NULL, 19, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0020', 'TTS_HuoshanDoubleStreamTTS', '深夜播客', 'zh_male_shenyeboke_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%B7%B1%E5%A4%9C%E6%92%AD%E5%AE%A2.mp3', NULL, 20, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0021', 'TTS_HuoshanDoubleStreamTTS', '柔美女友', 'zh_female_sajiaonvyou_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%9F%94%E7%BE%8E%E5%A5%B3%E5%8F%8B.mp3', NULL, 21, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0022', 'TTS_HuoshanDoubleStreamTTS', '撒娇学妹', 'zh_female_yuanqinvyou_moon_bigtts', '中文', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%92%92%E5%A8%87%E5%AD%A6%E5%A6%B9.mp3', NULL, 22, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0023', 'TTS_HuoshanDoubleStreamTTS', 'かずね(和音)', 'multi_male_jingqiangkanye_moon_bigtts', '日语、西语', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Javier.wav', NULL, 23, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0024', 'TTS_HuoshanDoubleStreamTTS', 'はるこ(晴子)', 'multi_female_shuangkuaisisi_moon_bigtts', '日语、西语', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Esmeralda.mp3', NULL, 24, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0025', 'TTS_HuoshanDoubleStreamTTS', 'あけみ(朱美)', 'multi_female_gaolengyujie_moon_bigtts', '日语', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/%E6%9C%B1%E7%BE%8E.mp3', NULL, 25, NULL, NULL, NULL, NULL);
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_HuoshanDoubleStreamTTS_0026', 'TTS_HuoshanDoubleStreamTTS', 'ひろし(広志)', 'multi_male_wanqudashu_moon_bigtts', '日语、西语', 'https://lf3-static.bytednsdoc.com/obj/eden-cn/lm_hz_ihsph/ljhwZthlaukjlkulzlp/portal/bigtts/Roberto.wav', NULL, 26, NULL, NULL, NULL, NULL);
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
-- VLLM模型供应器
|
||||||
|
delete from `ai_model_provider` where id = 'SYSTEM_VLLM_openai';
|
||||||
|
INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
|
||||||
|
('SYSTEM_VLLM_openai', 'VLLM', 'openai', 'OpenAI接口', '[{"key":"base_url","label":"基础URL","type":"string"},{"key":"model_name","label":"模型名称","type":"string"},{"key":"api_key","label":"API密钥","type":"string"}]', 9, 1, NOW(), 1, NOW());
|
||||||
|
|
||||||
|
-- VLLM模型配置
|
||||||
|
delete from `ai_model_config` where id = 'VLLM_ChatGLMVLLM';
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('VLLM_ChatGLMVLLM', 'VLLM', 'ChatGLMVLLM', '智谱视觉AI', 1, 1, '{\"type\": \"openai\", \"model_name\": \"glm-4v-flash\", \"base_url\": \"https://open.bigmodel.cn/api/paas/v4/\", \"api_key\": \"你的api_key\"}', NULL, NULL, 1, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
-- 更新文档
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://bigmodel.cn/usercenter/proj-mgmt/apikeys',
|
||||||
|
`remark` = '智谱视觉AI配置说明:
|
||||||
|
1. 访问 https://bigmodel.cn/usercenter/proj-mgmt/apikeys
|
||||||
|
2. 注册并获取API密钥
|
||||||
|
3. 填入配置文件中' WHERE `id` = 'VLLM_ChatGLMVLLM';
|
||||||
|
|
||||||
|
|
||||||
|
-- 添加参数
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (113, 'server.http_port', '8003', 'number', 1, 'http服务的端口,用于启动视觉分析接口');
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (114, 'server.vision_explain', 'null', 'string', 1, '视觉分析接口地址,用于下发到设备,多个用;分隔');
|
||||||
|
|
||||||
|
-- 智能体表增加VLLM模型配置
|
||||||
|
ALTER TABLE `ai_agent`
|
||||||
|
ADD COLUMN `vllm_model_id` varchar(32) NULL DEFAULT 'VLLM_ChatGLMVLLM' COMMENT '视觉模型标识' AFTER `llm_model_id`;
|
||||||
|
|
||||||
|
-- 智能体模版表增加VLLM模型配置
|
||||||
|
ALTER TABLE `ai_agent_template`
|
||||||
|
ADD COLUMN `vllm_model_id` varchar(32) NULL DEFAULT 'VLLM_ChatGLMVLLM' COMMENT '视觉模型标识' AFTER `llm_model_id`;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-- VLLM模型供应器
|
||||||
|
delete from `ai_model_provider` where id = 'SYSTEM_ASR_DoubaoStreamASR';
|
||||||
|
INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES
|
||||||
|
('SYSTEM_ASR_DoubaoStreamASR', 'ASR', 'doubao_stream', '火山引擎语音识别(流式)', '[{"key":"appid","label":"应用ID","type":"string"},{"key":"access_token","label":"访问令牌","type":"string"},{"key":"cluster","label":"集群","type":"string"},{"key":"boosting_table_name","label":"热词文件名称","type":"string"},{"key":"correct_table_name","label":"替换词文件名称","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"}]', 3, 1, NOW(), 1, NOW());
|
||||||
|
|
||||||
|
|
||||||
|
-- VLLM模型配置
|
||||||
|
delete from `ai_model_config` where id = 'ASR_DoubaoStreamASR';
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('ASR_DoubaoStreamASR', 'ASR', 'DoubaoStreamASR', '豆包语音识别(流式)', 0, 1, '{\"type\": \"doubao_stream\", \"appid\": \"\", \"access_token\": \"\", \"cluster\": \"volcengine_input_common\", \"output_dir\": \"tmp/\"}', NULL, NULL, 3, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
-- 更新豆包ASR配置说明
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://console.volcengine.com/speech/app',
|
||||||
|
`remark` = '豆包ASR配置说明:
|
||||||
|
1. 豆包ASR和豆包(流式)ASR的区别是:豆包ASR是按次收费,豆包(流式)ASR是按时收费
|
||||||
|
2. 一般来说按次收费的更便宜,但是豆包(流式)ASR使用了大模型技术,效果更好
|
||||||
|
3. 需要在火山引擎控制台创建应用并获取appid和access_token
|
||||||
|
4. 支持中文语音识别
|
||||||
|
5. 需要网络连接
|
||||||
|
6. 输出文件保存在tmp/目录
|
||||||
|
申请步骤:
|
||||||
|
1. 访问 https://console.volcengine.com/speech/app
|
||||||
|
2. 创建新应用
|
||||||
|
3. 获取appid和access_token
|
||||||
|
4. 填入配置文件中
|
||||||
|
如需设置热词,请参考:https://www.volcengine.com/docs/6561/155738
|
||||||
|
' WHERE `id` = 'ASR_DoubaoASR';
|
||||||
|
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://console.volcengine.com/speech/app',
|
||||||
|
`remark` = '豆包ASR配置说明:
|
||||||
|
1. 豆包ASR和豆包(流式)ASR的区别是:豆包ASR是按次收费,豆包(流式)ASR是按时收费
|
||||||
|
2. 一般来说按次收费的更便宜,但是豆包(流式)ASR使用了大模型技术,效果更好
|
||||||
|
3. 需要在火山引擎控制台创建应用并获取appid和access_token
|
||||||
|
4. 支持中文语音识别
|
||||||
|
5. 需要网络连接
|
||||||
|
6. 输出文件保存在tmp/目录
|
||||||
|
申请步骤:
|
||||||
|
1. 访问 https://console.volcengine.com/speech/app
|
||||||
|
2. 创建新应用
|
||||||
|
3. 获取appid和access_token
|
||||||
|
4. 填入配置文件中
|
||||||
|
如需设置热词,请参考:https://www.volcengine.com/docs/6561/155738
|
||||||
|
' WHERE `id` = 'ASR_DoubaoStreamASR';
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
-- VLLM模型配置
|
||||||
|
delete from `ai_model_config` where id = 'VLLM_QwenVLVLLM';
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('VLLM_QwenVLVLLM', 'VLLM', 'QwenVLVLLM', '千问视觉模型', 0, 1, '{\"type\": \"openai\", \"model_name\": \"qwen2.5-vl-3b-instruct\", \"base_url\": \"https://dashscope.aliyuncs.com/compatible-mode/v1\", \"api_key\": \"你的api_key\"}', NULL, NULL, 2, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
-- 更新文档
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://bailian.console.aliyun.com/?tab=api#/api/?type=model&url=https%3A%2F%2Fhelp.aliyun.com%2Fdocument_detail%2F2845564.html&renderType=iframe',
|
||||||
|
`remark` = '千问视觉模型配置说明:
|
||||||
|
1. 访问 https://bailian.console.aliyun.com/?tab=model#/api-key
|
||||||
|
2. 注册并获取API密钥
|
||||||
|
3. 填入配置文件中' WHERE `id` = 'VLLM_QwenVLVLLM';
|
||||||
|
|
||||||
|
-- 删除参数,这两个参数已挪至python配置文件
|
||||||
|
delete from `sys_params` where id in (113,114);
|
||||||
@@ -113,4 +113,81 @@ databaseChangeLog:
|
|||||||
changes:
|
changes:
|
||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202505091409.sql
|
path: classpath:db/changelog/202505091409.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505091555
|
||||||
|
author: whosmyqueen
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505091555.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505111914
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505111914.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505122348
|
||||||
|
author: ljwwd2
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505122348.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505142037
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505142037.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505182234
|
||||||
|
author: amen
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505182234.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505201744
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505201744.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505151451
|
||||||
|
author: hsoftxl
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505151451.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505271414
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505271414.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202506010920
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202506010920.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202506031639
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202506031639.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202506032232
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202506032232.sql
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
10005=\u8D26\u53F7\u5DF2\u88AB\u505C\u7528
|
10005=\u8D26\u53F7\u5DF2\u88AB\u505C\u7528
|
||||||
10006=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A
|
10006=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A
|
||||||
10007=\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E
|
10007=\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E
|
||||||
|
10008=\u624B\u673A\u53F7\u7801\u4E0D\u53EF\u4EE5\u4E3A\u7A7A
|
||||||
10009=\u539F\u5BC6\u7801\u4E0D\u6B63\u786E
|
10009=\u539F\u5BC6\u7801\u4E0D\u6B63\u786E
|
||||||
10010=\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E,\u60A8\u8FD8\u6709\u53EF\u4EE5\u5C1D\u8BD5{0}\u6B21
|
10010=\u8D26\u53F7\u6216\u5BC6\u7801\u4E0D\u6B63\u786E,\u60A8\u8FD8\u6709\u53EF\u4EE5\u5C1D\u8BD5{0}\u6B21
|
||||||
10011=\u4E0A\u7EA7\u90E8\u95E8\u9009\u62E9\u9519\u8BEF
|
10011=\u4E0A\u7EA7\u90E8\u95E8\u9009\u62E9\u9519\u8BEF
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
redis.call('FLUSHALL')
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
local value = redis.call('GET', KEYS[1])
|
||||||
|
-- value 如果为空着设置值
|
||||||
|
if not value then
|
||||||
|
local result = redis.call('SET', KEYS[1], ARGV[1])
|
||||||
|
-- 检查 ARGV[2] 是否存在且大于 0
|
||||||
|
local expireTime = tonumber(ARGV[2])
|
||||||
|
if expireTime and expireTime > 0 then
|
||||||
|
redis.call('EXPIRE', KEYS[1], expireTime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return value
|
||||||
@@ -28,11 +28,17 @@
|
|||||||
SELECT audio_id
|
SELECT audio_id
|
||||||
FROM ai_agent_chat_history
|
FROM ai_agent_chat_history
|
||||||
WHERE agent_id = #{agentId}
|
WHERE agent_id = #{agentId}
|
||||||
);
|
)
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<update id="deleteAudioIdByAgentId">
|
||||||
|
UPDATE ai_agent_chat_history
|
||||||
|
SET audio_id = NULL
|
||||||
|
WHERE agent_id = #{agentId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteHistoryByAgentId">
|
<delete id="deleteHistoryByAgentId">
|
||||||
DELETE FROM ai_agent_chat_history
|
DELETE FROM ai_agent_chat_history
|
||||||
WHERE agent_id = #{agentId};
|
WHERE agent_id = #{agentId}
|
||||||
</delete>
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||