From 1a1d6c0835660236cfb84bc08f5ef06d17731779 Mon Sep 17 00:00:00 2001 From: jsonL <1775884984@qq.com> Date: Fri, 21 Mar 2025 13:00:17 +0800 Subject: [PATCH 01/38] agent api --- main/manager-api/.vscode/settings.json | 3 + .../agent/controller/AgentController.java | 149 ++++++++++++++++++ .../xiaozhi/modules/agent/dao/AgentDao.java | 10 ++ .../modules/agent/dto/AgentCreateDTO.java | 51 ++++++ .../modules/agent/dto/AgentUpdateDTO.java | 61 +++++++ .../modules/agent/entity/AgentEntity.java | 69 ++++++++ .../modules/agent/service/AgentService.java | 25 +++ .../agent/service/impl/AgentServiceImpl.java | 64 ++++++++ 8 files changed, 432 insertions(+) create mode 100644 main/manager-api/.vscode/settings.json create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/dao/AgentDao.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentCreateDTO.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentUpdateDTO.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/entity/AgentEntity.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentService.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java diff --git a/main/manager-api/.vscode/settings.json b/main/manager-api/.vscode/settings.json new file mode 100644 index 000000000..7b016a89f --- /dev/null +++ b/main/manager-api/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java new file mode 100644 index 000000000..9f2cb10d7 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java @@ -0,0 +1,149 @@ +package xiaozhi.modules.agent.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.web.bind.annotation.*; +import xiaozhi.common.constant.Constant; +import xiaozhi.common.page.PageData; +import xiaozhi.common.user.UserDetail; +import xiaozhi.common.utils.ConvertUtils; +import xiaozhi.common.utils.Result; +import xiaozhi.modules.agent.dto.AgentCreateDTO; +import xiaozhi.modules.agent.dto.AgentUpdateDTO; +import xiaozhi.modules.agent.entity.AgentEntity; +import xiaozhi.modules.agent.service.AgentService; +import xiaozhi.modules.security.user.SecurityUser; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Tag(name = "智能体管理") +@AllArgsConstructor +@RestController +@RequestMapping("/agent") +public class AgentController { + private final AgentService agentService; + + @GetMapping("/list") + @Operation(summary = "获取用户智能体列表") + @RequiresPermissions("sys:role:normal") + public Result> getUserAgents() { + UserDetail user = SecurityUser.getUser(); + List agents = agentService.getUserAgents(user.getId()); + return new Result>().ok(agents); + } + + @GetMapping("/all") + @Operation(summary = "智能体列表(管理员)") + @RequiresPermissions("sys:role:superAdmin") + @Parameters({ + @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true), + @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true), + }) + public Result> adminAgentList( + @Parameter(hidden = true) @RequestParam Map params) { + PageData page = agentService.adminAgentList(params); + return new Result>().ok(page); + } + + @GetMapping("/{id}") + @Operation(summary = "获取智能体详情") + @RequiresPermissions("sys:role:normal") + public Result getAgentById(@PathVariable("id") String id) { + AgentEntity agent = agentService.getAgentById(id); + return new Result().ok(agent); + } + + @PostMapping + @Operation(summary = "创建智能体") + @RequiresPermissions("sys:role:normal") + public Result save(@RequestBody @Valid AgentCreateDTO dto) { + AgentEntity entity = ConvertUtils.sourceToTarget(dto, AgentEntity.class); + + // 设置用户ID和创建者信息 + UserDetail user = SecurityUser.getUser(); + entity.setUserId(user.getId()); + entity.setCreator(user.getId()); + entity.setCreatedAt(new Date()); + + // ID、智能体编码和排序会在Service层自动生成 + agentService.insert(entity); + + return new Result<>(); + } + + @PutMapping + @Operation(summary = "更新智能体") + @RequiresPermissions("sys:role:normal") + public Result update(@RequestBody @Valid AgentUpdateDTO dto) { + // 先查询现有实体 + AgentEntity existingEntity = agentService.getAgentById(dto.getId()); + if (existingEntity == null) { + return new Result().error("智能体不存在"); + } + + // 只更新提供的非空字段 + if (dto.getAgentName() != null) { + existingEntity.setAgentName(dto.getAgentName()); + } + if (dto.getAgentCode() != null) { + existingEntity.setAgentCode(dto.getAgentCode()); + } + if (dto.getAsrModelId() != null) { + existingEntity.setAsrModelId(dto.getAsrModelId()); + } + if (dto.getVadModelId() != null) { + existingEntity.setVadModelId(dto.getVadModelId()); + } + if (dto.getLlmModelId() != null) { + existingEntity.setLlmModelId(dto.getLlmModelId()); + } + if (dto.getTtsModelId() != null) { + existingEntity.setTtsModelId(dto.getTtsModelId()); + } + if (dto.getTtsVoiceId() != null) { + existingEntity.setTtsVoiceId(dto.getTtsVoiceId()); + } + if (dto.getMemModelId() != null) { + existingEntity.setMemModelId(dto.getMemModelId()); + } + if (dto.getIntentModelId() != null) { + existingEntity.setIntentModelId(dto.getIntentModelId()); + } + if (dto.getSystemPrompt() != null) { + existingEntity.setSystemPrompt(dto.getSystemPrompt()); + } + if (dto.getLangCode() != null) { + existingEntity.setLangCode(dto.getLangCode()); + } + if (dto.getLanguage() != null) { + existingEntity.setLanguage(dto.getLanguage()); + } + if (dto.getSort() != null) { + existingEntity.setSort(dto.getSort()); + } + + // 设置更新者信息 + UserDetail user = SecurityUser.getUser(); + existingEntity.setUpdater(user.getId()); + existingEntity.setUpdatedAt(new Date()); + + agentService.updateById(existingEntity); + + return new Result<>(); + } + + @DeleteMapping("/{id}") + @Operation(summary = "删除智能体") + @RequiresPermissions("sys:role:normal") + public Result delete(@PathVariable String id) { + agentService.deleteById(id); + return new Result<>(); + } +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/dao/AgentDao.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/dao/AgentDao.java new file mode 100644 index 000000000..169346bfd --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/dao/AgentDao.java @@ -0,0 +1,10 @@ +package xiaozhi.modules.agent.dao; + +import org.apache.ibatis.annotations.Mapper; +import xiaozhi.common.dao.BaseDao; +import xiaozhi.modules.agent.entity.AgentEntity; + +@Mapper +public interface AgentDao extends BaseDao { + +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentCreateDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentCreateDTO.java new file mode 100644 index 000000000..302a55fb7 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentCreateDTO.java @@ -0,0 +1,51 @@ +package xiaozhi.modules.agent.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.io.Serializable; + +/** + * 智能体创建DTO + * 专用于新增智能体,不包含id、agentCode和sort字段,这些字段由系统自动生成/设置默认值 + */ +@Data +@Schema(description = "智能体创建对象") +public class AgentCreateDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "智能体名称", example = "客服助手") + @NotBlank(message = "智能体名称不能为空") + private String agentName; + + @Schema(description = "语音识别模型标识", example = "asr_model_01") + private String asrModelId; + + @Schema(description = "语音活动检测标识", example = "vad_model_01") + private String vadModelId; + + @Schema(description = "大语言模型标识", example = "llm_model_01") + private String llmModelId; + + @Schema(description = "语音合成模型标识", example = "tts_model_01") + private String ttsModelId; + + @Schema(description = "音色标识", example = "voice_01") + private String ttsVoiceId; + + @Schema(description = "记忆模型标识", example = "mem_model_01") + private String memModelId; + + @Schema(description = "意图模型标识", example = "intent_model_01") + private String intentModelId; + + @Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题") + private String systemPrompt; + + @Schema(description = "语言编码", example = "zh_CN") + private String langCode; + + @Schema(description = "交互语种", example = "中文") + private String language; +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentUpdateDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentUpdateDTO.java new file mode 100644 index 000000000..6445bddae --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/AgentUpdateDTO.java @@ -0,0 +1,61 @@ +package xiaozhi.modules.agent.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.io.Serializable; + +/** + * 智能体更新DTO + * 专用于更新智能体,id字段是必需的,用于标识要更新的智能体 + * 其他字段均为非必填,只更新提供的字段 + */ +@Data +@Schema(description = "智能体更新对象") +public class AgentUpdateDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "智能体唯一标识", example = "a1b2c3d4e5f6", required = true) + @NotBlank(message = "智能体ID不能为空") + private String id; + + @Schema(description = "智能体编码", example = "AGT_1234567890", required = false) + private String agentCode; + + @Schema(description = "智能体名称", example = "客服助手", required = false) + private String agentName; + + @Schema(description = "语音识别模型标识", example = "asr_model_02", required = false) + private String asrModelId; + + @Schema(description = "语音活动检测标识", example = "vad_model_02", required = false) + private String vadModelId; + + @Schema(description = "大语言模型标识", example = "llm_model_02", required = false) + private String llmModelId; + + @Schema(description = "语音合成模型标识", example = "tts_model_02", required = false) + private String ttsModelId; + + @Schema(description = "音色标识", example = "voice_02", required = false) + private String ttsVoiceId; + + @Schema(description = "记忆模型标识", example = "mem_model_02", required = false) + private String memModelId; + + @Schema(description = "意图模型标识", example = "intent_model_02", required = false) + private String intentModelId; + + @Schema(description = "角色设定参数", example = "你是一个专业的客服助手,负责回答用户问题并提供帮助", required = false) + private String systemPrompt; + + @Schema(description = "语言编码", example = "zh_CN", required = false) + private String langCode; + + @Schema(description = "交互语种", example = "中文", required = false) + private String language; + + @Schema(description = "排序", example = "1", required = false) + private Integer sort; +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/entity/AgentEntity.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/entity/AgentEntity.java new file mode 100644 index 000000000..6800aefb0 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/entity/AgentEntity.java @@ -0,0 +1,69 @@ +package xiaozhi.modules.agent.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("ai_agent") +@Schema(description = "智能体信息") +public class AgentEntity { + @Schema(description = "智能体唯一标识") + private String id; + + @Schema(description = "所属用户ID") + private Long userId; + + @Schema(description = "智能体编码") + private String agentCode; + + @Schema(description = "智能体名称") + private String agentName; + + @Schema(description = "语音识别模型标识") + private String asrModelId; + + @Schema(description = "语音活动检测标识") + private String vadModelId; + + @Schema(description = "大语言模型标识") + private String llmModelId; + + @Schema(description = "语音合成模型标识") + private String ttsModelId; + + @Schema(description = "音色标识") + private String ttsVoiceId; + + @Schema(description = "记忆模型标识") + private String memModelId; + + @Schema(description = "意图模型标识") + private String intentModelId; + + @Schema(description = "角色设定参数") + private String systemPrompt; + + @Schema(description = "语言编码") + private String langCode; + + @Schema(description = "交互语种") + private String language; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建者") + private Long creator; + + @Schema(description = "创建时间") + private Date createdAt; + + @Schema(description = "更新者") + private Long updater; + + @Schema(description = "更新时间") + private Date updatedAt; +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentService.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentService.java new file mode 100644 index 000000000..76439edea --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentService.java @@ -0,0 +1,25 @@ +package xiaozhi.modules.agent.service; + +import xiaozhi.common.page.PageData; +import xiaozhi.common.service.BaseService; +import xiaozhi.modules.agent.entity.AgentEntity; + +import java.util.List; +import java.util.Map; + +public interface AgentService extends BaseService { + /** + * 根据用户ID获取智能体列表 + */ + List getUserAgents(Long userId); + + /** + * 管理员获取所有智能体列表(分页) + */ + PageData adminAgentList(Map params); + + /** + * 获取智能体详情 + */ + AgentEntity getAgentById(String id); +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java new file mode 100644 index 000000000..b41310ab9 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java @@ -0,0 +1,64 @@ +package xiaozhi.modules.agent.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springframework.stereotype.Service; +import xiaozhi.common.page.PageData; +import xiaozhi.common.service.impl.BaseServiceImpl; +import xiaozhi.modules.agent.dao.AgentDao; +import xiaozhi.modules.agent.entity.AgentEntity; +import xiaozhi.modules.agent.service.AgentService; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Service +public class AgentServiceImpl extends BaseServiceImpl implements AgentService { + private final AgentDao agentDao; + + public AgentServiceImpl(AgentDao agentDao) { + this.agentDao = agentDao; + } + + @Override + public List getUserAgents(Long userId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("user_id", userId); + return agentDao.selectList(wrapper); + } + + @Override + public PageData adminAgentList(Map params) { + IPage page = agentDao.selectPage( + getPage(params, "sort", true), + new QueryWrapper<>() + ); + return new PageData<>(page.getRecords(), page.getTotal()); + } + + @Override + public AgentEntity getAgentById(String id) { + return agentDao.selectById(id); + } + + @Override + public boolean insert(AgentEntity entity) { + // 如果ID为空,自动生成一个UUID作为ID + if (entity.getId() == null || entity.getId().trim().isEmpty()) { + entity.setId(UUID.randomUUID().toString().replace("-", "")); + } + + // 如果智能体编码为空,自动生成一个带前缀的编码 + if (entity.getAgentCode() == null || entity.getAgentCode().trim().isEmpty()) { + entity.setAgentCode("AGT_" + System.currentTimeMillis()); + } + + // 如果排序字段为空,设置默认值0 + if (entity.getSort() == null) { + entity.setSort(0); + } + + return super.insert(entity); + } +} \ No newline at end of file From af038b7fc8b44f296e0bf420f8adcd83094d0c94 Mon Sep 17 00:00:00 2001 From: pengzhisheng Date: Sun, 23 Mar 2025 17:32:01 +0800 Subject: [PATCH 02/38] =?UTF-8?q?manager-api=20=E6=A8=A1=E5=9D=97=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20/api/v1/models/=20=E6=8E=A5=E5=8F=A3:=201=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A8=A1=E5=9E=8B=E9=85=8D=E7=BD=AE=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E6=8E=A5=E5=8F=A3=EF=BC=9B=202=E3=80=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20mapper=20=E7=9B=AE=E5=BD=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=9B=203=E3=80=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=E8=87=AA=E5=8A=A8=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B=E5=8C=96=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ModelConfigController.java~ | 2 + .../model/controller/ModelController.java | 98 ++++++++++++++ .../model/controller/ModelController.java~ | 106 +++++++++++++++ .../modules/model/dao/ModelConfigDao.java | 17 +++ .../modules/model/dao/ModelProviderDao.java | 14 ++ .../modules/model/dto/ModelConfigBodyDTO.java | 41 ++++++ .../modules/model/dto/ModelConfigDTO.java | 45 +++++++ .../modules/model/dto/ModelProviderDTO.java | 45 +++++++ .../model/entity/ModelConfigEntity.java | 59 +++++++++ .../model/entity/ModelProviderEntity.java | 46 +++++++ .../model/entity/ModelProviderEntity.java~ | 46 +++++++ .../model/service/ModelConfigService.java | 22 ++++ .../model/service/ModelProviderService.java | 23 ++++ .../service/impl/ModelConfigServiceImpl.java | 124 ++++++++++++++++++ .../impl/ModelProviderServiceImpl.java | 59 +++++++++ .../modules/security/oauth2/Oauth2Filter.java | 16 ++- .../service/impl/CaptchaServiceImpl.java | 4 + .../modules/timbre/service/TimbreService.java | 4 + .../service/impl/TimbreServiceImpl.java | 22 +++- .../src/main/resources/application-dev.yml | 5 + .../src/main/resources/application.yml | 10 +- .../src/main/resources/db/changelog/data.sql | 3 + .../src/main/resources/db/changelog/data.sql~ | 2 + .../resources/mapper/model/ModelConfigDao.xml | 10 ++ .../mapper/model/ModelProviderDao.xml | 9 ++ .../{sys => security}/SysUserTokenDao.xml | 0 26 files changed, 828 insertions(+), 4 deletions(-) create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelConfigController.java~ create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelConfigDao.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelProviderDao.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigBodyDTO.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigDTO.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelProviderDTO.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelProviderService.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java create mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java create mode 100644 main/manager-api/src/main/resources/db/changelog/data.sql create mode 100644 main/manager-api/src/main/resources/db/changelog/data.sql~ create mode 100644 main/manager-api/src/main/resources/mapper/model/ModelConfigDao.xml create mode 100644 main/manager-api/src/main/resources/mapper/model/ModelProviderDao.xml rename main/manager-api/src/main/resources/mapper/{sys => security}/SysUserTokenDao.xml (100%) diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelConfigController.java~ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelConfigController.java~ new file mode 100644 index 000000000..d1693839a --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelConfigController.java~ @@ -0,0 +1,2 @@ +package xiaozhi.modules.model.controller;public class ModelConfigController { +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java new file mode 100644 index 000000000..6cbfe1df6 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java @@ -0,0 +1,98 @@ +package xiaozhi.modules.model.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; +import xiaozhi.common.page.PageData; +import xiaozhi.common.utils.Result; +import xiaozhi.modules.model.dto.ModelConfigBodyDTO; +import xiaozhi.modules.model.dto.ModelConfigDTO; +import xiaozhi.modules.model.dto.ModelProviderDTO; +import xiaozhi.modules.model.service.ModelConfigService; +import xiaozhi.modules.model.service.ModelProviderService; + +import java.util.List; + +@AllArgsConstructor +@RestController +@RequestMapping("/models") +@Tag(name = "模型配置") +public class ModelController { + + private final ModelProviderService modelProviderService; + + private final ModelConfigService modelConfigService; + + + @GetMapping("/models/names") + @Operation(summary = "获取所有模型名称") + public Result> getModelNames(@RequestParam String modelType, + @RequestParam(required = false) String modelName) { + List modelNameList = modelConfigService.getModelCodeList(modelType, modelName); + return new Result>().ok(modelNameList); + } + + @GetMapping("/{modelType}/provideTypes") + @Operation(summary = "获取模型供应器列表") + public Result> getModelProviderList(@PathVariable String modelType) { + List modelProviderDTOS = modelProviderService.getListByModelType(modelType); + return new Result>().ok(modelProviderDTOS); + } + + @GetMapping("/{modelType}/{provideCode}/fields") + @Operation(summary = "获取模型供应器字段") + public Result> getModelProviderFields(@PathVariable String modelType, @PathVariable String provideCode) { + List fieldList = modelProviderService.getFieldList(modelType, provideCode); + return new Result>().ok(fieldList); + } + + + @GetMapping("/models/list") + @Operation(summary = "获取模型配置列表") + public Result> getModelConfigList(@RequestParam String modelType, + @RequestParam(required = false) String modelName, + @RequestParam(required = false, defaultValue = "0") Integer page, + @RequestParam(required = false,defaultValue = "10") Integer limit) { + PageData pageList = modelConfigService.getPageList(modelType, modelName, page, limit); + return new Result>().ok(pageList); + } + + + @PostMapping("/models/{modelType}/{provideCode}") + @Operation(summary = "新增模型配置") + public Result addModelConfig(@PathVariable String modelType, + @PathVariable String provideCode, + @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { + ModelConfigDTO modelConfigDTO = modelConfigService.add(modelType, provideCode, modelConfigBodyDTO); + return new Result().ok(modelConfigDTO); + } + + + @PutMapping("/models/{modelType}/{provideCode}/{id}") + @Operation(summary = "编辑模型配置") + public Result editModelConfig(@PathVariable String modelType, + @PathVariable String provideCode, + @PathVariable String id, + @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { + ModelConfigDTO modelConfigDTO = modelConfigService.edit(modelType, provideCode, id, modelConfigBodyDTO); + return new Result().ok(modelConfigDTO); + } + + + @DeleteMapping("/models/{modelType}/{provideCode}/{id}") + @Operation(summary = "删除模型配置") + public Result deleteModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @PathVariable String id) { + modelConfigService.delete(modelType, provideCode, id); + return new Result<>(); + } + + @GetMapping("/models/{modelName}/voices") + @Operation(summary = "获取模型音色") + public Result> getVoiceList(@PathVariable String modelName, + @RequestParam(required = false) String voiceName) { + + List voiceList = modelConfigService.getVoiceList(modelName, voiceName); + return new Result>().ok(voiceList); + } +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ new file mode 100644 index 000000000..bac2be570 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ @@ -0,0 +1,106 @@ +package xiaozhi.modules.model.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; +import xiaozhi.common.page.PageData; +import xiaozhi.common.utils.Result; +import xiaozhi.modules.model.dto.ModelConfigBodyDTO; +import xiaozhi.modules.model.dto.ModelConfigDTO; +import xiaozhi.modules.model.dto.ModelProviderDTO; +import xiaozhi.modules.model.service.ModelConfigService; +import xiaozhi.modules.model.service.ModelProviderService; + +import java.util.List; + +@AllArgsConstructor +@RestController +@RequestMapping("/models") +@Tag(name = "模型配置") +public class ModelController { + + private final ModelProviderService modelProviderService; + + private final ModelConfigService modelConfigService; + + + @GetMapping("/models/names") + @Operation(summary = "获取所有模型名称") + public Result> getModelNames(@RequestParam String modelType, + @RequestParam(required = false) String modelName) { + List modelNameList = modelConfigService.getModelCodeList(modelType, modelName); + return new Result>().ok(modelNameList); + } + + @GetMapping("/{modelType}/provideTypes") + @Operation(summary = "获取模型供应器列表") + public Result> getModelProviderList(@PathVariable String modelType) { + List modelProviderDTOS = modelProviderService.getListByModelType(modelType); + return new Result>().ok(modelProviderDTOS); + } + + @GetMapping("/{modelType}/{provideCode}/fields") + @Operation(summary = "获取模型供应器字段") + public Result> getModelProviderFields(@PathVariable String modelType, @PathVariable String provideCode) { + List fieldList = modelProviderService.getFieldList(modelType, provideCode); + return new Result>().ok(fieldList); + } + + /** + * get model config list, by modelType and modelName with page, limit + */ + @GetMapping("/models/list") + @Operation(summary = "获取模型配置列表") + public Result> getModelConfigList(@RequestParam String modelType, + @RequestParam(required = false) String modelName, + @RequestParam(required = false, defaultValue = "0") Integer page, + @RequestParam(required = false,defaultValue = "10") Integer limit) { + PageData pageList = modelConfigService.getPageList(modelType, modelName, page, limit); + return new Result>().ok(pageList); + } + + /** + * post model config, path params is modelType and provideCode, the body is ModelConfigDTO, but exclude modelType and provideCode + */ + @PostMapping("/models/{modelType}/{provideCode}") + @Operation(summary = "新增模型配置") + public Result addModelConfig(@PathVariable String modelType, + @PathVariable String provideCode, + @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { + ModelConfigDTO modelConfigDTO = modelConfigService.add(modelType, provideCode, modelConfigBodyDTO); + return new Result().ok(modelConfigDTO); + } + + /** + * put to edit model config, path params is modelType, provideCode and id, the body is ModelConfigDTO, but exclude modelType, provideCode and id + */ + @PutMapping("/models/{modelType}/{provideCode}/{id}") + @Operation(summary = "编辑模型配置") + public Result editModelConfig(@PathVariable String modelType, + @PathVariable String provideCode, + @PathVariable String id, + @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { + ModelConfigDTO modelConfigDTO = modelConfigService.edit(modelType, provideCode, id, modelConfigBodyDTO); + return new Result().ok(modelConfigDTO); + } + + /** + * delete model config, path params is modelType, provideCode and id + */ + @DeleteMapping("/models/{modelType}/{provideCode}/{id}") + @Operation(summary = "删除模型配置") + public Result deleteModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @PathVariable String id) { + modelConfigService.delete(modelType, provideCode, id); + return new Result<>(); + } + + @GetMapping("/models/{modelName}/voices") + @Operation(summary = "获取模型音色") + public Result> getVoiceList(@PathVariable String modelName, + @RequestParam(required = false) String voiceName) { + + List voiceList = modelConfigService.getVoiceList(modelName, voiceName); + return new Result>().ok(voiceList); + } +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelConfigDao.java b/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelConfigDao.java new file mode 100644 index 000000000..a35967e4b --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelConfigDao.java @@ -0,0 +1,17 @@ +package xiaozhi.modules.model.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import xiaozhi.common.dao.BaseDao; +import xiaozhi.modules.model.entity.ModelConfigEntity; + +import java.util.List; + +@Mapper +public interface ModelConfigDao extends BaseDao { + + /** + * get model_code list + */ + List getModelCodeList(@Param("modelType") String modelType, @Param("modelName") String modelName); +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelProviderDao.java b/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelProviderDao.java new file mode 100644 index 000000000..51042e8d9 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/dao/ModelProviderDao.java @@ -0,0 +1,14 @@ +package xiaozhi.modules.model.dao; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import xiaozhi.common.dao.BaseDao; +import xiaozhi.modules.model.entity.ModelProviderEntity; + +import java.util.List; + +@Mapper +public interface ModelProviderDao extends BaseDao { + + List getFieldList(@Param("modelType") String modelType, @Param("provideCode") String provideCode); +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigBodyDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigBodyDTO.java new file mode 100644 index 000000000..639e19a29 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigBodyDTO.java @@ -0,0 +1,41 @@ +package xiaozhi.modules.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; + +@Data +@Schema(description = "模型供应器/商") +public class ModelConfigBodyDTO { + + @Serial + private static final long serialVersionUID = 1L; + +// @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") +// private String modelType; +// + @Schema(description = "模型编码(如AliLLM、DoubaoTTS)") + private String modelCode; + + @Schema(description = "模型名称") + private String modelName; + + @Schema(description = "是否默认配置(0否 1是)") + private Integer isDefault; + + @Schema(description = "是否启用") + private Integer isEnabled; + + @Schema(description = "模型配置(JSON格式)") + private String configJson; + + @Schema(description = "官方文档链接") + private String docLink; + + @Schema(description = "备注") + private String remark; + + @Schema(description = "排序") + private Integer sort; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigDTO.java new file mode 100644 index 000000000..95a449211 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelConfigDTO.java @@ -0,0 +1,45 @@ +package xiaozhi.modules.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Schema(description = "模型供应器/商") +public class ModelConfigDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + private Long id; + + @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") + private String modelType; + + @Schema(description = "模型编码(如AliLLM、DoubaoTTS)") + private String modelCode; + + @Schema(description = "模型名称") + private String modelName; + + @Schema(description = "是否默认配置(0否 1是)") + private Integer isDefault; + + @Schema(description = "是否启用") + private Integer isEnabled; + + @Schema(description = "模型配置(JSON格式)") + private String configJson; + + @Schema(description = "官方文档链接") + private String docLink; + + @Schema(description = "备注") + private String remark; + + @Schema(description = "排序") + private Integer sort; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelProviderDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelProviderDTO.java new file mode 100644 index 000000000..acce30365 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/dto/ModelProviderDTO.java @@ -0,0 +1,45 @@ +package xiaozhi.modules.model.dto; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +@Schema(description = "模型供应器/商") +public class ModelProviderDTO implements Serializable { +// +// @Schema(description = "主键") +// private Long id; + + @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") + private String modelType; + + @Schema(description = "供应器类型") + private String providerCode; + + @Schema(description = "供应器名称") + private String name; + + @Schema(description = "供应器字段列表(JSON格式)") + @TableField(typeHandler = JacksonTypeHandler.class) + private String fields; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建者") + private Long creator; + + @Schema(description = "创建时间") + private Date createDate; + + @Schema(description = "更新者") + private Long updater; + + @Schema(description = "更新时间") + private Date updateDate; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java new file mode 100644 index 000000000..de60993ec --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java @@ -0,0 +1,59 @@ +package xiaozhi.modules.model.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + + +@Data +@TableName("ai_model_config") +@Schema(description = "模型配置表") +public class ModelConfigEntity { + + @Schema(description = "主键") + private Long id; + + @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") + private String modelType; + + @Schema(description = "模型编码(如AliLLM、DoubaoTTS)") + private String modelCode; + + @Schema(description = "模型名称") + private String modelName; + + @Schema(description = "是否默认配置(0否 1是)") + private Integer isDefault; + + @Schema(description = "是否启用") + private Integer isEnabled; + + @TableField(typeHandler = JacksonTypeHandler.class) + @Schema(description = "模型配置(JSON格式)") + private String configJson; + + @Schema(description = "官方文档链接") + private String docLink; + + @Schema(description = "备注") + private String remark; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建者") + private Long creator; + + @Schema(description = "创建时间") + private Date createDate; + + @Schema(description = "更新者") + private Long updater; + + @Schema(description = "更新时间") + private Date updateDate; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java new file mode 100644 index 000000000..b91ef99bf --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java @@ -0,0 +1,46 @@ +package xiaozhi.modules.model.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("ai_model_provider") +@Schema(description = "模型供应器表") +public class ModelProviderEntity { + + @Schema(description = "主键") + private Long id; + + @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") + private String modelType; + + @Schema(description = "供应器类型,如 openai、") + private String providerCode; + + @Schema(description = "供应器名称") + private String name; + + @Schema(description = "供应器字段列表(JSON格式)") + @TableField(typeHandler = JacksonTypeHandler.class) + private String fields; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建者") + private Long creator; + + @Schema(description = "创建时间") + private Date createDate; + + @Schema(description = "更新者") + private Long updater; + + @Schema(description = "更新时间") + private Date updateDate; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ new file mode 100644 index 000000000..179b3f4b7 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ @@ -0,0 +1,46 @@ +package xiaozhi.modules.model.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("ai_model_provider") +@Schema(description = "模型供应器表") +public class ModelProviderEntity { + + @Schema(description = "主键") + private Long id; + + @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") + private String modelType; + + @Schema(description = "供应器类型") + private String providerCode; + + @Schema(description = "供应器名称") + private String name; + + @Schema(description = "供应器字段列表(JSON格式)") + @TableField(typeHandler = JacksonTypeHandler.class) + private String fields; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建者") + private Long creator; + + @Schema(description = "创建时间") + private Date createDate; + + @Schema(description = "更新者") + private Long updater; + + @Schema(description = "更新时间") + private Date updateDate; +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java new file mode 100644 index 000000000..1911be78e --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java @@ -0,0 +1,22 @@ +package xiaozhi.modules.model.service; + +import xiaozhi.common.page.PageData; +import xiaozhi.modules.model.dto.ModelConfigBodyDTO; +import xiaozhi.modules.model.dto.ModelConfigDTO; + +import java.util.List; + +public interface ModelConfigService { + + List getModelCodeList(String modelType, String modelName); + + PageData getPageList(String modelType, String modelName, Integer page, Integer limit); + + ModelConfigDTO add(String modelType, String provideCode, ModelConfigBodyDTO modelConfigBodyDTO); + + ModelConfigDTO edit(String modelType, String provideCode, String id, ModelConfigBodyDTO modelConfigBodyDTO); + + void delete(String modelType, String provideCode, String id); + + List getVoiceList(String modelName, String voiceName); +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelProviderService.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelProviderService.java new file mode 100644 index 000000000..d0d221cff --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelProviderService.java @@ -0,0 +1,23 @@ +package xiaozhi.modules.model.service; + +import xiaozhi.modules.model.dto.ModelProviderDTO; +import xiaozhi.modules.model.entity.ModelProviderEntity; + +import java.util.List; + +public interface ModelProviderService { + +// List getModelNames(String modelType, String modelName); + + List getListByModelType(String modelType); + + ModelProviderDTO add(ModelProviderEntity modelProviderEntity); + + ModelProviderDTO edit(ModelProviderEntity modelProviderEntity); + + void delete(); + + List getList(String modelType, String provideCode); + + List getFieldList(String modelType, String provideCode); +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java new file mode 100644 index 000000000..c7ab9e2e4 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java @@ -0,0 +1,124 @@ +package xiaozhi.modules.model.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.AllArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import xiaozhi.common.constant.Constant; +import xiaozhi.common.exception.RenException; +import xiaozhi.common.page.PageData; +import xiaozhi.common.service.impl.BaseServiceImpl; +import xiaozhi.common.utils.ConvertUtils; +import xiaozhi.modules.model.dao.ModelConfigDao; +import xiaozhi.modules.model.dto.ModelConfigBodyDTO; +import xiaozhi.modules.model.dto.ModelConfigDTO; +import xiaozhi.modules.model.dto.ModelProviderDTO; +import xiaozhi.modules.model.entity.ModelConfigEntity; +import xiaozhi.modules.model.service.ModelConfigService; +import xiaozhi.modules.model.service.ModelProviderService; +import xiaozhi.modules.timbre.service.TimbreService; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@AllArgsConstructor +public class ModelConfigServiceImpl extends BaseServiceImpl implements ModelConfigService { + + private final ModelConfigDao modelConfigDao; + private final ModelProviderService modelProviderService; + private final TimbreService timbreService; + + private static final Logger logger = LoggerFactory.getLogger(ModelConfigServiceImpl.class); + + @Override + public List getModelCodeList(String modelType, String modelName) { + return modelConfigDao.getModelCodeList(modelType, modelName); + } + + @Override + public PageData getPageList(String modelType, String modelName, Integer page, Integer limit) { + Map params = new HashMap(); + params.put(Constant.PAGE, page); + params.put(Constant.LIMIT, limit); + IPage modelConfigEntityIPage = modelConfigDao.selectPage( + getPage(params, "sort", true), + new QueryWrapper() + .eq("model_type", modelType) + .like(StringUtils.isNotBlank(modelName), "model_name", modelName) + ); + return getPageData(modelConfigEntityIPage, ModelConfigDTO.class); + } + + @Override + public ModelConfigDTO add(String modelType, String provideCode, ModelConfigBodyDTO modelConfigBodyDTO) { + // 先验证有没有供应器 + if (StringUtils.isBlank(modelType) || StringUtils.isBlank(provideCode)) { + throw new RenException("modelType和provideCode不能为空"); + } + List providerList = modelProviderService.getList(modelType, provideCode); + if (CollectionUtil.isEmpty(providerList)) { + throw new RenException("供应器不存在"); + } + + // 再保存供应器提供的模型 + ModelConfigEntity modelConfigEntity = ConvertUtils.sourceToTarget(modelConfigBodyDTO, ModelConfigEntity.class); + modelConfigEntity.setModelType(modelType); + modelConfigDao.insert(modelConfigEntity); + return ConvertUtils.sourceToTarget(modelConfigEntity, ModelConfigDTO.class); + } + + @Override + public ModelConfigDTO edit(String modelType, String provideCode, String id, ModelConfigBodyDTO modelConfigBodyDTO) { + // 先验证有没有供应器 + if (StringUtils.isBlank(modelType) || StringUtils.isBlank(provideCode)) { + throw new RenException("modelType和provideCode不能为空"); + } + List providerList = modelProviderService.getList(modelType, provideCode); + if (CollectionUtil.isEmpty(providerList)) { + throw new RenException("供应器不存在"); + } + + // 再更新供应器提供的模型 + ModelConfigEntity modelConfigEntity = ConvertUtils.sourceToTarget(modelConfigBodyDTO, ModelConfigEntity.class); + modelConfigEntity.setId(Long.getLong(id)); + modelConfigEntity.setModelType(modelType); + modelConfigDao.updateById(modelConfigEntity); + return ConvertUtils.sourceToTarget(modelConfigEntity, ModelConfigDTO.class); + } + + @Override + public void delete(String modelType, String provideCode, String id) { + // 先验证有没有供应器 + if (StringUtils.isBlank(modelType) || StringUtils.isBlank(provideCode)) { + throw new RenException("modelType和provideCode不能为空"); + } + List providerList = modelProviderService.getList(modelType, provideCode); + if (CollectionUtil.isEmpty(providerList)) { + throw new RenException("供应器不存在"); + } + + modelConfigDao.deleteById(Long.getLong(id)); + } + + @Override + public List getVoiceList(String modelName, String voiceName) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("model_name", StringUtils.isBlank(modelName) ? "" : modelName); + queryWrapper.eq("model_type", "TTS"); + List modelConfigEntities = modelConfigDao.selectList(queryWrapper); + if (CollectionUtil.isEmpty(modelConfigEntities)) { + logger.warn("没有找到模型配置信息"); + return null; + } + ModelConfigEntity modelConfigEntity = modelConfigEntities.get(0); + Long id = modelConfigEntity.getId(); + + return timbreService.getVoiceNames(String.valueOf(id), voiceName); + } +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java new file mode 100644 index 000000000..042749d93 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java @@ -0,0 +1,59 @@ +package xiaozhi.modules.model.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.AllArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import xiaozhi.common.service.impl.BaseServiceImpl; +import xiaozhi.common.utils.ConvertUtils; +import xiaozhi.modules.model.dao.ModelProviderDao; +import xiaozhi.modules.model.dto.ModelProviderDTO; +import xiaozhi.modules.model.entity.ModelProviderEntity; +import xiaozhi.modules.model.service.ModelProviderService; + +import java.util.List; + +@Service +@AllArgsConstructor +public class ModelProviderServiceImpl extends BaseServiceImpl implements ModelProviderService { + + private final ModelProviderDao modelProviderDao; + + @Override + public List getListByModelType(String modelType) { + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("model_type", StringUtils.isBlank(modelType) ? "" : modelType); + List providerEntities = modelProviderDao.selectList(queryWrapper); + return ConvertUtils.sourceToTarget(providerEntities, ModelProviderDTO.class); + } + + @Override + public ModelProviderDTO add(ModelProviderEntity modelProviderEntity) { + return null; + } + + @Override + public ModelProviderDTO edit(ModelProviderEntity modelProviderEntity) { + return null; + } + + @Override + public void delete() { + + } + + @Override + public List getList(String modelType, String provideCode) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("model_type", StringUtils.isBlank(modelType) ? "" : modelType); + queryWrapper.eq("provide_code", StringUtils.isBlank(provideCode) ? "" : provideCode); + List providerEntities = modelProviderDao.selectList(queryWrapper); + return ConvertUtils.sourceToTarget(providerEntities, ModelProviderDTO.class); + } + + @Override + public List getFieldList(String modelType, String provideCode) { + return modelProviderDao.getFieldList(modelType, provideCode); + } +} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/security/oauth2/Oauth2Filter.java b/main/manager-api/src/main/java/xiaozhi/modules/security/oauth2/Oauth2Filter.java index 1520a8501..55e3fa036 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/security/oauth2/Oauth2Filter.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/security/oauth2/Oauth2Filter.java @@ -8,6 +8,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.web.filter.authc.AuthenticatingFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMethod; import xiaozhi.common.constant.Constant; import xiaozhi.common.exception.ErrorCode; @@ -24,12 +26,15 @@ import java.io.IOException; */ public class Oauth2Filter extends AuthenticatingFilter { + private static final Logger logger = LoggerFactory.getLogger(Oauth2Filter.class); + @Override protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception { //获取请求token String token = getRequestToken((HttpServletRequest) request); if (StringUtils.isBlank(token)) { + logger.warn("createToken:token is empty"); return null; } @@ -49,7 +54,15 @@ public class Oauth2Filter extends AuthenticatingFilter { protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { //获取请求token,如果token不存在,直接返回401 String token = getRequestToken((HttpServletRequest) request); + + // TODO 调试接口,临时取消登录限制,需要 token 参数的除外 + if (true) { + return true; + } + if (StringUtils.isBlank(token)) { + logger.warn("onAccessDenied:token is empty"); + HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setContentType("application/json;charset=utf-8"); httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); @@ -73,13 +86,14 @@ public class Oauth2Filter extends AuthenticatingFilter { httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin()); try { //处理登录失败的异常 + logger.error("onLoginFailure:登录失败!", e); Throwable throwable = e.getCause() == null ? e : e.getCause(); Result r = new Result().error(ErrorCode.UNAUTHORIZED, throwable.getMessage()); String json = JsonUtils.toJsonString(r); httpResponse.getWriter().print(json); } catch (IOException e1) { - + logger.error("onLoginFailure:登录失败! msg:{}", e1.getMessage(), e1); } return false; diff --git a/main/manager-api/src/main/java/xiaozhi/modules/security/service/impl/CaptchaServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/security/service/impl/CaptchaServiceImpl.java index fdc0d5b51..761ad1399 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/security/service/impl/CaptchaServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/security/service/impl/CaptchaServiceImpl.java @@ -4,8 +4,11 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.wf.captcha.SpecCaptcha; import com.wf.captcha.base.Captcha; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import xiaozhi.common.redis.RedisKeys; import xiaozhi.common.redis.RedisUtils; +import xiaozhi.modules.security.oauth2.Oauth2Realm; import xiaozhi.modules.security.service.CaptchaService; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; @@ -29,6 +32,7 @@ public class CaptchaServiceImpl implements CaptchaService { * Local Cache 5分钟过期 */ Cache localCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES).build(); + private static final Logger logger = LoggerFactory.getLogger(Oauth2Realm.class); @Override public void create(HttpServletResponse response, String uuid) throws IOException { diff --git a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java index 9b6c73eb2..044322e52 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java @@ -7,6 +7,8 @@ import xiaozhi.modules.timbre.dto.TimbrePageDTO; import xiaozhi.modules.timbre.entity.TimbreEntity; import xiaozhi.modules.timbre.vo.TimbreDetailsVO; +import java.util.List; + /** * 音色的业务层的定义 @@ -46,4 +48,6 @@ public interface TimbreService extends BaseService { * @param ids 需要被删除的音色id列表 */ void delete(Long[] ids); + + List getVoiceNames(String ttsModelId, String voiceName); } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java index ce3c2b7be..fa2731bd1 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java @@ -1,7 +1,9 @@ package xiaozhi.modules.timbre.service.impl; +import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,12 +14,13 @@ import xiaozhi.common.utils.ConvertUtils; import xiaozhi.modules.timbre.dao.TimbreDao; import xiaozhi.modules.timbre.dto.TimbreDataDTO; import xiaozhi.modules.timbre.dto.TimbrePageDTO; -import xiaozhi.modules.timbre.service.TimbreService; import xiaozhi.modules.timbre.entity.TimbreEntity; +import xiaozhi.modules.timbre.service.TimbreService; import xiaozhi.modules.timbre.vo.TimbreDetailsVO; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -25,9 +28,11 @@ import java.util.Map; * @author zjy * @since 2025-3-21 */ +@AllArgsConstructor @Service public class TimbreServiceImpl extends BaseServiceImpl implements TimbreService { + private final TimbreDao timbreDao; @Override public PageData page(TimbrePageDTO dto) { @@ -76,6 +81,21 @@ public class TimbreServiceImpl extends BaseServiceImpl baseDao.deleteBatchIds(Arrays.asList(ids)); } + @Override + public List getVoiceNames(String ttsModelId, String voiceName) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("ttsModelId", StringUtils.isBlank(ttsModelId) ? "" : ttsModelId); + if (StringUtils.isNotBlank(voiceName)) { + queryWrapper.like("name", voiceName); + } + List timbreEntities = timbreDao.selectList(queryWrapper); + if (CollectionUtil.isEmpty(timbreEntities)) { + return null; + } + + return timbreEntities.stream().map(TimbreEntity::getName).toList(); + } + /** * 处理是不是tts模型的id */ diff --git a/main/manager-api/src/main/resources/application-dev.yml b/main/manager-api/src/main/resources/application-dev.yml index a8fdf21f4..b093c3b27 100644 --- a/main/manager-api/src/main/resources/application-dev.yml +++ b/main/manager-api/src/main/resources/application-dev.yml @@ -11,6 +11,11 @@ jasypt: encryptor: password: P9Hx718z8L spring: + sql: + init: + #初始化数据库默认数据,对应sql文件必须存在 + data-locations: + - classpath:db/changelog/data.sql datasource: druid: #MySQL diff --git a/main/manager-api/src/main/resources/application.yml b/main/manager-api/src/main/resources/application.yml index 967f610ec..549595198 100644 --- a/main/manager-api/src/main/resources/application.yml +++ b/main/manager-api/src/main/resources/application.yml @@ -29,7 +29,7 @@ spring: database: 0 host: 127.0.0.1 port: 6379 - password: # 密码(默认为空) + password: # 密码(默认为空) timeout: 6000ms # 连接超时时长(毫秒) lettuce: pool: @@ -39,7 +39,13 @@ spring: min-idle: 5 # 连接池中的最小空闲连接 main: allow-bean-definition-overriding: true - + sql: + init: + mode: always + # 启动时自动执行创建表的sql,对应sql文件必须存在 + schema-locations: + - classpath:db/changelog/202503141335.sql + - classpath:db/changelog/202503141346.sql knife4j: enable: true basic: diff --git a/main/manager-api/src/main/resources/db/changelog/data.sql b/main/manager-api/src/main/resources/db/changelog/data.sql new file mode 100644 index 000000000..2bf5b65c6 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/data.sql @@ -0,0 +1,3 @@ +-- password: Admin123456. +INSERT INTO xiaozhi_esp32_server.sys_user (id, username, password, super_admin, status, create_date, updater, creator, update_date) +VALUES (1903735517485289473, 'admin', '$2a$10$VY1sr9hJc9pMVNACVSvA9eadivi.WcWBRLsPzGdLduv3LqOkxz98u', 1, 1, '2025-03-23 17:08:12', null, null, '2025-03-23 17:08:12'); diff --git a/main/manager-api/src/main/resources/db/changelog/data.sql~ b/main/manager-api/src/main/resources/db/changelog/data.sql~ new file mode 100644 index 000000000..0ee8626d9 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/data.sql~ @@ -0,0 +1,2 @@ +INSERT INTO xiaozhi_esp32_server.sys_user (id, username, password, super_admin, status, create_date, updater, creator, update_date) +VALUES (1903735517485289473, 'admin', '$2a$10$VY1sr9hJc9pMVNACVSvA9eadivi.WcWBRLsPzGdLduv3LqOkxz98u', 1, 1, '2025-03-23 17:08:12', null, null, '2025-03-23 17:08:12'); diff --git a/main/manager-api/src/main/resources/mapper/model/ModelConfigDao.xml b/main/manager-api/src/main/resources/mapper/model/ModelConfigDao.xml new file mode 100644 index 000000000..3f01ea5b7 --- /dev/null +++ b/main/manager-api/src/main/resources/mapper/model/ModelConfigDao.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/main/manager-api/src/main/resources/mapper/model/ModelProviderDao.xml b/main/manager-api/src/main/resources/mapper/model/ModelProviderDao.xml new file mode 100644 index 000000000..b17e24fce --- /dev/null +++ b/main/manager-api/src/main/resources/mapper/model/ModelProviderDao.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/main/manager-api/src/main/resources/mapper/sys/SysUserTokenDao.xml b/main/manager-api/src/main/resources/mapper/security/SysUserTokenDao.xml similarity index 100% rename from main/manager-api/src/main/resources/mapper/sys/SysUserTokenDao.xml rename to main/manager-api/src/main/resources/mapper/security/SysUserTokenDao.xml From 52a66ea304b9c81836f86dfcc73419b593b8f8e3 Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Mon, 24 Mar 2025 17:27:08 +0800 Subject: [PATCH 03/38] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/apis/module/user.js | 32 +-- .../manager-web/src/components/DeviceItem.vue | 5 +- main/manager-web/src/components/HeaderBar.vue | 29 +- main/manager-web/src/views/ModelConfig.vue | 247 +++++++++++------- main/manager-web/src/views/roleConfig.vue | 105 +++++--- 5 files changed, 256 insertions(+), 162 deletions(-) diff --git a/main/manager-web/src/apis/module/user.js b/main/manager-web/src/apis/module/user.js index 2e9bc6e29..b0db55b80 100755 --- a/main/manager-web/src/apis/module/user.js +++ b/main/manager-web/src/apis/module/user.js @@ -112,22 +112,6 @@ export default { }); }).send(); }, - // 获取设备配置 - getDeviceConfig(device_id, callback) { - RequestService.sendRequest() - .url(`${getServiceUrl()}/api/v1/user/configDevice/${device_id}`) - .method('GET') - .success((res) => { - RequestService.clearRequestTime(); - callback(res); - }) - .fail((err) => { - console.error('获取配置失败:', err); - RequestService.reAjaxFun(() => { - this.getDeviceConfig(device_id, callback); - }); - }).send(); - }, // 获取所有模型名称 getModelNames(callback) { RequestService.sendRequest() @@ -221,5 +205,21 @@ export default { }); }).send(); }, + // 获取智能体配置 + getDeviceConfig(deviceId, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/agent/${deviceId}`) + .method('GET') + .success((res) => { + RequestService.clearRequestTime(); + callback(res); + }) + .fail((err) => { + console.error('获取配置失败:', err); + RequestService.reAjaxFun(() => { + this.getDeviceConfig(deviceId, callback); + }); + }).send(); + }, } diff --git a/main/manager-web/src/components/DeviceItem.vue b/main/manager-web/src/components/DeviceItem.vue index cb8783886..4f651482b 100644 --- a/main/manager-web/src/components/DeviceItem.vue +++ b/main/manager-web/src/components/DeviceItem.vue @@ -17,7 +17,7 @@ 音色模型:{{ device.ttsVoiceName }}
-
+
配置角色
@@ -48,6 +48,9 @@ export default { methods: { handleDelete() { this.$emit('delete', this.device.agentId) + }, + handleConfigure() { + this.$router.push({ path: '/role-config', query: { agentId: this.device.agentId } }); } } } diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index a8dff30cb..2d349e7f4 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -4,14 +4,14 @@
-
+
智能体管理
-
+
用户管理
-
+
模型配置
@@ -104,26 +104,7 @@ export default { diff --git a/main/manager-web/src/views/roleConfig.vue b/main/manager-web/src/views/roleConfig.vue index d0f0000e4..d4fd94db2 100644 --- a/main/manager-web/src/views/roleConfig.vue +++ b/main/manager-web/src/views/roleConfig.vue @@ -17,7 +17,7 @@
- +
@@ -30,7 +30,7 @@
- + @@ -45,13 +45,13 @@
+ v-model="form.systemPrompt" maxlength="2000" show-word-limit/>
+ v-model="form.memModelld" maxlength="1000"/>
当前记忆(每次对话后重新生成)
@@ -60,7 +60,7 @@ 清除
-
{{ form.prompt.length }}/1000
+
{{ form.systemPrompt.length }}/1000
@@ -106,33 +106,35 @@ export default { return { deviceMac: 'CC:ba:97:11:a6:ac', form: { - name: "", - timbre: "", - introduction: "", - prompt: "", + agentCode:"", + agentName: "", + ttsVoiceId: "", + systemPrompt: "", + langCode:"", + language:"", + sort:"", model: { - tts: "", - vad: "", - asr: "", - llm: "", - memory:"", - intent:"" + ttsModelId: "", + vadModelId: "", + asrModelId:"", + llmModelId: "", + memModelId: "", + intentModelId: "", } }, - options: [ - { value: '选项1', label: '黄金糕' }, - { value: '选项2', label: '双皮奶' } - ], + options: [ + { value: '选项1', label: '黄金糕' }, + { value: '选项2', label: '双皮奶' } + ], models: [ - { label: '大语言模型(LLM)', key: 'llm' }, - { label: '语音识别(ASR)', key: 'asr' }, - { label: '语音活动检测模型(VAD)', key: 'vad' }, - { label: '语音合成模型(TTS)', key: 'tts' }, - { label: '意图识别模型(Intent)', key: 'intent' }, - { label: '记忆模型(Memory)', key: 'memory' } - ], + { 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: { @@ -148,20 +150,57 @@ export default { }).then(() => { // 重置表单 this.form = { - name: "", - timbre: "", - introduction: "", - prompt: "", - model: "" + agentCode:"", + agentName: "", + ttsVoiceId: "", + systemPrompt: "", + langCode:"", + language:"", + sort:"", + model: { + ttsModelId: "", + vadModelId: "", + asrModelId:"", + llmModelId: "", + memModelId: "", + intentModelId: "", + } } this.$message.success('配置已重置') }).catch(() => { }) }, - // 处理选择模板的逻辑 selectTemplate(template) { this.form.name = template; this.$message.success(`已选择模板:${template}`); + }, + fetchAgentConfig(agentId) { + import('@/apis/module/user').then(({ default: userApi }) => { + userApi.getDeviceConfig(agentId, ({ data }) => { + if (data.code === 0) { + this.form = { + ...this.form, + ...data.data, + model: { + ttsModelId: data.data.ttsModelId, + vadModelId: data.data.vadModelId, + asrModelId: data.data.asrModelId, + llmModelId: data.data.llmModelId, + memModelId: data.data.memModelId, + intentModelId: data.data.intentModelId + } + }; + } else { + this.$message.error(data.msg || '获取配置失败'); + } + }); + }); + } +}, + mounted() { + const agentId = this.$route.query.agentId; + if (agentId) { + this.fetchAgentConfig(agentId); } } } From 2001258ef47b8d7c39af25d4b914851a48155b18 Mon Sep 17 00:00:00 2001 From: Ran_Chen <1908198662@qq.com> Date: Mon, 24 Mar 2025 18:08:05 +0800 Subject: [PATCH 04/38] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/apis/module/user.js | 35 ++++- .../src/components/ChangePasswordDialog.vue | 141 ++++++++++++++++++ main/manager-web/src/components/HeaderBar.vue | 31 ++-- 3 files changed, 187 insertions(+), 20 deletions(-) create mode 100644 main/manager-web/src/components/ChangePasswordDialog.vue diff --git a/main/manager-web/src/apis/module/user.js b/main/manager-web/src/apis/module/user.js index 2e9bc6e29..0c917a630 100755 --- a/main/manager-web/src/apis/module/user.js +++ b/main/manager-web/src/apis/module/user.js @@ -43,9 +43,9 @@ export default { }) .fail(() => { RequestService.reAjaxFun(() => { - this.unbindDevice(device_id, callback); + this.unbindDevice(device_id, callback); }); - }).send() + }).send() }, // 绑定设备 bindDevice(deviceCode, callback) { @@ -71,9 +71,9 @@ export default { .method('GET') .type('blob') .header({ - 'Content-Type': 'image/gif', - 'Pragma': 'No-cache', - 'Cache-Control': 'no-cache' + 'Content-Type': 'image/gif', + 'Pragma': 'No-cache', + 'Cache-Control': 'no-cache' }) .success((res) => { RequestService.clearRequestTime(); @@ -173,7 +173,7 @@ export default { this.getAgentList(callback); }); }).send(); - }, + }, getUserInfo(callback) { RequestService.sendRequest() @@ -195,7 +195,7 @@ export default { RequestService.sendRequest() .url(`${getServiceUrl()}/api/v1/user/agent`) .method('POST') - .data({ name: agentName }) + .data({name: agentName}) .success((res) => { RequestService.clearRequestTime(); callback(res); @@ -221,5 +221,24 @@ export default { }); }).send(); }, - + // API接口代码修改 + changePassword(oldPassword, newPassword, successCallback, errorCallback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/change-password`) // 修改URL + .method('PUT') // 修改方法为PUT + .data({ + old_password: oldPassword, // 修改参数名 + new_password: newPassword // 修改参数名 + }) + .success((res) => { + RequestService.clearRequestTime(); + successCallback(res); + }) + .fail((error) => { + RequestService.reAjaxFun(() => { + this.changePassword(oldPassword, newPassword, successCallback, errorCallback); + }); + }) + .send(); + }, } diff --git a/main/manager-web/src/components/ChangePasswordDialog.vue b/main/manager-web/src/components/ChangePasswordDialog.vue new file mode 100644 index 000000000..19c20fd6b --- /dev/null +++ b/main/manager-web/src/components/ChangePasswordDialog.vue @@ -0,0 +1,141 @@ + + + + + \ No newline at end of file diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index a8dff30cb..dcaa3c0b2 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -25,25 +25,31 @@ - {{ userInfo.username }} + {{ userInfo.username || '加载中...' }} 个人中心 - 修改密码 + 修改密码 退出登录
+ + + @@ -181,4 +188,4 @@ export default { color: #3d4566; } - + \ No newline at end of file From f3562e091ff165086de4731341c5eaf8511b5ebd Mon Sep 17 00:00:00 2001 From: pengzhisheng Date: Mon, 24 Mar 2025 20:03:56 +0800 Subject: [PATCH 05/38] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9D=83=E9=99=90=EF=BC=8C=E4=BC=98=E5=8C=96=20model=20?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E4=B8=BB=E9=94=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/model/controller/ModelController.java | 10 +++++++++- .../modules/model/entity/ModelConfigEntity.java | 5 ++++- .../modules/model/entity/ModelProviderEntity.java | 5 ++++- .../manager-api/src/main/resources/application-dev.yml | 5 ----- main/manager-api/src/main/resources/application.yml | 7 ------- .../src/main/resources/db/changelog/data.sql | 3 --- 6 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 main/manager-api/src/main/resources/db/changelog/data.sql diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java index 6cbfe1df6..f743a7959 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java @@ -3,6 +3,7 @@ package xiaozhi.modules.model.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; import xiaozhi.common.page.PageData; import xiaozhi.common.utils.Result; @@ -24,9 +25,9 @@ public class ModelController { private final ModelConfigService modelConfigService; - @GetMapping("/models/names") @Operation(summary = "获取所有模型名称") + @RequiresPermissions("sys:role:superAdmin") public Result> getModelNames(@RequestParam String modelType, @RequestParam(required = false) String modelName) { List modelNameList = modelConfigService.getModelCodeList(modelType, modelName); @@ -35,6 +36,7 @@ public class ModelController { @GetMapping("/{modelType}/provideTypes") @Operation(summary = "获取模型供应器列表") + @RequiresPermissions("sys:role:superAdmin") public Result> getModelProviderList(@PathVariable String modelType) { List modelProviderDTOS = modelProviderService.getListByModelType(modelType); return new Result>().ok(modelProviderDTOS); @@ -42,6 +44,7 @@ public class ModelController { @GetMapping("/{modelType}/{provideCode}/fields") @Operation(summary = "获取模型供应器字段") + @RequiresPermissions("sys:role:superAdmin") public Result> getModelProviderFields(@PathVariable String modelType, @PathVariable String provideCode) { List fieldList = modelProviderService.getFieldList(modelType, provideCode); return new Result>().ok(fieldList); @@ -50,6 +53,7 @@ public class ModelController { @GetMapping("/models/list") @Operation(summary = "获取模型配置列表") + @RequiresPermissions("sys:role:superAdmin") public Result> getModelConfigList(@RequestParam String modelType, @RequestParam(required = false) String modelName, @RequestParam(required = false, defaultValue = "0") Integer page, @@ -61,6 +65,7 @@ public class ModelController { @PostMapping("/models/{modelType}/{provideCode}") @Operation(summary = "新增模型配置") + @RequiresPermissions("sys:role:superAdmin") public Result addModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { @@ -71,6 +76,7 @@ public class ModelController { @PutMapping("/models/{modelType}/{provideCode}/{id}") @Operation(summary = "编辑模型配置") + @RequiresPermissions("sys:role:superAdmin") public Result editModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @PathVariable String id, @@ -82,6 +88,7 @@ public class ModelController { @DeleteMapping("/models/{modelType}/{provideCode}/{id}") @Operation(summary = "删除模型配置") + @RequiresPermissions("sys:role:superAdmin") public Result deleteModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @PathVariable String id) { modelConfigService.delete(modelType, provideCode, id); return new Result<>(); @@ -89,6 +96,7 @@ public class ModelController { @GetMapping("/models/{modelName}/voices") @Operation(summary = "获取模型音色") + @RequiresPermissions("sys:role:normal") public Result> getVoiceList(@PathVariable String modelName, @RequestParam(required = false) String voiceName) { diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java index de60993ec..c98705f3a 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelConfigEntity.java @@ -1,6 +1,8 @@ package xiaozhi.modules.model.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import io.swagger.v3.oas.annotations.media.Schema; @@ -14,8 +16,9 @@ import java.util.Date; @Schema(description = "模型配置表") public class ModelConfigEntity { + @TableId(type = IdType.ASSIGN_UUID) @Schema(description = "主键") - private Long id; + private String id; @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") private String modelType; diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java index b91ef99bf..0c526b88f 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java @@ -1,6 +1,8 @@ package xiaozhi.modules.model.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import io.swagger.v3.oas.annotations.media.Schema; @@ -13,8 +15,9 @@ import java.util.Date; @Schema(description = "模型供应器表") public class ModelProviderEntity { + @TableId(type = IdType.ASSIGN_UUID) @Schema(description = "主键") - private Long id; + private String id; @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") private String modelType; diff --git a/main/manager-api/src/main/resources/application-dev.yml b/main/manager-api/src/main/resources/application-dev.yml index b093c3b27..a8fdf21f4 100644 --- a/main/manager-api/src/main/resources/application-dev.yml +++ b/main/manager-api/src/main/resources/application-dev.yml @@ -11,11 +11,6 @@ jasypt: encryptor: password: P9Hx718z8L spring: - sql: - init: - #初始化数据库默认数据,对应sql文件必须存在 - data-locations: - - classpath:db/changelog/data.sql datasource: druid: #MySQL diff --git a/main/manager-api/src/main/resources/application.yml b/main/manager-api/src/main/resources/application.yml index 549595198..03f6a0449 100644 --- a/main/manager-api/src/main/resources/application.yml +++ b/main/manager-api/src/main/resources/application.yml @@ -39,13 +39,6 @@ spring: min-idle: 5 # 连接池中的最小空闲连接 main: allow-bean-definition-overriding: true - sql: - init: - mode: always - # 启动时自动执行创建表的sql,对应sql文件必须存在 - schema-locations: - - classpath:db/changelog/202503141335.sql - - classpath:db/changelog/202503141346.sql knife4j: enable: true basic: diff --git a/main/manager-api/src/main/resources/db/changelog/data.sql b/main/manager-api/src/main/resources/db/changelog/data.sql deleted file mode 100644 index 2bf5b65c6..000000000 --- a/main/manager-api/src/main/resources/db/changelog/data.sql +++ /dev/null @@ -1,3 +0,0 @@ --- password: Admin123456. -INSERT INTO xiaozhi_esp32_server.sys_user (id, username, password, super_admin, status, create_date, updater, creator, update_date) -VALUES (1903735517485289473, 'admin', '$2a$10$VY1sr9hJc9pMVNACVSvA9eadivi.WcWBRLsPzGdLduv3LqOkxz98u', 1, 1, '2025-03-23 17:08:12', null, null, '2025-03-23 17:08:12'); From 8f1fbbdeef34cb0323c70b80b34eb15da423ffbe Mon Sep 17 00:00:00 2001 From: pengzhisheng Date: Mon, 24 Mar 2025 20:03:56 +0800 Subject: [PATCH 06/38] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9D=83=E9=99=90=EF=BC=8C=E4=BC=98=E5=8C=96=20model=20?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E4=B8=BB=E9=94=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/controller/ModelController.java~ | 106 ------------------ .../model/entity/ModelProviderEntity.java~ | 46 -------- 2 files changed, 152 deletions(-) delete mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ delete mode 100644 main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ deleted file mode 100644 index bac2be570..000000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java~ +++ /dev/null @@ -1,106 +0,0 @@ -package xiaozhi.modules.model.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.*; -import xiaozhi.common.page.PageData; -import xiaozhi.common.utils.Result; -import xiaozhi.modules.model.dto.ModelConfigBodyDTO; -import xiaozhi.modules.model.dto.ModelConfigDTO; -import xiaozhi.modules.model.dto.ModelProviderDTO; -import xiaozhi.modules.model.service.ModelConfigService; -import xiaozhi.modules.model.service.ModelProviderService; - -import java.util.List; - -@AllArgsConstructor -@RestController -@RequestMapping("/models") -@Tag(name = "模型配置") -public class ModelController { - - private final ModelProviderService modelProviderService; - - private final ModelConfigService modelConfigService; - - - @GetMapping("/models/names") - @Operation(summary = "获取所有模型名称") - public Result> getModelNames(@RequestParam String modelType, - @RequestParam(required = false) String modelName) { - List modelNameList = modelConfigService.getModelCodeList(modelType, modelName); - return new Result>().ok(modelNameList); - } - - @GetMapping("/{modelType}/provideTypes") - @Operation(summary = "获取模型供应器列表") - public Result> getModelProviderList(@PathVariable String modelType) { - List modelProviderDTOS = modelProviderService.getListByModelType(modelType); - return new Result>().ok(modelProviderDTOS); - } - - @GetMapping("/{modelType}/{provideCode}/fields") - @Operation(summary = "获取模型供应器字段") - public Result> getModelProviderFields(@PathVariable String modelType, @PathVariable String provideCode) { - List fieldList = modelProviderService.getFieldList(modelType, provideCode); - return new Result>().ok(fieldList); - } - - /** - * get model config list, by modelType and modelName with page, limit - */ - @GetMapping("/models/list") - @Operation(summary = "获取模型配置列表") - public Result> getModelConfigList(@RequestParam String modelType, - @RequestParam(required = false) String modelName, - @RequestParam(required = false, defaultValue = "0") Integer page, - @RequestParam(required = false,defaultValue = "10") Integer limit) { - PageData pageList = modelConfigService.getPageList(modelType, modelName, page, limit); - return new Result>().ok(pageList); - } - - /** - * post model config, path params is modelType and provideCode, the body is ModelConfigDTO, but exclude modelType and provideCode - */ - @PostMapping("/models/{modelType}/{provideCode}") - @Operation(summary = "新增模型配置") - public Result addModelConfig(@PathVariable String modelType, - @PathVariable String provideCode, - @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { - ModelConfigDTO modelConfigDTO = modelConfigService.add(modelType, provideCode, modelConfigBodyDTO); - return new Result().ok(modelConfigDTO); - } - - /** - * put to edit model config, path params is modelType, provideCode and id, the body is ModelConfigDTO, but exclude modelType, provideCode and id - */ - @PutMapping("/models/{modelType}/{provideCode}/{id}") - @Operation(summary = "编辑模型配置") - public Result editModelConfig(@PathVariable String modelType, - @PathVariable String provideCode, - @PathVariable String id, - @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { - ModelConfigDTO modelConfigDTO = modelConfigService.edit(modelType, provideCode, id, modelConfigBodyDTO); - return new Result().ok(modelConfigDTO); - } - - /** - * delete model config, path params is modelType, provideCode and id - */ - @DeleteMapping("/models/{modelType}/{provideCode}/{id}") - @Operation(summary = "删除模型配置") - public Result deleteModelConfig(@PathVariable String modelType, @PathVariable String provideCode, @PathVariable String id) { - modelConfigService.delete(modelType, provideCode, id); - return new Result<>(); - } - - @GetMapping("/models/{modelName}/voices") - @Operation(summary = "获取模型音色") - public Result> getVoiceList(@PathVariable String modelName, - @RequestParam(required = false) String voiceName) { - - List voiceList = modelConfigService.getVoiceList(modelName, voiceName); - return new Result>().ok(voiceList); - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ b/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ deleted file mode 100644 index 179b3f4b7..000000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/entity/ModelProviderEntity.java~ +++ /dev/null @@ -1,46 +0,0 @@ -package xiaozhi.modules.model.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.Date; - -@Data -@TableName("ai_model_provider") -@Schema(description = "模型供应器表") -public class ModelProviderEntity { - - @Schema(description = "主键") - private Long id; - - @Schema(description = "模型类型(Memory/ASR/VAD/LLM/TTS)") - private String modelType; - - @Schema(description = "供应器类型") - private String providerCode; - - @Schema(description = "供应器名称") - private String name; - - @Schema(description = "供应器字段列表(JSON格式)") - @TableField(typeHandler = JacksonTypeHandler.class) - private String fields; - - @Schema(description = "排序") - private Integer sort; - - @Schema(description = "创建者") - private Long creator; - - @Schema(description = "创建时间") - private Date createDate; - - @Schema(description = "更新者") - private Long updater; - - @Schema(description = "更新时间") - private Date updateDate; -} From eef7bb0cadabc3f4a057fd339a34f24f4110d6b6 Mon Sep 17 00:00:00 2001 From: zhisheng Date: Mon, 24 Mar 2025 20:13:14 +0800 Subject: [PATCH 07/38] Delete main/manager-api/src/main/resources/db/changelog/data.sql~ --- main/manager-api/src/main/resources/db/changelog/data.sql~ | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 main/manager-api/src/main/resources/db/changelog/data.sql~ diff --git a/main/manager-api/src/main/resources/db/changelog/data.sql~ b/main/manager-api/src/main/resources/db/changelog/data.sql~ deleted file mode 100644 index 0ee8626d9..000000000 --- a/main/manager-api/src/main/resources/db/changelog/data.sql~ +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO xiaozhi_esp32_server.sys_user (id, username, password, super_admin, status, create_date, updater, creator, update_date) -VALUES (1903735517485289473, 'admin', '$2a$10$VY1sr9hJc9pMVNACVSvA9eadivi.WcWBRLsPzGdLduv3LqOkxz98u', 1, 1, '2025-03-23 17:08:12', null, null, '2025-03-23 17:08:12'); From a3b3079b63f0924905163ff655859a14b2999752 Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Mon, 24 Mar 2025 22:41:32 +0800 Subject: [PATCH 08/38] =?UTF-8?q?=E5=AE=8C=E6=88=90=E2=80=9C=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=99=BA=E8=83=BD=E4=BD=93=E2=80=9C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/apis/module/user.js | 17 +++++ main/manager-web/src/views/roleConfig.vue | 92 +++++++++++++++-------- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/main/manager-web/src/apis/module/user.js b/main/manager-web/src/apis/module/user.js index b0db55b80..ddec6f049 100755 --- a/main/manager-web/src/apis/module/user.js +++ b/main/manager-web/src/apis/module/user.js @@ -221,5 +221,22 @@ export default { }); }).send(); }, + // 智能体配置 + updateAgentConfig(agentId, configData, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/user/agent/${agentId}`) + .method('PUT') + .data(configData) + .success((res) => { + RequestService.clearRequestTime(); + callback(res); + }) + .fail((err) => { + console.error('保存配置失败:', err); + RequestService.reAjaxFun(() => { + this.updateAgentConfig(agentId, configData, callback); + }); + }).send(); + }, } diff --git a/main/manager-web/src/views/roleConfig.vue b/main/manager-web/src/views/roleConfig.vue index d4fd94db2..e8fd0adec 100644 --- a/main/manager-web/src/views/roleConfig.vue +++ b/main/manager-web/src/views/roleConfig.vue @@ -1,6 +1,5 @@