mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 23:53:55 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
396de72c5d | ||
|
|
9932d60dee | ||
|
|
27df97d710 | ||
|
|
a25b7b9b3f | ||
|
|
8a005ffb00 | ||
|
|
80ffa7a577 | ||
|
|
ca8f9a7e4a | ||
|
|
8d19d78297 | ||
|
|
483e5eb85a | ||
|
|
a4b4f491d2 | ||
|
|
08093f509a | ||
|
|
9a96223d12 | ||
|
|
0c2b194444 | ||
|
|
a06055168f | ||
|
|
e04546a9ae | ||
|
|
f6da1a045d | ||
|
|
acd386bb09 | ||
|
|
45225c0ce1 | ||
|
|
0bd884d309 | ||
|
|
aea2ae8d79 | ||
|
|
99ec5ab161 | ||
|
|
4431e7470f | ||
|
|
ed775405c6 | ||
|
|
4aefbe5aa8 | ||
|
|
786c467464 | ||
|
|
50182ef940 | ||
|
|
bf3aa2df09 | ||
|
|
0b744a2599 | ||
|
|
a75b8b40e2 | ||
|
|
2e23c08608 | ||
|
|
178f45ee26 | ||
|
|
7b16edc99c | ||
|
|
f3738a1630 | ||
|
|
34fa65132d | ||
|
|
c796af7d07 | ||
|
|
b7251e2be2 | ||
|
|
6efede79c7 | ||
|
|
e58da80f8e | ||
|
|
bd556c33a0 | ||
|
|
878809ecb4 | ||
|
|
ea4966f494 | ||
|
|
f5d9b478d5 | ||
|
|
3d97fab16d | ||
|
|
2c1fc30bfb | ||
|
|
c7dec8045e | ||
|
|
5d7d12415c | ||
|
|
08e57936fc | ||
|
|
7d474e17fa | ||
|
|
d3571942d7 | ||
|
|
66f5f8ab12 | ||
|
|
74ce9f7a86 | ||
|
|
5b2957e7eb | ||
|
|
40eb4ea4ec | ||
|
|
0f41039b99 | ||
|
|
8f76db9e41 | ||
|
|
fc922e996c | ||
|
|
6142d325c8 | ||
|
|
aa21aa686d | ||
|
|
ec2719a572 | ||
|
|
a466126d63 | ||
|
|
568f322a25 | ||
|
|
1b64959e2c |
+4
-1
@@ -141,8 +141,8 @@ music/
|
|||||||
# Cython debug symbols
|
# Cython debug symbols
|
||||||
cython_debug/
|
cython_debug/
|
||||||
*.iml
|
*.iml
|
||||||
model.pt
|
|
||||||
tmp
|
tmp
|
||||||
|
.history
|
||||||
.DS_Store
|
.DS_Store
|
||||||
main/xiaozhi-server/data
|
main/xiaozhi-server/data
|
||||||
main/manager-web/node_modules
|
main/manager-web/node_modules
|
||||||
@@ -151,3 +151,6 @@ main/manager-web/node_modules
|
|||||||
.private_config.yaml
|
.private_config.yaml
|
||||||
.env.development
|
.env.development
|
||||||
|
|
||||||
|
# model files
|
||||||
|
main/xiaozhi-server/models/SenseVoiceSmall/model.pt
|
||||||
|
main/xiaozhi-server/models/sherpa-onnx*
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ server:
|
|||||||
| TTS | CosyVoiceSiliconflow | 接口调用 | 消耗 token | 需申请硅基流动 API 密钥;输出格式为 wav |
|
| TTS | CosyVoiceSiliconflow | 接口调用 | 消耗 token | 需申请硅基流动 API 密钥;输出格式为 wav |
|
||||||
| TTS | TTS302AI | 接口调用 | 消耗 token | [点击创建密钥](https://dash.302.ai/apis/list) |
|
| TTS | TTS302AI | 接口调用 | 消耗 token | [点击创建密钥](https://dash.302.ai/apis/list) |
|
||||||
| TTS | CozeCnTTS | 接口调用 | 消耗 token | 需提供 Coze API key;输出格式为 wav |
|
| TTS | CozeCnTTS | 接口调用 | 消耗 token | 需提供 Coze API key;输出格式为 wav |
|
||||||
|
| TTS | GizwitsTTS | 接口调用 | 消耗 token | [点击创建密钥](https://agentrouter.gizwitsapi.com) |
|
||||||
| TTS | ACGNTTS | 接口调用 | 消耗 token | [联系网站管理员购买密钥](www.ttson.cn) |
|
| TTS | ACGNTTS | 接口调用 | 消耗 token | [联系网站管理员购买密钥](www.ttson.cn) |
|
||||||
| TTS | OpenAITTS | 接口调用 | 消耗 token | 境外使用,境外购买 |
|
| TTS | OpenAITTS | 接口调用 | 消耗 token | 境外使用,境外购买 |
|
||||||
| TTS | FishSpeech | 接口调用 | 免费/自定义 | 本地启动 TTS 服务;启动方法见配置文件内说明 |
|
| TTS | FishSpeech | 接口调用 | 免费/自定义 | 本地启动 TTS 服务;启动方法见配置文件内说明 |
|
||||||
@@ -223,8 +224,10 @@ server:
|
|||||||
| 类型 | 平台名称 | 使用方式 | 收费模式 | 备注 |
|
| 类型 | 平台名称 | 使用方式 | 收费模式 | 备注 |
|
||||||
|:---:|:---------:|:----:|:----:|:--:|
|
|:---:|:---------:|:----:|:----:|:--:|
|
||||||
| ASR | FunASR | 本地使用 | 免费 | |
|
| ASR | FunASR | 本地使用 | 免费 | |
|
||||||
|
| ASR | SherpaASR | 本地使用 | 免费 | |
|
||||||
| ASR | DoubaoASR | 接口调用 | 收费 | |
|
| ASR | DoubaoASR | 接口调用 | 收费 | |
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Memory 记忆存储
|
### Memory 记忆存储
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ In fact, any LLM that supports OpenAI API calls can be integrated.
|
|||||||
| Type | Platform Name | Usage Method | Pricing Model | Remarks |
|
| Type | Platform Name | Usage Method | Pricing Model | Remarks |
|
||||||
|:----:|:-------------------:|:------------:|:-------------:|:-------:|
|
|:----:|:-------------------:|:------------:|:-------------:|:-------:|
|
||||||
| ASR | FunASR | Local | Free | |
|
| ASR | FunASR | Local | Free | |
|
||||||
|
| ASR | SherpaASR | Local | Free | |
|
||||||
| ASR | DoubaoASR | API call | Paid | |
|
| ASR | DoubaoASR | API call | Paid | |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
package xiaozhi.common.aspect;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import xiaozhi.common.annotation.DataFilter;
|
|
||||||
import xiaozhi.common.constant.Constant;
|
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
|
||||||
import xiaozhi.common.exception.RenException;
|
|
||||||
import xiaozhi.common.interceptor.DataScope;
|
|
||||||
import xiaozhi.common.user.UserDetail;
|
|
||||||
import xiaozhi.modules.security.user.SecurityUser;
|
|
||||||
import xiaozhi.modules.sys.enums.SuperAdminEnum;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据过滤,切面处理类
|
|
||||||
* Copyright (c) 人人开源 All rights reserved.
|
|
||||||
* Website: https://www.renren.io
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Component
|
|
||||||
public class DataFilterAspect {
|
|
||||||
|
|
||||||
@Pointcut("@annotation(xiaozhi.common.annotation.DataFilter)")
|
|
||||||
public void dataFilterCut() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("dataFilterCut()")
|
|
||||||
public void dataFilter(JoinPoint point) {
|
|
||||||
Object params = point.getArgs()[0];
|
|
||||||
if (params != null && params instanceof Map) {
|
|
||||||
UserDetail user = SecurityUser.getUser();
|
|
||||||
|
|
||||||
//如果是超级管理员,则不进行数据过滤
|
|
||||||
if (user.getSuperAdmin() == SuperAdminEnum.YES.value()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
//否则进行数据过滤
|
|
||||||
Map map = (Map) params;
|
|
||||||
String sqlFilter = getSqlFilter(user, point);
|
|
||||||
map.put(Constant.SQL_FILTER, new DataScope(sqlFilter));
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RenException(ErrorCode.DATA_SCOPE_PARAMS_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取数据过滤的SQL
|
|
||||||
*/
|
|
||||||
private String getSqlFilter(UserDetail user, JoinPoint point) throws Exception {
|
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
|
||||||
Method method = point.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes());
|
|
||||||
DataFilter dataFilter = method.getAnnotation(DataFilter.class);
|
|
||||||
|
|
||||||
//获取表的别名
|
|
||||||
String tableAlias = dataFilter.tableAlias();
|
|
||||||
if (StringUtils.isNotBlank(tableAlias)) {
|
|
||||||
tableAlias += ".";
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sqlFilter = new StringBuilder();
|
|
||||||
sqlFilter.append(" (");
|
|
||||||
|
|
||||||
//部门ID列表
|
|
||||||
List<Long> deptIdList = user.getDeptIdList();
|
|
||||||
if (CollUtil.isNotEmpty(deptIdList)) {
|
|
||||||
sqlFilter.append(tableAlias).append(dataFilter.deptId());
|
|
||||||
|
|
||||||
sqlFilter.append(" in(").append(StringUtils.join(deptIdList, ",")).append(")");
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询本人数据
|
|
||||||
if (CollUtil.isNotEmpty(deptIdList)) {
|
|
||||||
sqlFilter.append(" or ");
|
|
||||||
}
|
|
||||||
sqlFilter.append(tableAlias).append(dataFilter.userId()).append("=").append(user.getId());
|
|
||||||
|
|
||||||
sqlFilter.append(")");
|
|
||||||
|
|
||||||
return sqlFilter.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -73,10 +73,6 @@ public interface Constant {
|
|||||||
* 排序方式
|
* 排序方式
|
||||||
*/
|
*/
|
||||||
String ORDER = "order";
|
String ORDER = "order";
|
||||||
/**
|
|
||||||
* token header
|
|
||||||
*/
|
|
||||||
String TOKEN_HEADER = "token";
|
|
||||||
|
|
||||||
String AUTHORIZATION = "Authorization";
|
String AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
|
|||||||
//创建时间
|
//创建时间
|
||||||
strictInsertFill(metaObject, CREATE_DATE, Date.class, date);
|
strictInsertFill(metaObject, CREATE_DATE, Date.class, date);
|
||||||
|
|
||||||
//创建者所属部门
|
|
||||||
strictInsertFill(metaObject, DEPT_ID, Long.class, user.getDeptId());
|
|
||||||
|
|
||||||
//更新者
|
//更新者
|
||||||
strictInsertFill(metaObject, UPDATER, Long.class, user.getId());
|
strictInsertFill(metaObject, UPDATER, Long.class, user.getId());
|
||||||
//更新时间
|
//更新时间
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package xiaozhi.common.user;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录用户信息
|
* 登录用户信息
|
||||||
@@ -14,19 +13,7 @@ import java.util.List;
|
|||||||
public class UserDetail implements Serializable {
|
public class UserDetail implements Serializable {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String username;
|
private String username;
|
||||||
private String realName;
|
|
||||||
private String headUrl;
|
|
||||||
private Integer gender;
|
|
||||||
private String email;
|
|
||||||
private String mobile;
|
|
||||||
private Long deptId;
|
|
||||||
private String password;
|
|
||||||
private Integer status;
|
|
||||||
private Integer superAdmin;
|
private Integer superAdmin;
|
||||||
private String token;
|
private String token;
|
||||||
/**
|
private Integer status;
|
||||||
* 部门数据权限
|
|
||||||
*/
|
|
||||||
private List<Long> deptIdList;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package xiaozhi.common.utils;
|
package xiaozhi.common.utils;
|
||||||
|
|
||||||
import xiaozhi.common.constant.Constant;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -8,6 +7,8 @@ import org.springframework.util.DigestUtils;
|
|||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
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;
|
||||||
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
|
import xiaozhi.common.exception.RenException;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@@ -30,13 +31,14 @@ public class HttpContextUtils {
|
|||||||
return ((ServletRequestAttributes) requestAttributes).getRequest();
|
return ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getToken() {
|
public static String getToken(String authorization) {
|
||||||
HttpServletRequest httpRequest = getHttpServletRequest();
|
String token;
|
||||||
String token = httpRequest.getHeader(Constant.TOKEN_HEADER);
|
if (StringUtils.isBlank(authorization) && authorization.contains("Bearer ")) {
|
||||||
|
throw new RenException(ErrorCode.UNAUTHORIZED);
|
||||||
//如果header中不存在token,则从参数中获取token
|
}
|
||||||
|
token = authorization.replace("Bearer ", "");
|
||||||
if (StringUtils.isBlank(token)) {
|
if (StringUtils.isBlank(token)) {
|
||||||
token = httpRequest.getParameter(Constant.TOKEN_HEADER);
|
throw new RenException(ErrorCode.TOKEN_NOT_EMPTY);
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
package xiaozhi.common.utils;
|
package xiaozhi.common.utils;
|
||||||
|
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
|
||||||
import xiaozhi.common.page.PageData;
|
|
||||||
import xiaozhi.modules.security.user.SecurityUser;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 响应数据
|
* 响应数据
|
||||||
@@ -42,9 +36,6 @@ public class Result<T> implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean success() {
|
|
||||||
return code == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Result<T> error() {
|
public Result<T> error() {
|
||||||
this.code = ErrorCode.INTERNAL_SERVER_ERROR;
|
this.code = ErrorCode.INTERNAL_SERVER_ERROR;
|
||||||
|
|||||||
+1
-2
@@ -25,11 +25,10 @@ import xiaozhi.modules.security.user.SecurityUser;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Tag(name = "设备管理")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/device")
|
@RequestMapping("/device")
|
||||||
@Tag(name = "设备管理")
|
|
||||||
|
|
||||||
public class DeviceController {
|
public class DeviceController {
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ public class ShiroConfig {
|
|||||||
filterMap.put("/v3/api-docs/**", "anon");
|
filterMap.put("/v3/api-docs/**", "anon");
|
||||||
filterMap.put("/doc.html", "anon");
|
filterMap.put("/doc.html", "anon");
|
||||||
filterMap.put("/favicon.ico", "anon");
|
filterMap.put("/favicon.ico", "anon");
|
||||||
filterMap.put("/user/**", "anon");
|
filterMap.put("/user/captcha", "anon");
|
||||||
|
filterMap.put("/user/login", "anon");
|
||||||
|
filterMap.put("/user/register", "anon");
|
||||||
filterMap.put("/**", "oauth2");
|
filterMap.put("/**", "oauth2");
|
||||||
shiroFilter.setFilterChainDefinitionMap(filterMap);
|
shiroFilter.setFilterChainDefinitionMap(filterMap);
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -4,20 +4,21 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
import xiaozhi.common.exception.RenException;
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.page.TokenDTO;
|
import xiaozhi.common.page.TokenDTO;
|
||||||
|
import xiaozhi.common.user.UserDetail;
|
||||||
import xiaozhi.common.utils.Result;
|
import xiaozhi.common.utils.Result;
|
||||||
import xiaozhi.common.validator.AssertUtils;
|
import xiaozhi.common.validator.AssertUtils;
|
||||||
import xiaozhi.modules.security.dao.SysUserTokenDao;
|
|
||||||
import xiaozhi.modules.security.dto.LoginDTO;
|
import xiaozhi.modules.security.dto.LoginDTO;
|
||||||
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.sys.dto.PasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
import xiaozhi.modules.sys.service.SysUserService;
|
import xiaozhi.modules.sys.service.SysUserService;
|
||||||
|
|
||||||
@@ -26,7 +27,6 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* 登录控制层
|
* 登录控制层
|
||||||
*/
|
*/
|
||||||
@Tag(name = "登录管理")
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/user")
|
@RequestMapping("/user")
|
||||||
@@ -36,7 +36,6 @@ public class LoginController {
|
|||||||
private final SysUserTokenService sysUserTokenService;
|
private final SysUserTokenService sysUserTokenService;
|
||||||
private final CaptchaService captchaService;
|
private final CaptchaService captchaService;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
|
|
||||||
|
|
||||||
@GetMapping("/captcha")
|
@GetMapping("/captcha")
|
||||||
@Operation(summary = "验证码")
|
@Operation(summary = "验证码")
|
||||||
@@ -79,32 +78,31 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
// 按照用户名获取用户
|
// 按照用户名获取用户
|
||||||
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
||||||
if (userDTO != null){
|
if (userDTO != null) {
|
||||||
throw new RenException("此手机号码已经注册过");
|
throw new RenException("此手机号码已经注册过");
|
||||||
}
|
}
|
||||||
userDTO = new SysUserDTO();
|
userDTO = new SysUserDTO();
|
||||||
userDTO.setUsername(login.getUsername());
|
userDTO.setUsername(login.getUsername());
|
||||||
userDTO.setPassword(login.getPassword());
|
userDTO.setPassword(login.getPassword());
|
||||||
sysUserService.save(userDTO);
|
sysUserService.save(userDTO);
|
||||||
return new Result<Void>();
|
return new Result<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/info")
|
@GetMapping("/info")
|
||||||
@Operation(summary = "用户信息获取")
|
@Operation(summary = "用户信息获取")
|
||||||
public Result<SysUserDTO> info(@RequestHeader("Authorization")String authorization) {
|
public Result<UserDetail> info() {
|
||||||
logger.info("the authorization:{}", authorization);
|
UserDetail user = SecurityUser.getUser();
|
||||||
|
Result<UserDetail> result = new Result<>();
|
||||||
|
result.setData(user);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
String token;
|
@PutMapping("/change-password")
|
||||||
if (StringUtils.isBlank(authorization) && authorization.contains("Bearer ")) {
|
@Operation(summary = "修改用户密码")
|
||||||
throw new RenException(ErrorCode.UNAUTHORIZED);
|
public Result<?> changePassword(@RequestBody PasswordDTO passwordDTO) {
|
||||||
}
|
Long userId = SecurityUser.getUserId();
|
||||||
token = authorization.replace("Bearer ", "");
|
sysUserTokenService.changePassword(userId, passwordDTO);
|
||||||
if (StringUtils.isBlank(token)) {
|
return new Result<>();
|
||||||
throw new RenException(ErrorCode.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
SysUserDTO sysUserDTO = sysUserTokenService.getUserByToken(token);
|
|
||||||
Result result = new Result<SysUserDTO>();
|
|
||||||
return result.ok(sysUserDTO);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@ import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
|
|||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
import xiaozhi.common.exception.RenException;
|
|
||||||
import xiaozhi.common.utils.HttpContextUtils;
|
import xiaozhi.common.utils.HttpContextUtils;
|
||||||
import xiaozhi.common.utils.JsonUtils;
|
import xiaozhi.common.utils.JsonUtils;
|
||||||
import xiaozhi.common.utils.Result;
|
import xiaozhi.common.utils.Result;
|
||||||
@@ -90,21 +89,10 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||||||
* 获取请求的token
|
* 获取请求的token
|
||||||
*/
|
*/
|
||||||
private String getRequestToken(HttpServletRequest httpRequest) {
|
private String getRequestToken(HttpServletRequest httpRequest) {
|
||||||
String token;
|
String token = null;
|
||||||
//从header中获取token
|
//从header中获取token
|
||||||
String authorization = httpRequest.getHeader(Constant.AUTHORIZATION);
|
String authorization = httpRequest.getHeader(Constant.AUTHORIZATION);
|
||||||
if (StringUtils.isBlank(authorization) && authorization.contains("Bearer ")) {
|
if (StringUtils.isNotBlank(authorization) && authorization.startsWith("Bearer ")) {
|
||||||
throw new RenException(ErrorCode.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
token = authorization.replace("Bearer ", "");
|
|
||||||
|
|
||||||
//如果header中不存在token,则从参数中获取token
|
|
||||||
if (StringUtils.isBlank(token)) {
|
|
||||||
authorization = httpRequest.getParameter(Constant.AUTHORIZATION);
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(authorization) && authorization.contains("Bearer ")) {
|
|
||||||
throw new RenException(ErrorCode.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
token = authorization.replace("Bearer ", "");
|
token = authorization.replace("Bearer ", "");
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import xiaozhi.common.exception.ErrorCode;
|
|||||||
import xiaozhi.common.user.UserDetail;
|
import xiaozhi.common.user.UserDetail;
|
||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.common.utils.MessageUtils;
|
import xiaozhi.common.utils.MessageUtils;
|
||||||
import xiaozhi.modules.security.controller.LoginController;
|
|
||||||
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
||||||
import xiaozhi.modules.security.service.ShiroService;
|
import xiaozhi.modules.security.service.ShiroService;
|
||||||
import xiaozhi.modules.sys.entity.SysUserEntity;
|
import xiaozhi.modules.sys.entity.SysUserEntity;
|
||||||
@@ -82,8 +81,6 @@ public class Oauth2Realm extends AuthorizingRealm {
|
|||||||
//转换成UserDetail对象
|
//转换成UserDetail对象
|
||||||
UserDetail userDetail = ConvertUtils.sourceToTarget(userEntity, UserDetail.class);
|
UserDetail userDetail = ConvertUtils.sourceToTarget(userEntity, UserDetail.class);
|
||||||
|
|
||||||
//获取用户对应的部门数据权限
|
|
||||||
userDetail.setDeptIdList(null);
|
|
||||||
userDetail.setToken(accessToken);
|
userDetail.setToken(accessToken);
|
||||||
|
|
||||||
//账号锁定
|
//账号锁定
|
||||||
|
|||||||
+9
-3
@@ -1,14 +1,12 @@
|
|||||||
package xiaozhi.modules.security.service;
|
package xiaozhi.modules.security.service;
|
||||||
|
|
||||||
import xiaozhi.common.page.PageData;
|
|
||||||
import xiaozhi.common.page.TokenDTO;
|
import xiaozhi.common.page.TokenDTO;
|
||||||
import xiaozhi.common.service.BaseService;
|
import xiaozhi.common.service.BaseService;
|
||||||
import xiaozhi.common.utils.Result;
|
import xiaozhi.common.utils.Result;
|
||||||
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
||||||
|
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户Token
|
* 用户Token
|
||||||
* Copyright (c) 人人开源 All rights reserved.
|
* Copyright (c) 人人开源 All rights reserved.
|
||||||
@@ -32,4 +30,12 @@ public interface SysUserTokenService extends BaseService<SysUserTokenEntity> {
|
|||||||
*/
|
*/
|
||||||
void logout(Long userId);
|
void logout(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
* @param passwordDTO
|
||||||
|
*/
|
||||||
|
void changePassword(Long userId, PasswordDTO passwordDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
+15
-1
@@ -2,6 +2,7 @@ package xiaozhi.modules.security.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
import xiaozhi.common.exception.RenException;
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.page.TokenDTO;
|
import xiaozhi.common.page.TokenDTO;
|
||||||
@@ -12,7 +13,7 @@ import xiaozhi.modules.security.dao.SysUserTokenDao;
|
|||||||
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
import xiaozhi.modules.security.entity.SysUserTokenEntity;
|
||||||
import xiaozhi.modules.security.oauth2.TokenGenerator;
|
import xiaozhi.modules.security.oauth2.TokenGenerator;
|
||||||
import xiaozhi.modules.security.service.SysUserTokenService;
|
import xiaozhi.modules.security.service.SysUserTokenService;
|
||||||
import org.springframework.stereotype.Service;
|
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
import xiaozhi.modules.sys.service.SysUserService;
|
import xiaozhi.modules.sys.service.SysUserService;
|
||||||
|
|
||||||
@@ -81,6 +82,9 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl<SysUserTokenDao, Sy
|
|||||||
@Override
|
@Override
|
||||||
public SysUserDTO getUserByToken(String token) {
|
public SysUserDTO getUserByToken(String token) {
|
||||||
SysUserTokenEntity userToken = baseDao.getByToken(token);
|
SysUserTokenEntity userToken = baseDao.getByToken(token);
|
||||||
|
if (null == userToken) {
|
||||||
|
throw new RenException(ErrorCode.TOKEN_INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (userToken.getExpireDate().before(now)) {
|
if (userToken.getExpireDate().before(now)) {
|
||||||
@@ -97,4 +101,14 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl<SysUserTokenDao, Sy
|
|||||||
Date expireDate = DateUtil.offsetMinute(new Date(), -1);
|
Date expireDate = DateUtil.offsetMinute(new Date(), -1);
|
||||||
baseDao.logout(userId, expireDate);
|
baseDao.logout(userId, expireDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changePassword(Long userId, PasswordDTO passwordDTO) {
|
||||||
|
// 修改密码
|
||||||
|
sysUserService.changePassword(userId, passwordDTO);
|
||||||
|
|
||||||
|
// 使 token 失效,后需要重新登录
|
||||||
|
Date expireDate = DateUtil.offsetMinute(new Date(), -1);
|
||||||
|
baseDao.logout(userId, expireDate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -46,11 +46,4 @@ public class SecurityUser {
|
|||||||
public static Long getUserId() {
|
public static Long getUserId() {
|
||||||
return getUser().getId();
|
return getUser().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门ID
|
|
||||||
*/
|
|
||||||
public static Long getDeptId() {
|
|
||||||
return getUser().getDeptId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@ package xiaozhi.modules.sys.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import xiaozhi.common.entity.BaseEntity;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import xiaozhi.common.entity.BaseEntity;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -32,11 +32,6 @@ public class SysUserEntity extends BaseEntity {
|
|||||||
* 状态 0:停用 1:正常
|
* 状态 0:停用 1:正常
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
|
||||||
* 更新者
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private Date createDate;
|
|
||||||
/**
|
/**
|
||||||
* 更新者
|
* 更新者
|
||||||
*/
|
*/
|
||||||
@@ -47,10 +42,5 @@ public class SysUserEntity extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
/**
|
|
||||||
* 部门名称
|
|
||||||
*/
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String deptName;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.sys.service;
|
package xiaozhi.modules.sys.service;
|
||||||
|
|
||||||
import xiaozhi.common.service.BaseService;
|
import xiaozhi.common.service.BaseService;
|
||||||
|
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
import xiaozhi.modules.sys.entity.SysUserEntity;
|
import xiaozhi.modules.sys.entity.SysUserEntity;
|
||||||
|
|
||||||
@@ -18,4 +19,5 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
|||||||
|
|
||||||
void delete(Long[] ids);
|
void delete(Long[] ids);
|
||||||
|
|
||||||
|
void changePassword(Long userId, PasswordDTO passwordDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
+26
@@ -10,6 +10,7 @@ import xiaozhi.common.service.impl.BaseServiceImpl;
|
|||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.modules.security.password.PasswordUtils;
|
import xiaozhi.modules.security.password.PasswordUtils;
|
||||||
import xiaozhi.modules.sys.dao.SysUserDao;
|
import xiaozhi.modules.sys.dao.SysUserDao;
|
||||||
|
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||||
import xiaozhi.modules.sys.dto.SysUserDTO;
|
import xiaozhi.modules.sys.dto.SysUserDTO;
|
||||||
import xiaozhi.modules.sys.entity.SysUserEntity;
|
import xiaozhi.modules.sys.entity.SysUserEntity;
|
||||||
import xiaozhi.modules.sys.enums.SuperAdminEnum;
|
import xiaozhi.modules.sys.enums.SuperAdminEnum;
|
||||||
@@ -81,6 +82,31 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
|||||||
baseDao.deleteBatchIds(Arrays.asList(ids));
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changePassword(Long userId, PasswordDTO passwordDTO) {
|
||||||
|
SysUserEntity sysUserEntity = sysUserDao.selectById(userId);
|
||||||
|
|
||||||
|
if (null == sysUserEntity) {
|
||||||
|
throw new RenException(ErrorCode.TOKEN_INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断旧密码是否正确
|
||||||
|
if (!PasswordUtils.matches(passwordDTO.getPassword(), sysUserEntity.getPassword())) {
|
||||||
|
throw new RenException("旧密码输入错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
//新密码强度
|
||||||
|
if (!isStrongPassword(passwordDTO.getNewPassword())) {
|
||||||
|
throw new RenException(ErrorCode.PASSWORD_WEAK_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
//密码加密
|
||||||
|
String password = PasswordUtils.encode(passwordDTO.getNewPassword());
|
||||||
|
sysUserEntity.setPassword(password);
|
||||||
|
|
||||||
|
updateById(sysUserEntity);
|
||||||
|
}
|
||||||
|
|
||||||
private Long getUserCount() {
|
private Long getUserCount() {
|
||||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
||||||
return baseDao.selectCount(queryWrapper);
|
return baseDao.selectCount(queryWrapper);
|
||||||
|
|||||||
@@ -18,20 +18,6 @@ export default {
|
|||||||
})
|
})
|
||||||
}).send()
|
}).send()
|
||||||
},
|
},
|
||||||
// 获取用户信息
|
|
||||||
getUserInfo(callback) {
|
|
||||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/info`)
|
|
||||||
.method('GET')
|
|
||||||
.success((res) => {
|
|
||||||
RequestService.clearRequestTime()
|
|
||||||
callback(res)
|
|
||||||
})
|
|
||||||
.fail(() => {
|
|
||||||
RequestService.reAjaxFun(() => {
|
|
||||||
this.getUserInfo()
|
|
||||||
})
|
|
||||||
}).send()
|
|
||||||
},
|
|
||||||
// 获取设备信息
|
// 获取设备信息
|
||||||
getHomeList(callback) {
|
getHomeList(callback) {
|
||||||
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/device/bind`)
|
RequestService.sendRequest().url(`${getServiceUrl()}/api/v1/user/device/bind`)
|
||||||
@@ -173,5 +159,52 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
|
// 获取智能体列表
|
||||||
|
getAgentList(callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getAgentList(callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
|
||||||
|
getUserInfo(callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/user/info`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime()
|
||||||
|
callback(res)
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
console.error('接口请求失败:', err)
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getUserInfo(callback)
|
||||||
|
})
|
||||||
|
}).send()
|
||||||
|
},
|
||||||
|
// 添加智能体
|
||||||
|
addAgent(agentName, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/user/agent`)
|
||||||
|
.method('POST')
|
||||||
|
.data({ name: agentName })
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail(() => {
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.addAgent(agentName, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog :visible.sync="visible" width="480px" center>
|
<el-dialog :visible.sync="visible" width="400px" center >
|
||||||
<div style="margin: 0 20px 20px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
|
<div style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
|
||||||
<div style="width: 36px;height: 36px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
||||||
<img src="@/assets/home/equipment.png" alt="" style="width: 16px;height: 14px;" />
|
<img src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
|
||||||
</div>
|
</div>
|
||||||
添加设备
|
添加设备
|
||||||
</div>
|
</div>
|
||||||
<div style="height: 1px;background: #e8f0ff;" />
|
<div style="height: 1px;background: #e8f0ff;" />
|
||||||
<div style="margin: 30px 20px;">
|
<div style="margin: 22px 15px;">
|
||||||
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
|
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
|
||||||
<div style="color: red;display: inline-block;">*</div>验证码:
|
<div style="color: red;display: inline-block;">*</div>
|
||||||
|
<span style="font-size: 11px"> 验证码:</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-46" style="margin-top: 10px;">
|
<div class="input-46" style="margin-top: 12px;">
|
||||||
<el-input placeholder="请输入设备播报的6位数验证码.." v-model="deviceCode" />
|
<el-input placeholder="请输入设备播报的6位数验证码.." v-model="deviceCode" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;margin: 0 20px;gap: 10px;">
|
<div style="display: flex;margin: 15px 15px;gap: 7px;">
|
||||||
<div class="dialog-btn" @click="confirm">
|
<div class="dialog-btn" @click="confirm">
|
||||||
确定
|
确定
|
||||||
</div>
|
</div>
|
||||||
@@ -53,7 +54,6 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
|
|
||||||
.input-46 {
|
.input-46 {
|
||||||
border: 1px solid #e4e6ef;
|
border: 1px solid #e4e6ef;
|
||||||
background: #f6f8fb;
|
background: #f6f8fb;
|
||||||
@@ -65,11 +65,26 @@ export default {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
border-radius: 23px;
|
border-radius: 23px;
|
||||||
background: #5778ff;
|
background: #5778ff;
|
||||||
height: 46px;
|
height: 40px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 14px;
|
font-size: 12px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
line-height: 46px;
|
line-height: 40px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::v-deep .el-dialog {
|
||||||
|
border-radius: 15px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__headerbtn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__body {
|
||||||
|
padding: 4px 6px;
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__header{
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :visible.sync="visible" width="400px" center>
|
||||||
|
<div style="margin: 0 10px 10px;display: flex;align-items: center;gap: 10px;font-weight: 700;font-size: 20px;text-align: left;color: #3d4566;">
|
||||||
|
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
||||||
|
<img src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
|
||||||
|
</div>
|
||||||
|
添加智慧体
|
||||||
|
</div>
|
||||||
|
<div style="height: 1px;background: #e8f0ff;" />
|
||||||
|
<div style="margin: 22px 15px;">
|
||||||
|
<div style="font-weight: 400;font-size: 14px;text-align: left;color: #3d4566;">
|
||||||
|
<div style="color: red;display: inline-block;">*</div> 智慧体名称:
|
||||||
|
</div>
|
||||||
|
<div class="input-46" style="margin-top: 12px;">
|
||||||
|
<el-input placeholder="请输入智慧体名称.." v-model="wisdomBodyName" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex;margin: 15px 15px;gap: 7px;">
|
||||||
|
<div class="dialog-btn" @click="confirm">
|
||||||
|
确定
|
||||||
|
</div>
|
||||||
|
<div class="dialog-btn"
|
||||||
|
style="background: #e6ebff;border: 1px solid #adbdff;color: #5778ff;"
|
||||||
|
@click="cancel">
|
||||||
|
取消
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import userApi from '@/apis/module/user';
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'AddWisdomBodyDialog',
|
||||||
|
props: {
|
||||||
|
visible: { type: Boolean, required: true }
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return { wisdomBodyName: "" }
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
confirm() {
|
||||||
|
if (!this.wisdomBodyName.trim()) {
|
||||||
|
this.$message.error('请输入智慧体名称');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
userApi.addAgent(this.wisdomBodyName, (res) => {
|
||||||
|
this.$message.success('添加成功');
|
||||||
|
this.$emit('confirm', res);
|
||||||
|
this.$emit('update:visible', false);
|
||||||
|
this.wisdomBodyName = "";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
cancel() {
|
||||||
|
this.$emit('update:visible', false)
|
||||||
|
this.wisdomBodyName = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
.input-46 {
|
||||||
|
border: 1px solid #e4e6ef;
|
||||||
|
background: #f6f8fb;
|
||||||
|
border-radius: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-btn {
|
||||||
|
cursor: pointer;
|
||||||
|
flex: 1;
|
||||||
|
border-radius: 23px;
|
||||||
|
background: #5778ff;
|
||||||
|
height: 40px;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #fff;
|
||||||
|
line-height: 40px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog {
|
||||||
|
border-radius: 15px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__headerbtn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__body {
|
||||||
|
padding: 4px 6px;
|
||||||
|
}
|
||||||
|
::v-deep .el-dialog__header{
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="device-item">
|
<div class="device-item">
|
||||||
<div style="display: flex;justify-content: space-between;">
|
<div style="display: flex;justify-content: space-between;">
|
||||||
<div style="font-weight: 700;font-size: 24px;text-align: left;color: #3d4566;">
|
<div style="font-weight: 700;font-size: 18px;text-align: left;color: #3d4566;">
|
||||||
{{ device.mac }}
|
{{ device.agentName }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<img src="@/assets/home/delete.png" alt=""
|
<img src="@/assets/home/delete.png" alt=""
|
||||||
style="width: 24px;height: 24px;margin-right: 10px;" />
|
style="width: 18px;height: 18px;margin-right: 10px;" />
|
||||||
<img src="@/assets/home/info.png" alt="" style="width: 24px;height: 24px;" />
|
<img src="@/assets/home/info.png" alt="" style="width: 18px;height: 18px;" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="device-name">
|
<div class="device-name">
|
||||||
设备型号:{{ device.model }}
|
设备型号:{{ device.ttsModelName }}
|
||||||
|
</div>
|
||||||
|
<div class="device-name">
|
||||||
|
音色模型:{{ device.ttsVoiceName }}
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;gap: 10px;align-items: center;">
|
<div style="display: flex;gap: 10px;align-items: center;">
|
||||||
<div class="settings-btn" @click="$emit('configure')">
|
<div class="settings-btn" @click="$emit('configure')">
|
||||||
@@ -23,12 +26,12 @@
|
|||||||
<div class="settings-btn">
|
<div class="settings-btn">
|
||||||
历史对话
|
历史对话
|
||||||
</div>
|
</div>
|
||||||
<el-switch v-model="switchValue" inactive-text="OTA升级:" :width="42"
|
<div class="settings-btn" @click="$emit('deviceManage')">
|
||||||
style="margin-left: auto;" />
|
设备管理
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="version-info">
|
<div class="version-info">
|
||||||
<div>最近对话:{{ device.lastConversation }}</div>
|
<div>最近对话:{{ device.lastConnectedAt }}</div>
|
||||||
<div>APP版本:{{ device.appVersion }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -46,28 +49,28 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.device-item {
|
.device-item {
|
||||||
width: 455px;
|
width: 342px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
background: #fafcfe;
|
background: #fafcfe;
|
||||||
padding: 30px;
|
padding: 22px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.device-name {
|
.device-name {
|
||||||
margin: 10px 0 14px;
|
margin: 7px 0 10px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 14px;
|
font-size: 11px;
|
||||||
color: #3d4566;
|
color: #3d4566;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-btn {
|
.settings-btn {
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 14px;
|
font-size: 10px;
|
||||||
color: #5778ff;
|
color: #5778ff;
|
||||||
background: #e6ebff;
|
background: #e6ebff;
|
||||||
width: 76px;
|
width: 57px;
|
||||||
height: 28px;
|
height: 21px;
|
||||||
line-height: 28px;
|
line-height: 21px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
}
|
}
|
||||||
@@ -75,9 +78,10 @@ export default {
|
|||||||
.version-info {
|
.version-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-top: 20px;
|
margin-top: 15px;
|
||||||
font-size: 14px;
|
font-size: 10px;
|
||||||
color: #979db1;
|
color: #979db1;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-header class="header">
|
<el-header class="header">
|
||||||
<div style="display: flex;justify-content: space-between;">
|
<div style="display: flex;justify-content: space-between;margin-top: 6px; ">
|
||||||
<div style="display: flex;align-items: center;gap: 10px;">
|
<div style="display: flex;align-items: center;gap: 10px;">
|
||||||
<img src="@/assets/xiaozhi-logo.png" alt="" style="width: 56px;height: 56px;" />
|
<img src="@/assets/xiaozhi-logo.png" alt="" style="width: 42px;height: 42px;" />
|
||||||
<img src="@/assets/xiaozhi-ai.png" alt="" style="width: 78px;height: 16px;" />
|
<img src="@/assets/xiaozhi-ai.png" alt="" style="width: 58px;height: 12px;" />
|
||||||
<div class="equipment-management" @click="goHome">
|
<div class="equipment-management" @click="goHome">
|
||||||
<img src="@/assets/home/equipment.png" alt="" style="width: 16px;height: 14px;" />
|
<img src="@/assets/home/equipment.png" alt="" style="width: 12px;height: 10px;" />
|
||||||
设备管理
|
智能体管理
|
||||||
</div>
|
</div>
|
||||||
<div class="console">
|
<div class="console">
|
||||||
<i class="el-icon-s-grid" style="font-size: 14px;color: #979db1;" />
|
<i class="el-icon-s-grid" style="font-size: 10px;color: #979db1;" />
|
||||||
控制台
|
控制台
|
||||||
</div>
|
</div>
|
||||||
<div class="equipment-management2">
|
<div class="equipment-management2">
|
||||||
设备管理
|
设备管理
|
||||||
<img src="@/assets/home/close.png" alt="" style="width: 8px;height: 8px;" />
|
<img src="@/assets/home/close.png" alt="" style="width: 6px;height: 6px;" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;align-items: center;gap: 10px;">
|
<div style="display: flex;align-items: center;gap: 7px; margin-top: 2px;">
|
||||||
<div class="serach-box">
|
<div class="serach-box">
|
||||||
<el-input placeholder="输入名称搜索.." v-model="serach" />
|
<el-input placeholder="输入名称搜索.." v-model="serach" style="border: none; background: transparent;" @keyup.enter.native="handleSearch" />
|
||||||
<img src="@/assets/home/search.png" alt=""
|
<img src="@/assets/home/search.png" alt=""
|
||||||
style="width: 16px;height: 16px;margin-right: 15px;cursor: pointer;" />
|
style="width: 14px;height: 14px;margin-right: 11px;cursor: pointer;" @click="handleSearch" />
|
||||||
</div>
|
</div>
|
||||||
<img src="@/assets/home/avatar.png" alt="" style="width: 28px;height: 28px;" />
|
<img src="@/assets/home/avatar.png" alt="" style="width: 21px;height: 21px;" />
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
158 3632 4642
|
{{ userInfo.mobile || '加载中...' }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,17 +33,57 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import userApi from '@/apis/module/user'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HeaderBar',
|
name: 'HeaderBar',
|
||||||
|
props: ['devices'], // 接收父组件设备列表
|
||||||
data() {
|
data() {
|
||||||
return { serach: '' }
|
return {
|
||||||
|
serach: '',
|
||||||
|
userInfo: {
|
||||||
|
mobile: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchUserInfo()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
goHome() {
|
goHome() {
|
||||||
// 跳转到首页
|
// 跳转到首页
|
||||||
this.$router.push('/')
|
this.$router.push('/')
|
||||||
|
},
|
||||||
|
// 获取用户信息
|
||||||
|
fetchUserInfo() {
|
||||||
|
userApi.getUserInfo(({data}) => {
|
||||||
|
this.userInfo = data.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 处理搜索
|
||||||
|
handleSearch() {
|
||||||
|
const searchValue = this.serach.trim();
|
||||||
|
let filteredDevices;
|
||||||
|
|
||||||
|
if (!searchValue) {
|
||||||
|
// 当搜索内容为空时,显示原始完整列表
|
||||||
|
filteredDevices = this.$parent.originalDevices;
|
||||||
|
} else {
|
||||||
|
// 过滤逻辑
|
||||||
|
filteredDevices = this.devices.filter(device => {
|
||||||
|
return device.agentName.includes(searchValue) ||
|
||||||
|
device.ttsModelName.includes(searchValue) ||
|
||||||
|
device.ttsVoiceName.includes(searchValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$emit('search-result', filteredDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -54,69 +94,82 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.equipment-management {
|
.equipment-management {
|
||||||
width: 110px;
|
width: 82px;
|
||||||
height: 32px;
|
height: 24px;
|
||||||
border-radius: 16px;
|
border-radius: 12px;
|
||||||
background: #5778ff;
|
background: #5778ff;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 10px;
|
gap: 7px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 14px;
|
font-size: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.equipment-management2 {
|
.equipment-management2 {
|
||||||
width: 116px;
|
width: 87px;
|
||||||
height: 30px;
|
height: 22px;
|
||||||
border-radius: 15px;
|
border-radius: 11px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: 12px;
|
font-size: 9px;
|
||||||
color: #979db1;
|
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
gap: 10px;
|
gap: 7px;
|
||||||
color: #3d4566;
|
color: #3d4566;
|
||||||
margin-left: 20px;
|
margin-left: 2px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
background: #f6fcfe66;
|
background: #f6fcfe66;
|
||||||
border: 1px solid #fff;
|
border: 1px solid #fff;
|
||||||
|
height: 53px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.serach-box {
|
.serach-box {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 306px;
|
width: 220px;
|
||||||
height: 40px;
|
height: 30px;
|
||||||
border-radius: 20px;
|
border-radius: 15px;
|
||||||
background-color: #e2f5f7;
|
background-color: #f6fcfe66;
|
||||||
|
border: 1px solid #e4e6ef;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
padding: 0 7px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.serach-box /deep/ .el-input__inner {
|
||||||
|
border-radius: 15px;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
padding-left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.user-info {
|
.user-info {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 16px;
|
font-size: 12px;
|
||||||
letter-spacing: -0.02px;
|
letter-spacing: -0.02px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: #3d4566;
|
color: #3d4566;
|
||||||
}
|
}
|
||||||
.console {
|
.console {
|
||||||
width: 120px;
|
width: 90px;
|
||||||
height: 30px;
|
height: 22px;
|
||||||
border-radius: 15px;
|
border-radius: 11px;
|
||||||
background: radial-gradient(50% 50% at 50% 50%, #fff 0%, #e8f0ff 100%);
|
background: radial-gradient(50% 50% at 50% 50%, #fff 0%, #e8f0ff 100%);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: 12px;
|
font-size: 9px;
|
||||||
color: #979db1;
|
color: #979db1;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
gap: 10px;
|
gap: 7px;
|
||||||
color: #979db1;
|
margin-left: 15px;
|
||||||
margin-left: 20px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -39,6 +39,15 @@ const routes = [
|
|||||||
return import('../views/register.vue')
|
return import('../views/register.vue')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 新增设备管理页面路由
|
||||||
|
{
|
||||||
|
path: '/device-management',
|
||||||
|
name: 'DeviceManagement',
|
||||||
|
component: function () {
|
||||||
|
return import('../views/DeviceManagement.vue')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
<template>
|
||||||
|
<div class="welcome">
|
||||||
|
<HeaderBar />
|
||||||
|
<el-main style="padding: 20px; display: flex; flex-direction: column;">
|
||||||
|
<div class="table-container">
|
||||||
|
<h3 class="device-list-title">设备列表</h3>
|
||||||
|
<el-button type="primary" class="add-device-btn" @click="handleAddDevice">
|
||||||
|
+ 添加设备
|
||||||
|
</el-button>
|
||||||
|
<el-table :data="deviceList" style="width: 100%; margin-top: 20px" border stripe>
|
||||||
|
<el-table-column label="设备型号" prop="model" flex></el-table-column>
|
||||||
|
<el-table-column label="固件版本" prop="firmwareVersion" width="140"></el-table-column>
|
||||||
|
<el-table-column label="Mac地址" prop="macAddress" width="220"></el-table-column>
|
||||||
|
<el-table-column label="绑定时间" prop="bindTime" width="260"></el-table-column>
|
||||||
|
<el-table-column label="最近对话" prop="lastConversation" width="100"></el-table-column>
|
||||||
|
<el-table-column label="备注" width="220">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-input v-if="scope.row.isEdit" v-model="scope.row.remark" size="mini" @blur="stopEditRemark(scope.$index)"></el-input>
|
||||||
|
<span v-else>
|
||||||
|
<i v-if="!scope.row.remark" class="el-icon-edit" @click="startEditRemark(scope.$index, scope.row)"></i>
|
||||||
|
<span v-else @click="startEditRemark(scope.$index, scope.row)">
|
||||||
|
{{ scope.row.remark }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="OTA升级" width="120">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-switch v-model="scope.row.otaSwitch" size="mini" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" width="80">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button size="mini" type="text" @click="handleUnbind(scope.row)" style="color: #ff4949">
|
||||||
|
解绑
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</div>
|
||||||
|
<div style="font-size: 12px; font-weight: 400; margin-top: auto; padding-top: 30px; color: #979db1;">
|
||||||
|
©2025 xiaozhi-esp32-server
|
||||||
|
</div>
|
||||||
|
<AddDeviceDialog :visible.sync="addDeviceDialogVisible" @added="handleDeviceAdded" />
|
||||||
|
</el-main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HeaderBar from "@/components/HeaderBar.vue";
|
||||||
|
import AddDeviceDialog from "@/components/AddDeviceDialog.vue";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {HeaderBar, AddDeviceDialog },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
addDeviceDialogVisible: false,
|
||||||
|
deviceList: [
|
||||||
|
{
|
||||||
|
model: 'xingzhi-cube-0.96oled-wifi',
|
||||||
|
firmwareVersion: '1.4.6',
|
||||||
|
macAddress: 'fc:01:2c:c5:d5:7c',
|
||||||
|
bindTime: '2025-03-10 18:16:21',
|
||||||
|
lastConversation: '6 天前',
|
||||||
|
remark: '',
|
||||||
|
isEdit: false,
|
||||||
|
otaSwitch: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: 'xingzhi-board-1.3tft-ble',
|
||||||
|
firmwareVersion: '2.1.0',
|
||||||
|
macAddress: 'ac:12:3d:e7:f8:9a',
|
||||||
|
bindTime: '2025-03-12 09:30:15',
|
||||||
|
lastConversation: '4 天前',
|
||||||
|
remark: '测试设备',
|
||||||
|
isEdit: false,
|
||||||
|
otaSwitch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: 'xingzhi-kit-0.91oled-4g',
|
||||||
|
firmwareVersion: '1.8.3',
|
||||||
|
macAddress: 'bc:45:6f:1e:2d:3c',
|
||||||
|
bindTime: '2025-03-15 14:22:08',
|
||||||
|
lastConversation: '2 天前',
|
||||||
|
remark: '生产环境设备',
|
||||||
|
isEdit: false,
|
||||||
|
otaSwitch: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleAddDevice() {
|
||||||
|
// 添加设备逻辑
|
||||||
|
this.addDeviceDialogVisible = true;
|
||||||
|
},
|
||||||
|
startEditRemark(index, row) {
|
||||||
|
this.deviceList[index].isEdit = true;
|
||||||
|
},
|
||||||
|
stopEditRemark(index) {
|
||||||
|
this.deviceList[index].isEdit = false;
|
||||||
|
},
|
||||||
|
handleUnbind(device) {
|
||||||
|
// 解绑逻辑
|
||||||
|
console.log('解绑设备', device);
|
||||||
|
},
|
||||||
|
handleDeviceAdded(deviceCode) {
|
||||||
|
console.log('添加的智慧体名称:', deviceCode);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.welcome {
|
||||||
|
min-width: 900px;
|
||||||
|
min-height: 506px;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-image: url("@/assets/home/background.png");
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
-webkit-background-size: cover;
|
||||||
|
-o-background-size: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-container {
|
||||||
|
background: #f9fafc;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-device-btn {
|
||||||
|
float: right;
|
||||||
|
background: #409eff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
width: 105px;
|
||||||
|
height: 32px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 14px;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
&:hover {
|
||||||
|
background: #3a8ee6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-list-title {
|
||||||
|
float: left;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 5px;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-icon-edit {
|
||||||
|
color: #409eff;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="welcome">
|
<div class="welcome">
|
||||||
<!-- 公共头部 -->
|
<!-- 公共头部 -->
|
||||||
<HeaderBar />
|
<HeaderBar :devices="devices" @search-result="handleSearchResult" />
|
||||||
<el-main style="padding: 20px;display: flex;flex-direction: column;">
|
<el-main style="padding: 20px;display: flex;flex-direction: column;">
|
||||||
<div>
|
<div>
|
||||||
<!-- 首页内容 -->
|
<!-- 首页内容 -->
|
||||||
@@ -21,23 +21,23 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="add-device-btn" @click="showAddDialog">
|
<div class="add-device-btn" @click="showAddDialog">
|
||||||
<div class="left-add">
|
<div class="left-add">
|
||||||
添加设备
|
添加智能体
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 23px;height: 13px;background: #5778ff;margin-left: -10px;" />
|
<div style="width: 23px;height: 13px;background: #5778ff;margin-left: -10px;" />
|
||||||
<div class="right-add">
|
<div class="right-add">
|
||||||
<i class="el-icon-right" style="font-size: 30px;color: #fff;" />
|
<i class="el-icon-right" style="font-size: 20px;color: #fff;" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;flex-wrap: wrap;margin-top: 20px;gap: 20px;justify-content: space-between;box-sizing: border-box;">
|
<div style="display: flex;flex-wrap: wrap;margin-top: 20px;gap: 20px;justify-content: flex-start;box-sizing: border-box;">
|
||||||
<DeviceItem v-for="(item,index) in devices" :key="index" :device="item" @configure="goToRoleConfig" />
|
<DeviceItem v-for="(item,index) in devices" :key="index" :device="item" @configure="goToRoleConfig" @deviceManage="handleDeviceManage" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: 12px;font-weight: 400;margin-top: auto;padding-top: 30px;color: #979db1;">
|
<div style="font-size: 12px;font-weight: 400;margin-top: auto;padding-top: 30px;color: #979db1;">
|
||||||
©2025 xiaozhi-esp32-server
|
©2025 xiaozhi-esp32-server
|
||||||
</div>
|
</div>
|
||||||
<AddDeviceDialog :visible.sync="addDeviceDialogVisible" @added="handleDeviceAdded" />
|
<AddWisdomBodyDialog :visible.sync="addDeviceDialogVisible" @confirm="handleWisdomBodyAdded" />
|
||||||
</el-main>
|
</el-main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -45,24 +45,24 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import DeviceItem from '@/components/DeviceItem.vue'
|
import DeviceItem from '@/components/DeviceItem.vue'
|
||||||
import AddDeviceDialog from '@/components/AddDeviceDialog.vue'
|
import AddWisdomBodyDialog from '@/components/AddWisdomBodyDialog.vue'
|
||||||
import HeaderBar from '@/components/HeaderBar.vue'
|
import HeaderBar from '@/components/HeaderBar.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HomePage',
|
name: 'HomePage',
|
||||||
components: { DeviceItem, AddDeviceDialog, HeaderBar },
|
components: { DeviceItem, AddWisdomBodyDialog, HeaderBar },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
addDeviceDialogVisible: false,
|
addDeviceDialogVisible: false,
|
||||||
// 此处模拟设备列表(10条数据)
|
devices: [],
|
||||||
devices: Array.from({ length: 10 }, (_, i) => ({
|
originalDevices: [],
|
||||||
id: i,
|
|
||||||
mac: 'CC:ba:97:11:a6:ac',
|
|
||||||
model: 'esp32-s3-touch-amoled-1.8',
|
|
||||||
lastConversation: '6天前',
|
|
||||||
appVersion: '1.1.0'
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.fetchAgentList();
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
showAddDialog() {
|
showAddDialog() {
|
||||||
this.addDeviceDialogVisible = true
|
this.addDeviceDialogVisible = true
|
||||||
@@ -71,19 +71,39 @@ export default {
|
|||||||
// 点击配置角色后跳转到角色配置页
|
// 点击配置角色后跳转到角色配置页
|
||||||
this.$router.push('/role-config')
|
this.$router.push('/role-config')
|
||||||
},
|
},
|
||||||
handleDeviceAdded(deviceCode) {
|
handleWisdomBodyAdded(res) {
|
||||||
// 根据需要处理添加设备后逻辑,比如刷新设备列表等
|
console.log('新增智能体响应:', res);
|
||||||
console.log('设备验证码:', deviceCode)
|
this.fetchAgentList();
|
||||||
|
this.addDeviceDialogVisible = false;
|
||||||
|
},
|
||||||
|
handleDeviceManage() {
|
||||||
|
this.$router.push('/device-management');
|
||||||
|
},
|
||||||
|
// 获取智能体列表
|
||||||
|
fetchAgentList() {
|
||||||
|
import('@/apis/module/user').then(({ default: userApi }) => {
|
||||||
|
userApi.getAgentList(({data}) => {
|
||||||
|
this.originalDevices = data.data;
|
||||||
|
this.devices = data.data;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 搜索更新智能体列表
|
||||||
|
handleSearchResult(filteredList) {
|
||||||
|
this.devices = filteredList; // 更新设备列表
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.welcome {
|
.welcome {
|
||||||
min-width: 1200px;
|
min-width: 900px;
|
||||||
min-height: 675px;
|
min-height: 506px;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
background-image: url("@/assets/home/background.png");
|
background-image: url("@/assets/home/background.png");
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
/* 确保背景图像覆盖整个元素 */
|
/* 确保背景图像覆盖整个元素 */
|
||||||
@@ -95,8 +115,8 @@ export default {
|
|||||||
/* 兼容老版本Opera浏览器 */
|
/* 兼容老版本Opera浏览器 */
|
||||||
}
|
}
|
||||||
.add-device {
|
.add-device {
|
||||||
height: 260px;
|
height: 195px;
|
||||||
border-radius: 20px;
|
border-radius: 15px;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: linear-gradient(
|
background: linear-gradient(
|
||||||
@@ -122,48 +142,48 @@ export default {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
/* 兼容老版本Opera浏览器 */
|
/* 兼容老版本Opera浏览器 */
|
||||||
.hellow-text {
|
.hellow-text {
|
||||||
margin-left: 100px;
|
margin-left: 75px;
|
||||||
color: #3d4566;
|
color: #3d4566;
|
||||||
font-size: 44px;
|
font-size: 33px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
letter-spacing: 0;
|
letter-spacing: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hi-hint {
|
.hi-hint {
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 12px;
|
font-size: 10px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: #818cae;
|
color: #818cae;
|
||||||
margin-left: 100px;
|
margin-left: 75px;
|
||||||
margin-top: 7px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-device-btn {
|
.add-device-btn {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-left: 100px;
|
margin-left: 75px;
|
||||||
margin-top: 20px;
|
margin-top: 15px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
.left-add {
|
.left-add {
|
||||||
width: 140px;
|
width: 105px;
|
||||||
height: 46px;
|
height: 34px;
|
||||||
border-radius: 23px;
|
border-radius: 17px;
|
||||||
background: #5778ff;
|
background: #5778ff;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 14px;
|
font-size: 10px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 46px;
|
line-height: 34px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-add {
|
.right-add {
|
||||||
width: 46px;
|
width: 34px;
|
||||||
height: 46px;
|
height: 34px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: #5778ff;
|
background: #5778ff;
|
||||||
margin-left: -8px;
|
margin-left: -6px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -2,45 +2,33 @@
|
|||||||
<div class="welcome">
|
<div class="welcome">
|
||||||
<!-- 公共头部 -->
|
<!-- 公共头部 -->
|
||||||
<HeaderBar/>
|
<HeaderBar/>
|
||||||
<el-main style="padding: 20px;display: flex;flex-direction: column;">
|
<el-main style="padding: 16px;display: flex;flex-direction: column;">
|
||||||
<div style="border-radius: 20px;background: #fafcfe;">
|
<div style="border-radius: 16px;background: #fafcfe; border: 1px solid #e8f0ff;">
|
||||||
<div
|
<div
|
||||||
style="padding: 19px 30px;font-weight: 700;font-size: 24px;text-align: left;color: #3d4566;display: flex;gap: 16px;align-items: center;">
|
style="padding: 15px 24px;font-weight: 700;font-size: 19px;text-align: left;color: #3d4566;display: flex;gap: 13px;align-items: center;">
|
||||||
<div
|
<div
|
||||||
style="width: 46px;height: 46px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
|
style="width: 37px;height: 37px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
|
||||||
<img src="@/assets/home/setting-user.png" alt="" style="width: 24px;height: 24px;"/>
|
<img src="@/assets/home/setting-user.png" alt="" style="width: 19px;height: 19px;"/>
|
||||||
</div>
|
</div>
|
||||||
{{ deviceMac }}
|
{{ deviceMac }}
|
||||||
</div>
|
</div>
|
||||||
<div style="height: 1px;background: #e8f0ff;"/>
|
<div style="height: 1px;background: #e8f0ff;"/>
|
||||||
<el-form ref="form" :model="form" label-width="90px">
|
<el-form ref="form" :model="form" label-width="72px">
|
||||||
<div style="padding: 20px 30px;max-width: 990px;">
|
<div style="padding: 16px 24px;max-width: 792px;">
|
||||||
<el-form-item label="助手昵称:">
|
<el-form-item label="助手昵称:">
|
||||||
<div class="input-46">
|
<div class="input-46" style="width: 100%; max-width: 412px;">
|
||||||
<el-input v-model="form.name"/>
|
<el-input v-model="form.name"/>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色模版:">
|
<el-form-item label="角色模版:">
|
||||||
<div style="display: flex;gap: 10px;">
|
<div style="display: flex;gap: 8px;">
|
||||||
<div class="template-item">
|
<div v-for="template in templates" :key="template" class="template-item" @click="selectTemplate(template)">
|
||||||
台湾女友
|
{{ template }}
|
||||||
</div>
|
|
||||||
<div class="template-item">
|
|
||||||
土豆子
|
|
||||||
</div>
|
|
||||||
<div class="template-item">
|
|
||||||
英语老师
|
|
||||||
</div>
|
|
||||||
<div class="template-item">
|
|
||||||
好奇小男孩
|
|
||||||
</div>
|
|
||||||
<div class="template-item">
|
|
||||||
汪汪队队长
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色音色:">
|
<el-form-item label="角色音色:">
|
||||||
<div style="display: flex;gap: 10px;align-items: center;">
|
<div style="display: flex;gap: 8px;align-items: center;">
|
||||||
<div class="input-46" style="flex:1.4;">
|
<div class="input-46" style="flex:1.4;">
|
||||||
<el-select v-model="form.timbre" placeholder="请选择" style="width: 100%;">
|
<el-select v-model="form.timbre" placeholder="请选择" style="width: 100%;">
|
||||||
<el-option v-for="item in options" :key="item.value" :label="item.label"
|
<el-option v-for="item in options" :key="item.value" :label="item.label"
|
||||||
@@ -56,45 +44,39 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色介绍:">
|
<el-form-item label="角色介绍:">
|
||||||
<div class="textarea-box">
|
<div class="textarea-box">
|
||||||
<el-input type="textarea" rows="6" resize="none" placeholder="请输入内容"
|
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容"
|
||||||
v-model="form.introduction" maxlength="2000" show-word-limit/>
|
v-model="form.introduction" maxlength="2000" show-word-limit/>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="记忆体:">
|
<el-form-item label="记忆体:">
|
||||||
<div class="textarea-box">
|
<div class="textarea-box">
|
||||||
<el-input type="textarea" rows="6" resize="none" placeholder="请输入内容"
|
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容"
|
||||||
v-model="form.prompt" maxlength="1000"/>
|
v-model="form.prompt" maxlength="1000"/>
|
||||||
<div class="prompt-bottom">
|
<div class="prompt-bottom">
|
||||||
<div style="display: flex;gap: 10px;align-items: center;">
|
<div style="display: flex;gap: 8px;align-items: center;">
|
||||||
<div style="color: #979db1;font-size: 14px;">当前记忆(每次对话后重新生成)</div>
|
<div style="color: #979db1;font-size: 11px;">当前记忆(每次对话后重新生成)</div>
|
||||||
<div class="clear-btn">
|
<div class="clear-btn">
|
||||||
<i class="el-icon-delete-solid" style="font-size: 14px;"/>
|
<i class="el-icon-delete-solid" style="font-size: 11px;"/>
|
||||||
清除
|
清除
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="color: #979db1;font-size:14px;">{{ form.prompt.length }}/1000</div>
|
<div style="color: #979db1;font-size:11px;">{{ form.prompt.length }}/1000</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="语言模型(内测):" class="lh-form-item">
|
<el-form-item v-for="model in models" :key="model.label" :label="model.label" class="model-item">
|
||||||
<div style="display: flex;gap: 10px;">
|
<el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="select-field">
|
||||||
<div class="input-46" style="width: 100%;">
|
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
|
||||||
<el-select v-model="form.model" placeholder="请选择" style="width: 100%;">
|
</el-select>
|
||||||
<el-option v-for="item in options" :key="item.value" :label="item.label"
|
|
||||||
:value="item.value">
|
|
||||||
</el-option>
|
|
||||||
</el-select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="" class="lh-form-item">
|
<el-form-item label="" class="lh-form-item" style="margin-top: -25px;">
|
||||||
<div style="color: #979db1;text-align: left;">除了“Qwen
|
<div style="color: #979db1;text-align: left;">除了“Qwen
|
||||||
实时”,其他模型通常会增加约1秒的延迟。改变模型后,建议清空记忆体,以免影响体验。
|
实时”,其他模型通常会增加约1秒的延迟。改变模型后,建议清空记忆体,以免影响体验。
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div style="display: flex;padding: 20px;gap: 10px;align-items: center;">
|
<div style="display: flex;padding: 16px;gap: 8px;align-items: center;">
|
||||||
<div class="save-btn" @click="saveConfig">
|
<div class="save-btn" @click="saveConfig">
|
||||||
保存配置
|
保存配置
|
||||||
</div>
|
</div>
|
||||||
@@ -102,12 +84,12 @@
|
|||||||
重制
|
重制
|
||||||
</div>
|
</div>
|
||||||
<div class="clear-text">
|
<div class="clear-text">
|
||||||
<img src="@/assets/home/red-info.png" alt="" style="width: 24px;height: 24px;"/>
|
<img src="@/assets/home/red-info.png" alt="" style="width: 19px;height: 19px;"/>
|
||||||
保存配置后,需要重启设备,新的配置才会生效。
|
保存配置后,需要重启设备,新的配置才会生效。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: 12px;font-weight: 400;margin-top: auto;padding-top: 30px;color: #979db1;">
|
<div style="font-size: 12px;font-weight: 400;margin-top: auto;padding-top: 24px;color: #979db1;">
|
||||||
©2025 xiaozhi-esp32-server
|
©2025 xiaozhi-esp32-server
|
||||||
</div>
|
</div>
|
||||||
</el-main>
|
</el-main>
|
||||||
@@ -128,15 +110,29 @@ export default {
|
|||||||
timbre: "",
|
timbre: "",
|
||||||
introduction: "",
|
introduction: "",
|
||||||
prompt: "",
|
prompt: "",
|
||||||
model: ""
|
model: {
|
||||||
|
tts: "",
|
||||||
|
vad: "",
|
||||||
|
asr: "",
|
||||||
|
llm: "",
|
||||||
|
memory:"",
|
||||||
|
intent:""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
options: [{
|
options: [
|
||||||
value: '选项1',
|
{ value: '选项1', label: '黄金糕' },
|
||||||
label: '黄金糕'
|
{ value: '选项2', label: '双皮奶' }
|
||||||
}, {
|
],
|
||||||
value: '选项2',
|
models: [
|
||||||
label: '双皮奶'
|
{ label: '大语言模型(LLM)', key: 'llm' },
|
||||||
}]
|
{ label: '语音转文本模型(ASR)', key: 'asr' },
|
||||||
|
{ label: '语音活动检测模型(VAD)', key: 'vad' },
|
||||||
|
{ label: '语音生成模型(TTS)', key: 'tts' },
|
||||||
|
{ label: '意图分类模型(Intent)', key: 'intent' },
|
||||||
|
{ label: '记忆增强模型(Memory)', key: 'memory' }
|
||||||
|
],
|
||||||
|
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长']
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -161,6 +157,11 @@ export default {
|
|||||||
this.$message.success('配置已重置')
|
this.$message.success('配置已重置')
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
// 处理选择模板的逻辑
|
||||||
|
selectTemplate(template) {
|
||||||
|
this.form.name = template;
|
||||||
|
this.$message.success(`已选择模板:${template}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,9 +169,11 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.welcome {
|
.welcome {
|
||||||
min-width: 1200px;
|
min-width: 900px;
|
||||||
min-height: 675px;
|
min-height: 506px;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
background-image: url("@/assets/home/background.png");
|
background-image: url("@/assets/home/background.png");
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
/* 确保背景图像覆盖整个元素 */
|
/* 确保背景图像覆盖整个元素 */
|
||||||
@@ -181,71 +184,97 @@ export default {
|
|||||||
-o-background-size: cover;
|
-o-background-size: cover;
|
||||||
/* 兼容老版本Opera浏览器 */
|
/* 兼容老版本Opera浏览器 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.el-form-item ::v-deep .el-form-item__label {
|
||||||
|
font-size: 10px !important;
|
||||||
|
color: #3d4566 !important;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 22px;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-field{
|
||||||
|
width: 100%;
|
||||||
|
max-width: 720px;
|
||||||
|
border: 1px solid #e4e6ef;
|
||||||
|
background: #f6f8fb;
|
||||||
|
border-radius: 8px;
|
||||||
|
height: 36px !important;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-box {
|
.audio-box {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
height: 46px;
|
height: 37px;
|
||||||
border-radius: 10px;
|
border-radius: 20px;
|
||||||
border: 1px solid #e4e6ef;
|
border: 1px solid #e4e6ef;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-btn {
|
.clear-btn {
|
||||||
width: 60px;
|
width: 48px;
|
||||||
height: 24px;
|
height: 19px;
|
||||||
background: #fd8383;
|
background: #fd8383;
|
||||||
border-radius: 12px;
|
border-radius: 10px;
|
||||||
line-height: 24px;
|
line-height: 19px;
|
||||||
font-size: 14px;
|
font-size: 11px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-text {
|
.clear-text {
|
||||||
color: #979db1;
|
color: #979db1;
|
||||||
font-size: 14px;
|
font-size: 11px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 8px;
|
||||||
margin-left: 20px;
|
margin-left: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.template-item {
|
.template-item {
|
||||||
height: 46px;
|
height: 37px;
|
||||||
width: 100px;
|
width: 76px;
|
||||||
border-radius: 10px;
|
border-radius: 8px;
|
||||||
background: #e6ebff;
|
background: #e6ebff;
|
||||||
line-height: 46px;
|
line-height: 37px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 14px;
|
font-size: 11px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #5778ff;
|
color: #5778ff;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.template-item:hover {
|
||||||
|
background-color: #d0d8ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.prompt-bottom {
|
.prompt-bottom {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 4px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 0 20px;
|
padding: 0 16px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-46 {
|
.input-46 {
|
||||||
border: 1px solid #e4e6ef;
|
border: 1px solid #e4e6ef;
|
||||||
background: #f6f8fb;
|
background: #f6f8fb;
|
||||||
border-radius: 10px;
|
border-radius: 8px;
|
||||||
|
height: 36px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-btn,
|
.save-btn,
|
||||||
.reset-btn {
|
.reset-btn {
|
||||||
width: 140px;
|
width: 112px;
|
||||||
height: 46px;
|
height: 37px;
|
||||||
border-radius: 23px;
|
border-radius: 18px;
|
||||||
line-height: 46px;
|
line-height: 37px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
font-size: 11px
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-btn {
|
.save-btn {
|
||||||
border-radius: 23px;
|
border-radius: 18px;
|
||||||
background: #5778ff;
|
background: #5778ff;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
@@ -258,7 +287,8 @@ export default {
|
|||||||
|
|
||||||
.textarea-box {
|
.textarea-box {
|
||||||
border: 1px solid #e4e6ef;
|
border: 1px solid #e4e6ef;
|
||||||
border-radius: 10px;
|
border-radius: 8px;
|
||||||
background: #f6f8fb;
|
background: #f6f8fb;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ Memory:
|
|||||||
# 每月有1000次免费调用
|
# 每月有1000次免费调用
|
||||||
api_key: 你的mem0ai api key
|
api_key: 你的mem0ai api key
|
||||||
nomem:
|
nomem:
|
||||||
# 不想使用记忆功能,可以使用nomem
|
# 不想使用记忆功能,可以使用nomem
|
||||||
type: nomem
|
type: nomem
|
||||||
mem_local_short:
|
mem_local_short:
|
||||||
# 本地记忆功能,通过selected_module的llm总结,数据保存在本地,不会上传到服务器
|
# 本地记忆功能,通过selected_module的llm总结,数据保存在本地,不会上传到服务器
|
||||||
type: mem_local_short
|
type: mem_local_short
|
||||||
|
|
||||||
ASR:
|
ASR:
|
||||||
@@ -125,6 +125,10 @@ ASR:
|
|||||||
type: fun_local
|
type: fun_local
|
||||||
model_dir: models/SenseVoiceSmall
|
model_dir: models/SenseVoiceSmall
|
||||||
output_dir: tmp/
|
output_dir: tmp/
|
||||||
|
SherpaASR:
|
||||||
|
type: sherpa_onnx_local
|
||||||
|
model_dir: models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17
|
||||||
|
output_dir: tmp/
|
||||||
DoubaoASR:
|
DoubaoASR:
|
||||||
type: doubao
|
type: doubao
|
||||||
appid: 你的火山引擎语音合成服务appid
|
appid: 你的火山引擎语音合成服务appid
|
||||||
@@ -138,6 +142,7 @@ VAD:
|
|||||||
min_silence_duration_ms: 700 # 如果说话停顿比较长,可以把这个值设置大一些
|
min_silence_duration_ms: 700 # 如果说话停顿比较长,可以把这个值设置大一些
|
||||||
|
|
||||||
LLM:
|
LLM:
|
||||||
|
# 所有openai类型均可以修改超参,以AliLLM为例
|
||||||
# 当前支持的type为openai、dify、ollama,可自行适配
|
# 当前支持的type为openai、dify、ollama,可自行适配
|
||||||
AliLLM:
|
AliLLM:
|
||||||
# 定义LLM API类型
|
# 定义LLM API类型
|
||||||
@@ -146,6 +151,11 @@ LLM:
|
|||||||
base_url: https://dashscope.aliyuncs.com/compatible-mode/v1
|
base_url: https://dashscope.aliyuncs.com/compatible-mode/v1
|
||||||
model_name: qwen-turbo
|
model_name: qwen-turbo
|
||||||
api_key: 你的deepseek web key
|
api_key: 你的deepseek web key
|
||||||
|
temperature: 0.7 # 温度值
|
||||||
|
max_tokens: 500 # 最大生成token数
|
||||||
|
top_p: 1
|
||||||
|
top_k: 50
|
||||||
|
frequency_penalty: 0 # 频率惩罚
|
||||||
DoubaoLLM:
|
DoubaoLLM:
|
||||||
# 定义LLM API类型
|
# 定义LLM API类型
|
||||||
type: openai
|
type: openai
|
||||||
@@ -181,8 +191,12 @@ LLM:
|
|||||||
type: dify
|
type: dify
|
||||||
# 建议使用本地部署的dify接口,国内部分区域访问dify公有云接口可能会受限
|
# 建议使用本地部署的dify接口,国内部分区域访问dify公有云接口可能会受限
|
||||||
# 如果使用DifyLLM,配置文件里prompt(提示词)是无效的,需要在dify控制台设置提示词
|
# 如果使用DifyLLM,配置文件里prompt(提示词)是无效的,需要在dify控制台设置提示词
|
||||||
base_url: https://api.dify.cn/v1
|
base_url: https://api.dify.ai/v1
|
||||||
api_key: 你的DifyLLM web key
|
api_key: 你的DifyLLM web key
|
||||||
|
# 使用的对话模式 可以选择工作流 workflows/run 对话模式 chat-messages 文本生成 completion-messages
|
||||||
|
# 使用workflows进行返回的时候输入参数为 query 返回参数的名字要设置为 answer
|
||||||
|
# 文本生成的默认输入参数也是query
|
||||||
|
mode: chat-messages
|
||||||
GeminiLLM:
|
GeminiLLM:
|
||||||
type: gemini
|
type: gemini
|
||||||
# 谷歌Gemini API,需要先在Google Cloud控制台创建API密钥并获取api_key
|
# 谷歌Gemini API,需要先在Google Cloud控制台创建API密钥并获取api_key
|
||||||
@@ -190,7 +204,9 @@ LLM:
|
|||||||
# token申请地址: https://aistudio.google.com/apikey
|
# token申请地址: https://aistudio.google.com/apikey
|
||||||
# 若部署地无法访问接口,需要开启科学上网
|
# 若部署地无法访问接口,需要开启科学上网
|
||||||
api_key: 你的gemini web key
|
api_key: 你的gemini web key
|
||||||
model_name: "gemini-1.5-pro" # gemini-1.5-pro 是免费的
|
model_name: "gemini-2.0-flash"
|
||||||
|
http_proxy: "" #"http://127.0.0.1:10808"
|
||||||
|
https_proxy: "" #http://127.0.0.1:10808"
|
||||||
CozeLLM:
|
CozeLLM:
|
||||||
# 定义LLM API类型
|
# 定义LLM API类型
|
||||||
type: coze
|
type: coze
|
||||||
@@ -225,17 +241,18 @@ TTS:
|
|||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: edge
|
type: edge
|
||||||
voice: zh-CN-XiaoxiaoNeural
|
voice: zh-CN-XiaoxiaoNeural
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
DoubaoTTS:
|
DoubaoTTS:
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: doubao
|
type: doubao
|
||||||
# 火山引擎语音合成服务,需要先在火山引擎控制台创建应用并获取appid和access_token
|
# 火山引擎语音合成服务,需要先在火山引擎控制台创建应用并获取appid和access_token
|
||||||
# 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误
|
# 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误
|
||||||
# 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。
|
# 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。
|
||||||
# 地址:https://console.volcengine.com/speech/service/8
|
# 普通音色在这里开通:https://console.volcengine.com/speech/service/8
|
||||||
|
# 湾湾小何音色在这里开通:https://console.volcengine.com/speech/service/10007,开通后将下面的voice设置成zh_female_wanwanxiaohe_moon_bigtts
|
||||||
api_url: https://openspeech.bytedance.com/api/v1/tts
|
api_url: https://openspeech.bytedance.com/api/v1/tts
|
||||||
voice: BV001_streaming
|
voice: BV001_streaming
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
authorization: "Bearer;"
|
authorization: "Bearer;"
|
||||||
appid: 你的火山引擎语音合成服务appid
|
appid: 你的火山引擎语音合成服务appid
|
||||||
access_token: 你的火山引擎语音合成服务access_token
|
access_token: 你的火山引擎语音合成服务access_token
|
||||||
@@ -246,7 +263,7 @@ TTS:
|
|||||||
# token申请地址 https://cloud.siliconflow.cn/account/ak
|
# token申请地址 https://cloud.siliconflow.cn/account/ak
|
||||||
model: FunAudioLLM/CosyVoice2-0.5B
|
model: FunAudioLLM/CosyVoice2-0.5B
|
||||||
voice: FunAudioLLM/CosyVoice2-0.5B:alex
|
voice: FunAudioLLM/CosyVoice2-0.5B:alex
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
access_token: 你的硅基流动API密钥
|
access_token: 你的硅基流动API密钥
|
||||||
response_format: wav
|
response_format: wav
|
||||||
CozeCnTTS:
|
CozeCnTTS:
|
||||||
@@ -254,7 +271,7 @@ TTS:
|
|||||||
# COZECN TTS
|
# COZECN TTS
|
||||||
# token申请地址 https://www.coze.cn/open/oauth/pats
|
# token申请地址 https://www.coze.cn/open/oauth/pats
|
||||||
voice: 7426720361733046281
|
voice: 7426720361733046281
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
access_token: 你的coze web key
|
access_token: 你的coze web key
|
||||||
response_format: wav
|
response_format: wav
|
||||||
FishSpeech:
|
FishSpeech:
|
||||||
@@ -267,7 +284,7 @@ TTS:
|
|||||||
#--decoder-config-name firefly_gan_vq
|
#--decoder-config-name firefly_gan_vq
|
||||||
#--compile
|
#--compile
|
||||||
type: fishspeech
|
type: fishspeech
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
response_format: wav
|
response_format: wav
|
||||||
reference_id: null
|
reference_id: null
|
||||||
reference_audio: ["/tmp/test.wav",]
|
reference_audio: ["/tmp/test.wav",]
|
||||||
@@ -291,7 +308,7 @@ TTS:
|
|||||||
#python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/caixukun.yaml
|
#python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/caixukun.yaml
|
||||||
type: gpt_sovits_v2
|
type: gpt_sovits_v2
|
||||||
url: "http://127.0.0.1:9880/tts"
|
url: "http://127.0.0.1:9880/tts"
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
text_lang: "auto"
|
text_lang: "auto"
|
||||||
ref_audio_path: "caixukun.wav"
|
ref_audio_path: "caixukun.wav"
|
||||||
prompt_text: ""
|
prompt_text: ""
|
||||||
@@ -316,7 +333,7 @@ TTS:
|
|||||||
#python api.py
|
#python api.py
|
||||||
type: gpt_sovits_v3
|
type: gpt_sovits_v3
|
||||||
url: "http://127.0.0.1:9880"
|
url: "http://127.0.0.1:9880"
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
text_language: "auto"
|
text_language: "auto"
|
||||||
refer_wav_path: "caixukun.wav"
|
refer_wav_path: "caixukun.wav"
|
||||||
prompt_language: "zh"
|
prompt_language: "zh"
|
||||||
@@ -337,7 +354,7 @@ TTS:
|
|||||||
# api_key地址:https://platform.minimaxi.com/user-center/basic-information/interface-key
|
# api_key地址:https://platform.minimaxi.com/user-center/basic-information/interface-key
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: minimax
|
type: minimax
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
group_id: 你的minimax平台groupID
|
group_id: 你的minimax平台groupID
|
||||||
api_key: 你的minimax平台接口密钥
|
api_key: 你的minimax平台接口密钥
|
||||||
model: "speech-01-turbo"
|
model: "speech-01-turbo"
|
||||||
@@ -374,7 +391,7 @@ TTS:
|
|||||||
# token地址:https://nls-portal.console.aliyun.com/overview
|
# token地址:https://nls-portal.console.aliyun.com/overview
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: aliyun
|
type: aliyun
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
appkey: 你的阿里云智能语音交互服务项目Appkey
|
appkey: 你的阿里云智能语音交互服务项目Appkey
|
||||||
token: 你的阿里云智能语音交互服务AccessToken,临时的24小时,要长期用下方的access_key_id,access_key_secret
|
token: 你的阿里云智能语音交互服务AccessToken,临时的24小时,要长期用下方的access_key_id,access_key_secret
|
||||||
voice: xiaoyun
|
voice: xiaoyun
|
||||||
@@ -396,9 +413,21 @@ TTS:
|
|||||||
type: doubao
|
type: doubao
|
||||||
api_url: https://api.302ai.cn/doubao/tts_hd
|
api_url: https://api.302ai.cn/doubao/tts_hd
|
||||||
authorization: "Bearer "
|
authorization: "Bearer "
|
||||||
|
# 湾湾小何音色
|
||||||
voice: "zh_female_wanwanxiaohe_moon_bigtts"
|
voice: "zh_female_wanwanxiaohe_moon_bigtts"
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
access_token: "你的302API密钥"
|
access_token: "你的302API密钥"
|
||||||
|
GizwitsTTS:
|
||||||
|
type: doubao
|
||||||
|
# 火山引擎作为基座,可以完全使用企业级火山引擎语音合成服务
|
||||||
|
# 前一万名注册的用户,将送5元体验金额
|
||||||
|
# 获取API Key地址:https://agentrouter.gizwitsapi.com/panel/token
|
||||||
|
api_url: https://bytedance.gizwitsapi.com/api/v1/tts
|
||||||
|
authorization: "Bearer "
|
||||||
|
# 湾湾小何音色
|
||||||
|
voice: "zh_female_wanwanxiaohe_moon_bigtts"
|
||||||
|
output_dir: tmp/
|
||||||
|
access_token: "你的机智云API key"
|
||||||
ACGNTTS:
|
ACGNTTS:
|
||||||
#在线网址:https://acgn.ttson.cn/
|
#在线网址:https://acgn.ttson.cn/
|
||||||
#token购买:www.ttson.cn
|
#token购买:www.ttson.cn
|
||||||
@@ -414,7 +443,7 @@ TTS:
|
|||||||
to_lang: ZH
|
to_lang: ZH
|
||||||
url: https://u95167-bd74-2aef8085.westx.seetacloud.com:8443/flashsummary/tts?token=
|
url: https://u95167-bd74-2aef8085.westx.seetacloud.com:8443/flashsummary/tts?token=
|
||||||
format: mp3
|
format: mp3
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
emotion: 1
|
emotion: 1
|
||||||
OpenAITTS:
|
OpenAITTS:
|
||||||
# openai官方文本转语音服务,可支持全球大多数语种
|
# openai官方文本转语音服务,可支持全球大多数语种
|
||||||
@@ -428,7 +457,7 @@ TTS:
|
|||||||
voice: onyx
|
voice: onyx
|
||||||
# 语速范围0.25-4.0
|
# 语速范围0.25-4.0
|
||||||
speed: 1
|
speed: 1
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
CustomTTS:
|
CustomTTS:
|
||||||
# 自定义的TTS接口服务,请求参数可自定义
|
# 自定义的TTS接口服务,请求参数可自定义
|
||||||
# 要求接口使用GET方式请求,并返回音频文件
|
# 要求接口使用GET方式请求,并返回音频文件
|
||||||
@@ -443,7 +472,7 @@ TTS:
|
|||||||
headers: # 自定义请求头
|
headers: # 自定义请求头
|
||||||
# Authorization: Bearer xxxx
|
# Authorization: Bearer xxxx
|
||||||
format: wav # 接口返回的音频格式
|
format: wav # 接口返回的音频格式
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
# 模块测试配置
|
# 模块测试配置
|
||||||
module_test:
|
module_test:
|
||||||
test_sentences: # 自定义测试语句
|
test_sentences: # 自定义测试语句
|
||||||
@@ -466,4 +495,4 @@ manager:
|
|||||||
enabled: false
|
enabled: false
|
||||||
ip: 0.0.0.0
|
ip: 0.0.0.0
|
||||||
port: 8002
|
port: 8002
|
||||||
use_private_config: false
|
use_private_config: false
|
||||||
|
|||||||
@@ -7,9 +7,48 @@ from core.utils.util import read_config, get_project_dir
|
|||||||
default_config_file = "config.yaml"
|
default_config_file = "config.yaml"
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_directories(config):
|
||||||
|
"""确保所有配置路径存在"""
|
||||||
|
dirs_to_create = set()
|
||||||
|
project_dir = get_project_dir() # 获取项目根目录
|
||||||
|
# 日志文件目录
|
||||||
|
log_dir = config.get('log', {}).get('log_dir', 'tmp')
|
||||||
|
dirs_to_create.add(os.path.join(project_dir, log_dir))
|
||||||
|
|
||||||
|
# ASR/TTS模块输出目录
|
||||||
|
for module in ['ASR', 'TTS']:
|
||||||
|
for provider in config.get(module, {}).values():
|
||||||
|
output_dir = provider.get('output_dir', '')
|
||||||
|
if output_dir:
|
||||||
|
dirs_to_create.add(output_dir)
|
||||||
|
|
||||||
|
# 根据selected_module创建模型目录
|
||||||
|
selected_modules = config.get('selected_module', {})
|
||||||
|
for module_type in ['ASR', 'LLM', 'TTS']:
|
||||||
|
selected_provider = selected_modules.get(module_type)
|
||||||
|
if not selected_provider:
|
||||||
|
continue
|
||||||
|
provider_config = config.get(module_type, {}).get(selected_provider, {})
|
||||||
|
output_dir = provider_config.get('output_dir')
|
||||||
|
if output_dir:
|
||||||
|
full_model_dir = os.path.join(project_dir, output_dir)
|
||||||
|
dirs_to_create.add(full_model_dir)
|
||||||
|
|
||||||
|
# 统一创建目录(保留原data目录创建)
|
||||||
|
for dir_path in dirs_to_create:
|
||||||
|
try:
|
||||||
|
os.makedirs(dir_path, exist_ok=True)
|
||||||
|
except PermissionError:
|
||||||
|
print(f"警告:无法创建目录 {dir_path},请检查写入权限")
|
||||||
|
|
||||||
|
|
||||||
def get_config_file():
|
def get_config_file():
|
||||||
global default_config_file
|
global default_config_file
|
||||||
# 判断是否存在私有的配置文件
|
"""获取配置文件路径,优先使用私有配置文件(若存在)。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 配置文件路径(相对路径或默认路径)
|
||||||
|
"""
|
||||||
config_file = default_config_file
|
config_file = default_config_file
|
||||||
if os.path.exists(get_project_dir() + "data/." + default_config_file):
|
if os.path.exists(get_project_dir() + "data/." + default_config_file):
|
||||||
config_file = "data/." + default_config_file
|
config_file = "data/." + default_config_file
|
||||||
@@ -20,9 +59,13 @@ def load_config():
|
|||||||
"""加载配置文件"""
|
"""加载配置文件"""
|
||||||
parser = argparse.ArgumentParser(description="Server configuration")
|
parser = argparse.ArgumentParser(description="Server configuration")
|
||||||
config_file = get_config_file()
|
config_file = get_config_file()
|
||||||
|
|
||||||
parser.add_argument("--config_path", type=str, default=config_file)
|
parser.add_argument("--config_path", type=str, default=config_file)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return read_config(args.config_path)
|
config = read_config(args.config_path)
|
||||||
|
# 初始化目录
|
||||||
|
ensure_directories(config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def update_config(config):
|
def update_config(config):
|
||||||
@@ -67,7 +110,7 @@ def find_missing_keys(new_config, old_config, parent_key=''):
|
|||||||
def check_config_file():
|
def check_config_file():
|
||||||
old_config_file = get_config_file()
|
old_config_file = get_config_file()
|
||||||
global default_config_file
|
global default_config_file
|
||||||
if not old_config_file.startswith('data'):
|
if not 'data' in old_config_file:
|
||||||
return
|
return
|
||||||
old_config = read_config(get_project_dir() + old_config_file)
|
old_config = read_config(get_project_dir() + old_config_file)
|
||||||
new_config = read_config(get_project_dir() + default_config_file)
|
new_config = read_config(get_project_dir() + default_config_file)
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class ConnectionHandler:
|
|||||||
self.dialogue.put(Message(role="system", content=self.prompt))
|
self.dialogue.put(Message(role="system", content=self.prompt))
|
||||||
|
|
||||||
self.func_handler = FunctionHandler(self.config)
|
self.func_handler = FunctionHandler(self.config)
|
||||||
|
|
||||||
def change_system_prompt(self, prompt):
|
def change_system_prompt(self, prompt):
|
||||||
self.prompt = prompt
|
self.prompt = prompt
|
||||||
# 找到原来的role==system,替换原来的系统提示
|
# 找到原来的role==system,替换原来的系统提示
|
||||||
@@ -303,7 +303,7 @@ class ConnectionHandler:
|
|||||||
self.logger.bind(tag=TAG).debug(json.dumps(self.dialogue.get_llm_dialogue(), indent=4, ensure_ascii=False))
|
self.logger.bind(tag=TAG).debug(json.dumps(self.dialogue.get_llm_dialogue(), indent=4, ensure_ascii=False))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def chat_with_function_calling(self, query, tool_call = False):
|
def chat_with_function_calling(self, query, tool_call=False):
|
||||||
self.logger.bind(tag=TAG).debug(f"Chat with function calling start: {query}")
|
self.logger.bind(tag=TAG).debug(f"Chat with function calling start: {query}")
|
||||||
"""Chat with function calling for intent detection using streaming"""
|
"""Chat with function calling for intent detection using streaming"""
|
||||||
if self.isNeedAuth():
|
if self.isNeedAuth():
|
||||||
@@ -311,7 +311,7 @@ class ConnectionHandler:
|
|||||||
future = asyncio.run_coroutine_threadsafe(self._check_and_broadcast_auth_code(), self.loop)
|
future = asyncio.run_coroutine_threadsafe(self._check_and_broadcast_auth_code(), self.loop)
|
||||||
future.result()
|
future.result()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not tool_call:
|
if not tool_call:
|
||||||
self.dialogue.put(Message(role="user", content=query))
|
self.dialogue.put(Message(role="user", content=query))
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ class ConnectionHandler:
|
|||||||
|
|
||||||
response_message = []
|
response_message = []
|
||||||
processed_chars = 0 # 跟踪已处理的字符位置
|
processed_chars = 0 # 跟踪已处理的字符位置
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ class ConnectionHandler:
|
|||||||
future = asyncio.run_coroutine_threadsafe(self.memory.query_memory(query), self.loop)
|
future = asyncio.run_coroutine_threadsafe(self.memory.query_memory(query), self.loop)
|
||||||
memory_str = future.result()
|
memory_str = future.result()
|
||||||
|
|
||||||
#self.logger.bind(tag=TAG).info(f"对话记录: {self.dialogue.get_llm_dialogue_with_memory(memory_str)}")
|
# self.logger.bind(tag=TAG).info(f"对话记录: {self.dialogue.get_llm_dialogue_with_memory(memory_str)}")
|
||||||
|
|
||||||
# 使用支持functions的streaming接口
|
# 使用支持functions的streaming接口
|
||||||
llm_responses = self.llm.response_with_functions(
|
llm_responses = self.llm.response_with_functions(
|
||||||
@@ -351,8 +351,8 @@ class ConnectionHandler:
|
|||||||
content_arguments = ""
|
content_arguments = ""
|
||||||
for response in llm_responses:
|
for response in llm_responses:
|
||||||
content, tools_call = response
|
content, tools_call = response
|
||||||
if content is not None and len(content)>0:
|
if content is not None and len(content) > 0:
|
||||||
if len(response_message)<=0 and (content=="```" or "<tool_call>" in content):
|
if len(response_message) <= 0 and (content == "```" or "<tool_call>" in content):
|
||||||
tool_call_flag = True
|
tool_call_flag = True
|
||||||
|
|
||||||
if tools_call is not None:
|
if tools_call is not None:
|
||||||
@@ -366,7 +366,7 @@ class ConnectionHandler:
|
|||||||
|
|
||||||
if content is not None and len(content) > 0:
|
if content is not None and len(content) > 0:
|
||||||
if tool_call_flag:
|
if tool_call_flag:
|
||||||
content_arguments+=content
|
content_arguments += content
|
||||||
else:
|
else:
|
||||||
response_message.append(content)
|
response_message.append(content)
|
||||||
|
|
||||||
@@ -422,16 +422,17 @@ class ConnectionHandler:
|
|||||||
else:
|
else:
|
||||||
function_arguments = json.loads(function_arguments)
|
function_arguments = json.loads(function_arguments)
|
||||||
if not bHasError:
|
if not bHasError:
|
||||||
self.logger.bind(tag=TAG).info(f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}")
|
self.logger.bind(tag=TAG).info(
|
||||||
|
f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}")
|
||||||
function_call_data = {
|
function_call_data = {
|
||||||
"name": function_name,
|
"name": function_name,
|
||||||
"id": function_id,
|
"id": function_id,
|
||||||
"arguments": function_arguments
|
"arguments": function_arguments
|
||||||
}
|
}
|
||||||
result = self.func_handler.handle_llm_function_call(self, function_call_data)
|
result = self.func_handler.handle_llm_function_call(self, function_call_data)
|
||||||
self._handle_function_result(result, function_call_data, text_index+1)
|
self._handle_function_result(result, function_call_data, text_index + 1)
|
||||||
|
|
||||||
# 处理最后剩余的文本
|
# 处理最后剩余的文本
|
||||||
full_text = "".join(response_message)
|
full_text = "".join(response_message)
|
||||||
remaining_text = full_text[processed_chars:]
|
remaining_text = full_text[processed_chars:]
|
||||||
if remaining_text:
|
if remaining_text:
|
||||||
@@ -443,7 +444,7 @@ class ConnectionHandler:
|
|||||||
self.tts_queue.put(future)
|
self.tts_queue.put(future)
|
||||||
|
|
||||||
# 存储对话内容
|
# 存储对话内容
|
||||||
if len(response_message)>0:
|
if len(response_message) > 0:
|
||||||
self.dialogue.put(Message(role="assistant", content="".join(response_message)))
|
self.dialogue.put(Message(role="assistant", content="".join(response_message)))
|
||||||
|
|
||||||
self.llm_finish_task = True
|
self.llm_finish_task = True
|
||||||
@@ -452,32 +453,40 @@ class ConnectionHandler:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _handle_function_result(self, result, function_call_data, text_index):
|
def _handle_function_result(self, result, function_call_data, text_index):
|
||||||
if result.action == Action.RESPONSE: # 直接回复前端
|
if result.action == Action.RESPONSE: # 直接回复前端
|
||||||
text = result.response
|
text = result.response
|
||||||
self.recode_first_last_text(text, text_index)
|
self.recode_first_last_text(text, text_index)
|
||||||
future = self.executor.submit(self.speak_and_play, text, text_index)
|
future = self.executor.submit(self.speak_and_play, text, text_index)
|
||||||
self.tts_queue.put(future)
|
self.tts_queue.put(future)
|
||||||
self.dialogue.put(Message(role="assistant", content=text))
|
self.dialogue.put(Message(role="assistant", content=text))
|
||||||
elif result.action == Action.REQLLM: # 调用函数后再请求llm生成回复
|
elif result.action == Action.REQLLM: # 调用函数后再请求llm生成回复
|
||||||
|
|
||||||
text = result.result
|
text = result.result
|
||||||
if text is not None and len(text) > 0:
|
if text is not None and len(text) > 0:
|
||||||
function_id = function_call_data["id"]
|
function_id = function_call_data["id"]
|
||||||
function_name = function_call_data["name"]
|
function_name = function_call_data["name"]
|
||||||
function_arguments = function_call_data["arguments"]
|
function_arguments = function_call_data["arguments"]
|
||||||
self.dialogue.put(Message(role='assistant',
|
self.dialogue.put(Message(role='assistant',
|
||||||
tool_calls=[{"id": function_id,
|
tool_calls=[{"id": function_id,
|
||||||
"function": {"arguments": function_arguments,"name": function_name},
|
"function": {"arguments": function_arguments,
|
||||||
"type": 'function',
|
"name": function_name},
|
||||||
"index": 0}]))
|
"type": 'function',
|
||||||
|
"index": 0}]))
|
||||||
|
|
||||||
self.dialogue.put(Message(role="tool", tool_call_id=function_id, content=text))
|
self.dialogue.put(Message(role="tool", tool_call_id=function_id, content=text))
|
||||||
self.chat_with_function_calling(text, tool_call=True)
|
self.chat_with_function_calling(text, tool_call=True)
|
||||||
elif result.action == Action.NOTFOUND:
|
elif result.action == Action.NOTFOUND:
|
||||||
text = result.response
|
text = result.result
|
||||||
|
self.recode_first_last_text(text, text_index)
|
||||||
|
future = self.executor.submit(self.speak_and_play, text, text_index)
|
||||||
|
self.tts_queue.put(future)
|
||||||
|
self.dialogue.put(Message(role="assistant", content=text))
|
||||||
else:
|
else:
|
||||||
text = result.response
|
text = result.result
|
||||||
|
self.recode_first_last_text(text, text_index)
|
||||||
|
future = self.executor.submit(self.speak_and_play, text, text_index)
|
||||||
|
self.tts_queue.put(future)
|
||||||
|
self.dialogue.put(Message(role="assistant", content=text))
|
||||||
|
|
||||||
def _tts_priority_thread(self):
|
def _tts_priority_thread(self):
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ def create_iot_function(device_name, method_name, method_info):
|
|||||||
# 生成结果信息
|
# 生成结果信息
|
||||||
result = f"{device_name}的{method_name}操作执行成功"
|
result = f"{device_name}的{method_name}操作执行成功"
|
||||||
|
|
||||||
# 根据方法名尝试自动更新状态
|
|
||||||
await update_state_by_method(conn, device_name, method_name, params)
|
|
||||||
|
|
||||||
# 处理响应中可能的占位符
|
# 处理响应中可能的占位符
|
||||||
response = response_success
|
response = response_success
|
||||||
@@ -114,35 +112,6 @@ def create_iot_query_function(device_name, prop_name, prop_info):
|
|||||||
return wrap_async_function(iot_query_function)
|
return wrap_async_function(iot_query_function)
|
||||||
|
|
||||||
|
|
||||||
async def update_state_by_method(conn, device_name, method_name, params):
|
|
||||||
"""根据方法和参数自动更新设备状态"""
|
|
||||||
try:
|
|
||||||
# 规则1: 方法名为TurnOn,设置power为True
|
|
||||||
if method_name == "TurnOn":
|
|
||||||
await set_iot_status(conn, device_name, "power", True)
|
|
||||||
|
|
||||||
# 规则2: 方法名为TurnOff,设置power为False
|
|
||||||
elif method_name == "TurnOff":
|
|
||||||
await set_iot_status(conn, device_name, "power", False)
|
|
||||||
|
|
||||||
# 规则3: Set开头的方法,尝试更新对应参数
|
|
||||||
elif method_name.startswith("Set"):
|
|
||||||
# 从参数中找到可能的状态值
|
|
||||||
for param_name, param_value in params.items():
|
|
||||||
# 尝试更新对应名称的属性
|
|
||||||
await set_iot_status(conn, device_name, param_name, param_value)
|
|
||||||
|
|
||||||
# 其他方法,尝试直接从参数更新状态
|
|
||||||
else:
|
|
||||||
for param_name, param_value in params.items():
|
|
||||||
# 检查设备是否有此属性
|
|
||||||
status = await get_iot_status(conn, device_name, param_name)
|
|
||||||
if status is not None: # 属性存在
|
|
||||||
await set_iot_status(conn, device_name, param_name, param_value)
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).warning(f"自动更新状态失败: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
class IotDescriptor:
|
class IotDescriptor:
|
||||||
"""
|
"""
|
||||||
A class to represent an IoT descriptor.
|
A class to represent an IoT descriptor.
|
||||||
@@ -212,7 +181,7 @@ def register_device_type(descriptor):
|
|||||||
},
|
},
|
||||||
"response_failure": {
|
"response_failure": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "查询失败时的友好回复,例如:'无法获取{device_name}的{prop_info['description']}'"
|
"description": f"查询失败时的友好回复,例如:'无法获取{device_name}的{prop_info['description']}'"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["response_success", "response_failure"]
|
"required": ["response_success", "response_failure"]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from config.logger import setup_logging
|
|||||||
import json
|
import json
|
||||||
from core.handle.abortHandle import handleAbortMessage
|
from core.handle.abortHandle import handleAbortMessage
|
||||||
from core.handle.helloHandle import handleHelloMessage
|
from core.handle.helloHandle import handleHelloMessage
|
||||||
from core.handle.receiveAudioHandle import startToChat
|
from core.handle.receiveAudioHandle import startToChat, handleAudioMessage
|
||||||
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
|
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
@@ -31,6 +31,8 @@ async def handleTextMessage(conn, message):
|
|||||||
elif msg_json["state"] == "stop":
|
elif msg_json["state"] == "stop":
|
||||||
conn.client_have_voice = True
|
conn.client_have_voice = True
|
||||||
conn.client_voice_stop = True
|
conn.client_voice_stop = True
|
||||||
|
if len(conn.asr_audio) > 0:
|
||||||
|
await handleAudioMessage(conn, b'')
|
||||||
elif msg_json["state"] == "detect":
|
elif msg_json["state"] == "detect":
|
||||||
conn.asr_server_receive = False
|
conn.asr_server_receive = False
|
||||||
conn.client_have_voice = False
|
conn.client_have_voice = False
|
||||||
@@ -41,6 +43,6 @@ async def handleTextMessage(conn, message):
|
|||||||
if "descriptors" in msg_json:
|
if "descriptors" in msg_json:
|
||||||
await handleIotDescriptors(conn, msg_json["descriptors"])
|
await handleIotDescriptors(conn, msg_json["descriptors"])
|
||||||
if "states" in msg_json:
|
if "states" in msg_json:
|
||||||
await handleIotStatus(conn, msg_json["states"])
|
await handleIotStatus(conn, msg_json["states"])
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
await conn.websocket.send(message)
|
await conn.websocket.send(message)
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import time
|
||||||
|
import wave
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import io
|
||||||
|
from config.logger import setup_logging
|
||||||
|
from typing import Optional, Tuple, List
|
||||||
|
import uuid
|
||||||
|
import opuslib_next
|
||||||
|
from core.providers.asr.base import ASRProviderBase
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import sherpa_onnx
|
||||||
|
|
||||||
|
from modelscope.hub.file_download import model_file_download
|
||||||
|
|
||||||
|
TAG = __name__
|
||||||
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
||||||
|
# 捕获标准输出
|
||||||
|
class CaptureOutput:
|
||||||
|
def __enter__(self):
|
||||||
|
self._output = io.StringIO()
|
||||||
|
self._original_stdout = sys.stdout
|
||||||
|
sys.stdout = self._output
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
sys.stdout = self._original_stdout
|
||||||
|
self.output = self._output.getvalue()
|
||||||
|
self._output.close()
|
||||||
|
|
||||||
|
# 将捕获到的内容通过 logger 输出
|
||||||
|
if self.output:
|
||||||
|
logger.bind(tag=TAG).info(self.output.strip())
|
||||||
|
|
||||||
|
|
||||||
|
class ASRProvider(ASRProviderBase):
|
||||||
|
def __init__(self, config: dict, delete_audio_file: bool):
|
||||||
|
self.model_dir = config.get("model_dir")
|
||||||
|
self.output_dir = config.get("output_dir")
|
||||||
|
self.delete_audio_file = delete_audio_file
|
||||||
|
|
||||||
|
# 确保输出目录存在
|
||||||
|
os.makedirs(self.output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# 初始化模型文件路径
|
||||||
|
model_files = {
|
||||||
|
"model.int8.onnx": os.path.join(self.model_dir, "model.int8.onnx"),
|
||||||
|
"tokens.txt": os.path.join(self.model_dir, "tokens.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
# 下载并检查模型文件
|
||||||
|
try:
|
||||||
|
for file_name, file_path in model_files.items():
|
||||||
|
if not os.path.isfile(file_path):
|
||||||
|
logger.bind(tag=TAG).info(f"正在下载模型文件: {file_name}")
|
||||||
|
model_file_download(
|
||||||
|
model_id="pengzhendong/sherpa-onnx-sense-voice-zh-en-ja-ko-yue",
|
||||||
|
file_path=file_name,
|
||||||
|
local_dir=self.model_dir
|
||||||
|
)
|
||||||
|
|
||||||
|
if not os.path.isfile(file_path):
|
||||||
|
raise FileNotFoundError(f"模型文件下载失败: {file_path}")
|
||||||
|
|
||||||
|
self.model_path = model_files["model.int8.onnx"]
|
||||||
|
self.tokens_path = model_files["tokens.txt"]
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.bind(tag=TAG).error(f"模型文件处理失败: {str(e)}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
with CaptureOutput():
|
||||||
|
self.model = sherpa_onnx.OfflineRecognizer.from_sense_voice(
|
||||||
|
model=self.model_path,
|
||||||
|
tokens=self.tokens_path,
|
||||||
|
num_threads=2,
|
||||||
|
sample_rate=16000,
|
||||||
|
feature_dim=80,
|
||||||
|
decoding_method="greedy_search",
|
||||||
|
debug=False,
|
||||||
|
use_itn=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def save_audio_to_file(self, opus_data: List[bytes], session_id: str) -> str:
|
||||||
|
"""将Opus音频数据解码并保存为WAV文件"""
|
||||||
|
file_name = f"asr_{session_id}_{uuid.uuid4()}.wav"
|
||||||
|
file_path = os.path.join(self.output_dir, file_name)
|
||||||
|
|
||||||
|
decoder = opuslib_next.Decoder(16000, 1) # 16kHz, 单声道
|
||||||
|
pcm_data = []
|
||||||
|
|
||||||
|
for opus_packet in opus_data:
|
||||||
|
try:
|
||||||
|
pcm_frame = decoder.decode(opus_packet, 960) # 960 samples = 60ms
|
||||||
|
pcm_data.append(pcm_frame)
|
||||||
|
except opuslib_next.OpusError as e:
|
||||||
|
logger.bind(tag=TAG).error(f"Opus解码错误: {e}", exc_info=True)
|
||||||
|
|
||||||
|
with wave.open(file_path, "wb") as wf:
|
||||||
|
wf.setnchannels(1)
|
||||||
|
wf.setsampwidth(2) # 2 bytes = 16-bit
|
||||||
|
wf.setframerate(16000)
|
||||||
|
wf.writeframes(b"".join(pcm_data))
|
||||||
|
|
||||||
|
return file_path
|
||||||
|
|
||||||
|
def read_wave(self, wave_filename: str) -> Tuple[np.ndarray, int]:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
wave_filename:
|
||||||
|
Path to a wave file. It should be single channel and each sample should
|
||||||
|
be 16-bit. Its sample rate does not need to be 16kHz.
|
||||||
|
Returns:
|
||||||
|
Return a tuple containing:
|
||||||
|
- A 1-D array of dtype np.float32 containing the samples, which are
|
||||||
|
normalized to the range [-1, 1].
|
||||||
|
- sample rate of the wave file
|
||||||
|
"""
|
||||||
|
|
||||||
|
with wave.open(wave_filename) as f:
|
||||||
|
assert f.getnchannels() == 1, f.getnchannels()
|
||||||
|
assert f.getsampwidth() == 2, f.getsampwidth() # it is in bytes
|
||||||
|
num_samples = f.getnframes()
|
||||||
|
samples = f.readframes(num_samples)
|
||||||
|
samples_int16 = np.frombuffer(samples, dtype=np.int16)
|
||||||
|
samples_float32 = samples_int16.astype(np.float32)
|
||||||
|
|
||||||
|
samples_float32 = samples_float32 / 32768
|
||||||
|
return samples_float32, f.getframerate()
|
||||||
|
|
||||||
|
async def speech_to_text(self, opus_data: List[bytes], session_id: str) -> Tuple[Optional[str], Optional[str]]:
|
||||||
|
"""语音转文本主处理逻辑"""
|
||||||
|
file_path = None
|
||||||
|
try:
|
||||||
|
# 保存音频文件
|
||||||
|
start_time = time.time()
|
||||||
|
file_path = self.save_audio_to_file(opus_data, session_id)
|
||||||
|
logger.bind(tag=TAG).debug(f"音频文件保存耗时: {time.time() - start_time:.3f}s | 路径: {file_path}")
|
||||||
|
|
||||||
|
# 语音识别
|
||||||
|
start_time = time.time()
|
||||||
|
s = self.model.create_stream()
|
||||||
|
samples, sample_rate = self.read_wave(file_path)
|
||||||
|
s.accept_waveform(sample_rate, samples)
|
||||||
|
self.model.decode_stream(s)
|
||||||
|
text = s.result.text
|
||||||
|
logger.bind(tag=TAG).debug(f"语音识别耗时: {time.time() - start_time:.3f}s | 结果: {text}")
|
||||||
|
|
||||||
|
return text, file_path
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.bind(tag=TAG).error(f"语音识别失败: {e}", exc_info=True)
|
||||||
|
return "", None
|
||||||
|
|
||||||
|
finally:
|
||||||
|
# 文件清理逻辑
|
||||||
|
if self.delete_audio_file and file_path and os.path.exists(file_path):
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
logger.bind(tag=TAG).debug(f"已删除临时音频文件: {file_path}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.bind(tag=TAG).error(f"文件删除失败: {file_path} | 错误: {e}")
|
||||||
@@ -9,6 +9,7 @@ logger = setup_logging()
|
|||||||
class LLMProvider(LLMProviderBase):
|
class LLMProvider(LLMProviderBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.api_key = config["api_key"]
|
self.api_key = config["api_key"]
|
||||||
|
self.mode = config.get("mode", "chat-messages")
|
||||||
self.base_url = config.get("base_url", "https://api.dify.ai/v1").rstrip('/')
|
self.base_url = config.get("base_url", "https://api.dify.ai/v1").rstrip('/')
|
||||||
self.session_conversation_map = {} # 存储session_id和conversation_id的映射
|
self.session_conversation_map = {} # 存储session_id和conversation_id的映射
|
||||||
|
|
||||||
@@ -19,27 +20,59 @@ class LLMProvider(LLMProviderBase):
|
|||||||
conversation_id = self.session_conversation_map.get(session_id)
|
conversation_id = self.session_conversation_map.get(session_id)
|
||||||
|
|
||||||
# 发起流式请求
|
# 发起流式请求
|
||||||
with requests.post(
|
if self.mode == "chat-messages":
|
||||||
f"{self.base_url}/chat-messages",
|
request_json = {
|
||||||
headers={"Authorization": f"Bearer {self.api_key}"},
|
|
||||||
json={
|
|
||||||
"query": last_msg["content"],
|
"query": last_msg["content"],
|
||||||
"response_mode": "streaming",
|
"response_mode": "streaming",
|
||||||
"user": session_id,
|
"user": session_id,
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"conversation_id": conversation_id
|
"conversation_id": conversation_id
|
||||||
},
|
}
|
||||||
|
elif self.mode == "workflows/run":
|
||||||
|
request_json = {
|
||||||
|
"inputs": {"query": last_msg["content"]},
|
||||||
|
"response_mode": "streaming",
|
||||||
|
"user": session_id
|
||||||
|
}
|
||||||
|
elif self.mode == "completion-messages":
|
||||||
|
request_json = {
|
||||||
|
"inputs": {"query": last_msg["content"]},
|
||||||
|
"response_mode": "streaming",
|
||||||
|
"user": session_id
|
||||||
|
}
|
||||||
|
|
||||||
|
with requests.post(
|
||||||
|
f"{self.base_url}/{self.mode}",
|
||||||
|
headers={"Authorization": f"Bearer {self.api_key}"},
|
||||||
|
json=request_json,
|
||||||
stream=True
|
stream=True
|
||||||
) as r:
|
) as r:
|
||||||
for line in r.iter_lines():
|
if self.mode == "chat-messages":
|
||||||
if line.startswith(b'data: '):
|
for line in r.iter_lines():
|
||||||
event = json.loads(line[6:])
|
if line.startswith(b'data: '):
|
||||||
# 如果没有找到conversation_id,则获取此次conversation_id
|
event = json.loads(line[6:])
|
||||||
if not conversation_id:
|
# 如果没有找到conversation_id,则获取此次conversation_id
|
||||||
conversation_id = event.get('conversation_id')
|
if not conversation_id:
|
||||||
self.session_conversation_map[session_id] = conversation_id # 更新映射
|
conversation_id = event.get('conversation_id')
|
||||||
if event.get('answer'):
|
self.session_conversation_map[session_id] = conversation_id # 更新映射
|
||||||
yield event['answer']
|
if event.get('answer'):
|
||||||
|
yield event['answer']
|
||||||
|
elif self.mode == "workflows/run":
|
||||||
|
for line in r.iter_lines():
|
||||||
|
# logger.bind(tag=TAG).info(f"chat message response: {line}")
|
||||||
|
if line.startswith(b'data: '):
|
||||||
|
event = json.loads(line[6:])
|
||||||
|
if event.get('event') == "workflow_finished":
|
||||||
|
if event['data']['status'] == "succeeded":
|
||||||
|
yield event['data']['outputs']['answer']
|
||||||
|
else:
|
||||||
|
yield "【服务响应异常】"
|
||||||
|
elif self.mode == "completion-messages":
|
||||||
|
for line in r.iter_lines():
|
||||||
|
if line.startswith(b'data: '):
|
||||||
|
event = json.loads(line[6:])
|
||||||
|
if event.get('answer'):
|
||||||
|
yield event['answer']
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"Error in response generation: {e}")
|
logger.bind(tag=TAG).error(f"Error in response generation: {e}")
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import google.generativeai as genai
|
import google.generativeai as genai
|
||||||
from core.utils.util import check_model_key
|
from core.utils.util import check_model_key
|
||||||
from core.providers.llm.base import LLMProviderBase
|
from core.providers.llm.base import LLMProviderBase
|
||||||
|
from config.logger import setup_logging
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
TAG = __name__
|
||||||
|
logger = setup_logging()
|
||||||
|
|
||||||
class LLMProvider(LLMProviderBase):
|
class LLMProvider(LLMProviderBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""初始化Gemini LLM Provider"""
|
"""初始化Gemini LLM Provider"""
|
||||||
self.model_name = config.get("model_name", "gemini-1.5-pro")
|
self.model_name = config.get("model_name", "gemini-1.5-pro")
|
||||||
self.api_key = config.get("api_key")
|
self.api_key = config.get("api_key")
|
||||||
|
self.http_proxy=config.get("http_proxy")
|
||||||
|
self.https_proxy = config.get("https_proxy")
|
||||||
have_key = check_model_key("LLM", self.api_key)
|
have_key = check_model_key("LLM", self.api_key)
|
||||||
|
|
||||||
if not have_key:
|
if not have_key:
|
||||||
@@ -16,6 +21,19 @@ class LLMProvider(LLMProviderBase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 初始化Gemini客户端
|
# 初始化Gemini客户端
|
||||||
|
# 配置代理(如果提供了代理配置)
|
||||||
|
self.proxies=None
|
||||||
|
if self.http_proxy is not "" or self.https_proxy is not "":
|
||||||
|
|
||||||
|
self.proxies = {
|
||||||
|
"http": self.http_proxy,
|
||||||
|
"https": self.https_proxy,
|
||||||
|
}
|
||||||
|
logger.bind(tag=TAG).info(f"Gemini set proxys:{self.proxies}")
|
||||||
|
# 使用猴子补丁修改 google-generativeai 库的请求会话
|
||||||
|
|
||||||
|
# 使用 session 对象配置 genai
|
||||||
|
|
||||||
genai.configure(api_key=self.api_key)
|
genai.configure(api_key=self.api_key)
|
||||||
self.model = genai.GenerativeModel(self.model_name)
|
self.model = genai.GenerativeModel(self.model_name)
|
||||||
|
|
||||||
@@ -46,26 +64,54 @@ class LLMProvider(LLMProviderBase):
|
|||||||
if content:
|
if content:
|
||||||
chat_history.append({
|
chat_history.append({
|
||||||
"role": role,
|
"role": role,
|
||||||
"parts": [content]
|
"parts": [{"text":content}]
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# 获取当前消息
|
# 获取当前消息
|
||||||
current_msg = dialogue[-1]["content"]
|
current_msg = dialogue[-1]["content"]
|
||||||
|
|
||||||
# 创建新的聊天会话
|
# 构建请求体
|
||||||
chat = self.model.start_chat(history=chat_history)
|
request_body = {
|
||||||
|
"contents": chat_history + [{"role": "user", "parts": [{"text":current_msg}]}],
|
||||||
|
"generationConfig": self.generation_config
|
||||||
|
}
|
||||||
|
|
||||||
# 发送消息并获取流式响应
|
# 构建请求URL
|
||||||
response = chat.send_message(
|
url = f"https://generativelanguage.googleapis.com/v1beta/models/{self.model_name}:generateContent?key={self.api_key}"
|
||||||
current_msg,
|
|
||||||
stream=True,
|
|
||||||
generation_config=self.generation_config
|
|
||||||
)
|
|
||||||
|
|
||||||
# 处理流式响应
|
# 构建请求头
|
||||||
for chunk in response:
|
headers = {
|
||||||
if hasattr(chunk, 'text') and chunk.text:
|
"Content-Type": "application/json",
|
||||||
yield chunk.text
|
}
|
||||||
|
|
||||||
|
# 发送POST请求,经测试手动 request 无法使用 stream 模式
|
||||||
|
if self.proxies:
|
||||||
|
response = requests.post(url, headers=headers, json=request_body, stream=False, proxies=self.proxies)
|
||||||
|
try:
|
||||||
|
data = response.json() # 直接解析JSON
|
||||||
|
if 'candidates' in data and data['candidates']:
|
||||||
|
yield data['candidates'][0]['content']['parts'][0]['text']
|
||||||
|
else:
|
||||||
|
yield "未找到候选回复。"
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
yield f"JSON解码错误:{e}"
|
||||||
|
except Exception as e:
|
||||||
|
yield f"发生错误:{e}"
|
||||||
|
else:
|
||||||
|
logger.bind(tag=TAG).info(f"Gemini stream mode ")
|
||||||
|
chat = self.model.start_chat(history=chat_history)
|
||||||
|
|
||||||
|
# 发送消息并获取流式响应
|
||||||
|
response = chat.send_message(
|
||||||
|
current_msg,
|
||||||
|
stream=True,
|
||||||
|
generation_config=self.generation_config
|
||||||
|
)
|
||||||
|
# 处理流式响应
|
||||||
|
for chunk in response:
|
||||||
|
if hasattr(chunk, 'text') and chunk.text:
|
||||||
|
yield chunk.text
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = str(e)
|
error_msg = str(e)
|
||||||
@@ -78,3 +124,13 @@ class LLMProvider(LLMProviderBase):
|
|||||||
yield "【Gemini API key无效】"
|
yield "【Gemini API key无效】"
|
||||||
else:
|
else:
|
||||||
yield f"【Gemini服务响应异常: {error_msg}】"
|
yield f"【Gemini服务响应异常: {error_msg}】"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
yield f"请求失败:{e}"
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
yield f"JSON解码错误:{e}"
|
||||||
|
except Exception as e:
|
||||||
|
yield f"发生错误:{e}"
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import openai
|
import openai
|
||||||
|
from config.logger import setup_logging
|
||||||
from core.utils.util import check_model_key
|
from core.utils.util import check_model_key
|
||||||
from core.providers.llm.base import LLMProviderBase
|
from core.providers.llm.base import LLMProviderBase
|
||||||
|
|
||||||
|
TAG = __name__
|
||||||
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
||||||
class LLMProvider(LLMProviderBase):
|
class LLMProvider(LLMProviderBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
@@ -11,6 +15,8 @@ class LLMProvider(LLMProviderBase):
|
|||||||
self.base_url = config.get("base_url")
|
self.base_url = config.get("base_url")
|
||||||
else:
|
else:
|
||||||
self.base_url = config.get("url")
|
self.base_url = config.get("url")
|
||||||
|
self.max_tokens = config.get("max_tokens", 500)
|
||||||
|
|
||||||
check_model_key("LLM", self.api_key)
|
check_model_key("LLM", self.api_key)
|
||||||
self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url)
|
self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url)
|
||||||
|
|
||||||
@@ -19,9 +25,10 @@ class LLMProvider(LLMProviderBase):
|
|||||||
responses = self.client.chat.completions.create(
|
responses = self.client.chat.completions.create(
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
messages=dialogue,
|
messages=dialogue,
|
||||||
stream=True
|
stream=True,
|
||||||
|
max_tokens=self.max_tokens,
|
||||||
)
|
)
|
||||||
|
|
||||||
is_active = True
|
is_active = True
|
||||||
for chunk in responses:
|
for chunk in responses:
|
||||||
try:
|
try:
|
||||||
@@ -50,12 +57,12 @@ class LLMProvider(LLMProviderBase):
|
|||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
messages=dialogue,
|
messages=dialogue,
|
||||||
stream=True,
|
stream=True,
|
||||||
tools=functions,
|
tools=functions
|
||||||
)
|
)
|
||||||
|
|
||||||
for chunk in stream:
|
for chunk in stream:
|
||||||
yield chunk.choices[0].delta.content, chunk.choices[0].delta.tool_calls
|
yield chunk.choices[0].delta.content, chunk.choices[0].delta.tool_calls
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.bind(tag=TAG).error(f"Error in function call streaming: {e}")
|
logger.bind(tag=TAG).error(f"Error in function call streaming: {e}")
|
||||||
yield {"type": "content", "content": f"【OpenAI服务响应异常: {e}】"}
|
yield {"type": "content", "content": f"【OpenAI服务响应异常: {e}】"}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ logger = setup_logging()
|
|||||||
class TTSProviderBase(ABC):
|
class TTSProviderBase(ABC):
|
||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
self.delete_audio_file = delete_audio_file
|
self.delete_audio_file = delete_audio_file
|
||||||
self.output_file = config.get("output_file")
|
self.output_file = config.get("output_dir")
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate_filename(self):
|
def generate_filename(self):
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.headers = config.get("headers", {})
|
self.headers = config.get("headers", {})
|
||||||
self.params = config.get("params")
|
self.params = config.get("params")
|
||||||
self.format = config.get("format", "wav")
|
self.format = config.get("format", "wav")
|
||||||
self.output_file = config.get("output_file", "tmp/")
|
self.output_file = config.get("output_dir", "tmp/")
|
||||||
|
|
||||||
def generate_filename(self):
|
def generate_filename(self):
|
||||||
return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}.{self.format}")
|
return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}.{self.format}")
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.voice = config.get("voice", "alloy")
|
self.voice = config.get("voice", "alloy")
|
||||||
self.response_format = "wav"
|
self.response_format = "wav"
|
||||||
self.speed = config.get("speed", 1.0)
|
self.speed = config.get("speed", 1.0)
|
||||||
self.output_file = config.get("output_file", "tmp/")
|
self.output_file = config.get("output_dir", "tmp/")
|
||||||
check_model_key("TTS", self.api_key)
|
check_model_key("TTS", self.api_key)
|
||||||
|
|
||||||
def generate_filename(self, extension=".wav"):
|
def generate_filename(self, extension=".wav"):
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class TTSProvider(TTSProviderBase):
|
|||||||
self.volume_change_dB = config.get("volume_change_dB", 0)
|
self.volume_change_dB = config.get("volume_change_dB", 0)
|
||||||
self.speed_factor = config.get("speed_factor", 1)
|
self.speed_factor = config.get("speed_factor", 1)
|
||||||
self.stream = config.get("stream", False)
|
self.stream = config.get("stream", False)
|
||||||
self.output_file = config.get("output_file")
|
self.output_file = config.get("output_dir")
|
||||||
self.pitch_factor = config.get("pitch_factor", 0)
|
self.pitch_factor = config.get("pitch_factor", 0)
|
||||||
self.format = config.get("format", "mp3")
|
self.format = config.get("format", "mp3")
|
||||||
self.emotion = config.get("emotion", 1)
|
self.emotion = config.get("emotion", 1)
|
||||||
|
|||||||
Executable → Regular
+1
@@ -21,6 +21,7 @@ services:
|
|||||||
- ./data:/opt/xiaozhi-esp32-server/data
|
- ./data:/opt/xiaozhi-esp32-server/data
|
||||||
# 模型文件挂接,很重要
|
# 模型文件挂接,很重要
|
||||||
- ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt
|
- ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt
|
||||||
|
|
||||||
# #智控台还没开发好,还不能完全使用,会报很多错误,如果是非技术人员,请不要启用智控台服务
|
# #智控台还没开发好,还不能完全使用,会报很多错误,如果是非技术人员,请不要启用智控台服务
|
||||||
# xiaozhi-esp32-server-web:
|
# xiaozhi-esp32-server-web:
|
||||||
# image: ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest
|
# image: ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ get_time_function_desc = {
|
|||||||
"function": {
|
"function": {
|
||||||
"name": "get_time",
|
"name": "get_time",
|
||||||
"description": "获取当前时间、日期、星期几",
|
"description": "获取当前时间、日期、星期几",
|
||||||
"parameters": {}
|
'parameters': {'type': 'object', 'properties': {}, 'required': []}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ def raise_and_lower_the_volume(conn, action: str):
|
|||||||
|
|
||||||
async def _raise_and_lower_the_volume(conn, action):
|
async def _raise_and_lower_the_volume(conn, action):
|
||||||
volume = await get_iot_status(conn, "Speaker", "volume")
|
volume = await get_iot_status(conn, "Speaker", "volume")
|
||||||
|
if volume is None:
|
||||||
|
raise Exception("你的设备不支持音量控制")
|
||||||
if action == 'raise':
|
if action == 'raise':
|
||||||
volume += 10
|
volume += 10
|
||||||
elif action == 'lower':
|
elif action == 'lower':
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ loguru==0.7.3
|
|||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
cozepy==0.12.0
|
cozepy==0.12.0
|
||||||
mem0ai==0.1.62
|
mem0ai==0.1.62
|
||||||
bs4==0.0.2
|
bs4==0.0.2
|
||||||
|
modelscope==1.23.2
|
||||||
|
sherpa_onnx==1.11.0
|
||||||
|
|||||||
Reference in New Issue
Block a user