diff --git a/docs/FAQ.md b/docs/FAQ.md index f18f02aa..d5785ef3 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -65,6 +65,7 @@ VAD: 3、[如何部署MQTT网关开启MQTT+UDP协议](./mqtt-gateway-integration.md)
4、[如何自动拉取本项目最新代码自动编译和启动](./dev-ops-integration.md)
5、[如何与Nginx集成](https://github.com/xinnan-tech/xiaozhi-esp32-server/issues/791)
+6、[修改代码后怎么编译自己的Docker镜像](./docker-build.md)
### 8、编译固件相关教程 1、[如何自己编译小智固件](./firmware-build.md)
@@ -85,6 +86,7 @@ VAD: 11、[如何集成PowerMem智能记忆](./powermem-integration.md)
12、[如何配置天气插件查询天气](./weather-integration.md)
13、[如何开启设备呼叫插件](./device-call-guide.md)
+14、[如何开启联网搜索功能](./web-search-integration.md)
### 10、数字人相关教程 1、[数字人digital-human启动方法](./digital-human-wakeword.md)
diff --git a/docs/docker-build.md b/docs/docker-build.md index 118ed1c9..91d45fd5 100644 --- a/docs/docker-build.md +++ b/docs/docker-build.md @@ -1,21 +1,74 @@ # 本地编译docker镜像方法 -现在本项目已经使用github自动编译docker功能,本文档是提供给有本地编译docker镜像需求的朋友准备的。 +现在本项目已经使用`github`的`自动编译docker镜像`功能,如果您拉取的是项目发行的镜像,您没有自己编译镜像的需求,那就忽略本文档。 -1、安装docker -``` +如果您修改了源码,然后想采用`docker`的方式部署运行,可以参照以下步骤操作: + +## 1、环境准备 + +安装docker: +```bash sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ``` -2、编译docker镜像 -``` -#进入项目根目录 -# 编译server -docker build -t xiaozhi-esp32-server:server_latest -f ./Dockerfile-server . -# 编译web -docker build -t xiaozhi-esp32-server:web_latest -f ./Dockerfile-web . -# 编译完成后,可以使用docker-compose启动项目 -# docker-compose.yml你需要修改成自己编译的镜像版本 +## 2、编译镜像 + +当你修改好代码后,需要编译新的镜像时,需要按照以下步骤操作: + +准备好你的`你的用户名`和`新的版本号`。 +- 这个`你的用户名`是你在`docker hub`注册的用户名,例如`xiaozhi`。当然,如果你不需要推送到`docker hub`,你可以自由定义。 +- 这个`新的版本号`是你编译的镜像版本,例如`1.2.3`,你可以根据需要自定义或者使用日期格式(例如`20260609`)主要是方便和现在运行的版本号做区分,同时也方便下次回忆你是什么时候构建的,不要和现在你本机运行的版本号相同。 + +进入`xiaozhi-esp32-server`项目根目录,编译 server 和 web 两个镜像: + +```bash +cd 项目根目录 + +# 编译server镜像 +docker build -f Dockerfile-server -t 你的用户名/xiaozhi-esp32-server:新的版本号 . + +# 编译web镜像 +docker build -f Dockerfile-web -t 你的用户名/xiaozhi-esp32-server-web:新的版本号 . + +``` + +## 3、修改docker-compose配置 + +```bash cd main/xiaozhi-server -docker compose up -d +``` + +编辑 `docker-compose_all.yml` 文件,将镜像版本替换为你刚才编译的版本: + +```yaml +services: + xiaozhi-esp32-server: + image: 你的用户名/xiaozhi-esp32-server:新的版本号 # 修改为你的镜像地址 + ... + + xiaozhi-esp32-server-web: + image: 你的用户名/xiaozhi-esp32-server-web:新的版本号 #修改为你的镜像地址 + ... +``` + +## 4、重启服务 + +```bash +# 停止旧容器 +docker compose -f docker-compose_all.yml down + +# 启动新容器 +docker compose -f docker-compose_all.yml up -d +``` + +## 5、验证 + +查看日志确认服务启动正常: + +```bash +# 查看server日志 +docker logs -f -n 50 xiaozhi-esp32-server + +# 查看web日志 +docker logs -f -n 50 xiaozhi-esp32-server-web ``` diff --git a/docs/web-search-integration.md b/docs/web-search-integration.md new file mode 100644 index 00000000..25dd546a --- /dev/null +++ b/docs/web-search-integration.md @@ -0,0 +1,71 @@ +# 联网搜索插件使用指南 + +## 功能简介 + +联网搜索插件 `web_search` 支持在对话过程中实时联网搜索信息并返回结果。插件支持两个搜索源:秘塔(Metaso)和Tavily,用户可根据需要选择其中一个。 + +## API Key申请指南 + +目前我们适配了`秘塔搜索`和`Tavily搜索`。 +- Tavily搜索:每个月1000次免费额度。 +- 秘塔搜索:拥有较为优质的国内数据源。 + +## API Key申请指南 + +### 方式一:使用秘塔搜索 + +- 访问 [秘塔搜索API](https://metaso.cn/search-api/api-keys),注册并登录账号 +- 在API密钥管理页面,点击"创建新的Key" +- 复制生成的API Key(以 `mk-` 为前缀),这是配置所需的关键信息 + +### 方式二:使用Tavily搜索 + +- 访问 [Tavily控制台](https://app.tavily.com/home),注册并登录账号 +- 在控制台中创建API Key +- 复制生成的API Key(以 `tvly-` 为前缀),这是配置所需的关键信息 + +## 配置方式 + +### 方式1. 使用智控台部署(推荐) + +- 登录智控台 +- 进入"配置角色"页面,选择要配置的智能体 +- 点击"编辑功能"按钮,在右侧参数配置区域找到"联网搜索"插件 +- 勾选"联网搜索" +- 填入搜索源(`metaso`或`tavily`),并将对应的`API Key`填入配置项 +- 保存配置,再保存智能体配置 + +### 方式2. 单模块xiaozhi-server部署 + +在 `data/.config.yaml` 中配置: + +- 将搜索源填入 `provider`,可选值为 `metaso` 或 `tavily` +- 将申请到的API Key填入 `api_key` + +```yaml +plugins: + web_search: + provider: "metaso" + api_key: "你的API Key" +``` + +如需自定义返回结果数量和工具描述,可额外配置 `max_results` 和 `description`: + +```yaml +plugins: + web_search: + provider: "metaso" + description: "联网搜索工具。当用户明确需要联网搜索问题时使用此工具。" + max_results: 5 + api_key: "你的API Key" +``` + +同时在 `functions` 列表中确保已启用 `web_search`: + +```yaml +plugins: + functions: + - web_search +``` + +配置完成后重启服务即可生效。 diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/McpJsonRpcResponse.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/McpJsonRpcResponse.java deleted file mode 100644 index 1bd667e6..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/dto/McpJsonRpcResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -package xiaozhi.modules.agent.dto; - -import lombok.Data; - -/** - * MCP JSON-RPC 响应 DTO - */ -@Data -public class McpJsonRpcResponse { - private String jsonrpc = "2.0"; - private Integer id; - private McpResult result; - private McpError error; - - public McpJsonRpcResponse() { - } - - @Data - public static class McpResult { - private String type; - private String message; - private String agent_id; - private McpTool[] tools; - - public McpResult() { - } - } - - @Data - public static class McpTool { - private String name; - private String description; - private Object inputSchema; - - public McpTool() { - } - } - - @Data - public static class McpError { - private Integer code; - private String message; - private Object data; - - public McpError() { - } - } -} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceBindDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceBindDTO.java deleted file mode 100644 index 3413c31b..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceBindDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package xiaozhi.modules.device.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; - -/** - * 设备绑定的DTO - * - * @author zjy - * @since 2025-3-28 - */ -@Data -@AllArgsConstructor -@Schema(description = "设备连接头信息") -public class DeviceBindDTO { - - @Schema(description = "mac地址") - private String macAddress; - - @Schema(description = "所属用户id") - private Long userId; - - @Schema(description = "智能体id") - private String agentId; - -} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/DocumentDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/DocumentDTO.java deleted file mode 100644 index 44b80582..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/DocumentDTO.java +++ /dev/null @@ -1,68 +0,0 @@ -package xiaozhi.modules.knowledge.dto; - -import java.io.Serializable; -import java.util.Date; -import java.util.Map; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -/** - * 文档 DTO - */ -@Data -@Schema(description = "知识库文档") -public class DocumentDTO implements Serializable { - private static final long serialVersionUID = 1L; - - @Schema(description = "本地ID") - private String id; - - @Schema(description = "知识库ID") - private String datasetId; - - @Schema(description = "RAGFlow文档ID") - private String documentId; - - @Schema(description = "文档名称") - private String name; - - @Schema(description = "文件大小") - private Long size; - - @Schema(description = "文件类型") - private String type; - - @Schema(description = "分块方法") - private String chunkMethod; - - @Schema(description = "解析配置") - private Map parserConfig; - - @Schema(description = "处理状态 (1:解析中 3:成功 4:失败)") - private Integer status; - - @Schema(description = "错误信息") - private String error; - - @Schema(description = "分块数量") - private Integer chunkCount; - - @Schema(description = "Token数量") - private Long tokenCount; - - @Schema(description = "是否启用") - private Integer enabled; - - @Schema(description = "创建时间") - private Date createdAt; - - @Schema(description = "更新时间") - private Date updatedAt; - - @Schema(description = "上传进度 (虚拟字段)") - private Double progress; - - @Schema(description = "缩略图/预览图 (虚拟字段)") - private String thumbnail; -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/KnowledgeBaseDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/KnowledgeBaseDTO.java index 39e89de8..5b772249 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/KnowledgeBaseDTO.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/KnowledgeBaseDTO.java @@ -67,4 +67,7 @@ public class KnowledgeBaseDTO implements Serializable { @Schema(description = "文档数量") private Integer documentCount; + + @Schema(description = "异常提示") + private String errorMessage; } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/agent/AgentDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/agent/AgentDTO.java deleted file mode 100644 index 171e981a..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/agent/AgentDTO.java +++ /dev/null @@ -1,421 +0,0 @@ -package xiaozhi.modules.knowledge.dto.agent; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.*; - -@Schema(description = "智能体 (Agent) 管理聚合 DTO") -public class AgentDTO { - - // ========== 1. Agent 管理 (CRUD) - 对应 RAGFlow_Agent接口详解 ========== - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Agent 创建请求") - public static class CreateReq implements Serializable { - @Schema(description = "Agent 标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "My Agent") - @NotBlank(message = "Agent 标题不能为空") - @JsonProperty("title") - private String title; - - @Schema(description = "DSL 定义 (画布 JSON)", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "DSL 定义不能为空") - @JsonProperty("dsl") - private Map dsl; - - @Schema(description = "描述", example = "这是一个测试 Agent") - @JsonProperty("description") - private String description; - - @Schema(description = "头像 URL", example = "http://example.com/avatar.png") - @JsonProperty("avatar") - private String avatar; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Agent 更新请求") - public static class UpdateReq implements Serializable { - @Schema(description = "Agent 标题", example = "Updated Agent") - @JsonProperty("title") - private String title; - - @Schema(description = "DSL 定义 (画布 JSON)") - @JsonProperty("dsl") - private Map dsl; - - @Schema(description = "描述") - @JsonProperty("description") - private String description; - - @Schema(description = "头像 URL") - @JsonProperty("avatar") - private String avatar; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Agent 列表请求") - public static class ListReq implements Serializable { - @Schema(description = "页码", defaultValue = "1") - @JsonProperty("page") - @Builder.Default - private Integer page = 1; - - @Schema(description = "每页大小", defaultValue = "10") - @JsonProperty("page_size") - @Builder.Default - private Integer pageSize = 10; - - @Schema(description = "排序字段", defaultValue = "update_time") - @JsonProperty("orderby") - @Builder.Default - private String orderby = "update_time"; - - @Schema(description = "是否降序", defaultValue = "true") - @JsonProperty("desc") - @Builder.Default - private Boolean desc = true; - - @Schema(description = "Agent ID 过滤") - @JsonProperty("id") - private String id; - - @Schema(description = "标题模糊搜索") - @JsonProperty("title") - private String title; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Agent 响应对象") - public static class AgentVO implements Serializable { - @Schema(description = "Agent ID") - @JsonProperty("id") - private String id; - - @Schema(description = "标题") - @JsonProperty("title") - private String title; - - @Schema(description = "描述") - @JsonProperty("description") - private String description; - - @Schema(description = "头像") - @JsonProperty("avatar") - private String avatar; - - @Schema(description = "DSL 定义") - @JsonProperty("dsl") - private Map dsl; - - @Schema(description = "创建者 ID") - @JsonProperty("user_id") - private String userId; - - @Schema(description = "画布分类") - @JsonProperty("canvas_category") - private String canvasCategory; - - @Schema(description = "创建时间 (时间戳)") - @JsonProperty("create_time") - private Long createTime; - - @Schema(description = "更新时间 (时间戳)") - @JsonProperty("update_time") - private Long updateTime; - } - - // ========== 2. Webhook 调试与追踪 - 对应 RAGFlow_Agent接口详解 ========== - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Webhook 触发请求 (参数动态)") - public static class WebhookTriggerReq implements Serializable { - @Schema(description = "输入变量", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "输入变量不能为空") - @JsonProperty("inputs") - private Map inputs; - - @Schema(description = "查询词", example = "Hello") - @JsonProperty("query") - private String query; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Webhook 追踪请求") - public static class WebhookTraceReq implements Serializable { - @Schema(description = "时间戳游标", example = "1700000000.0") - @JsonProperty("since_ts") - private Double sinceTs; - - @Schema(description = "Webhook ID") - @JsonProperty("webhook_id") - private String webhookId; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Webhook 追踪响应") - public static class WebhookTraceVO implements Serializable { - @Schema(description = "Webhook ID") - @JsonProperty("webhook_id") - private String webhookId; - - @Schema(description = "是否结束") - @JsonProperty("finished") - private Boolean finished; - - @Schema(description = "下一次查询的时间戳游标") - @JsonProperty("next_since_ts") - private Double nextSinceTs; - - @Schema(description = "事件列表") - @JsonProperty("events") - private List events; - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "追踪事件项") - public static class TraceEvent implements Serializable { - @Schema(description = "时间戳") - @JsonProperty("ts") - private Double ts; - - @Schema(description = "事件类型") - @JsonProperty("event") - private String event; - - @Schema(description = "事件数据") - @JsonProperty("data") - private Object data; - } - } - - // ========== 3. Agent 会话 (Session) - 对应 RAGFlow_Agent_Dify接口详解 ========== - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Session 创建请求") - public static class SessionCreateReq implements Serializable { - @Schema(description = "用户 ID") - @JsonProperty("user_id") - private String userId; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Session 列表请求") - public static class SessionListReq implements Serializable { - @Schema(description = "页码", defaultValue = "1") - @JsonProperty("page") - @Builder.Default - private Integer page = 1; - - @Schema(description = "每页大小", defaultValue = "10") - @JsonProperty("page_size") - @Builder.Default - private Integer pageSize = 10; - - @Schema(description = "排序字段", defaultValue = "create_time") - @JsonProperty("orderby") - @Builder.Default - private String orderby = "create_time"; - - @Schema(description = "是否降序", defaultValue = "true") - @JsonProperty("desc") - @Builder.Default - private Boolean desc = true; - - @Schema(description = "Session ID") - @JsonProperty("id") - private String id; - - @Schema(description = "用户 ID") - @JsonProperty("user_id") - private String userId; - - @Schema(description = "是否返回 DSL") - @JsonProperty("dsl") - @Builder.Default - private Boolean dsl = false; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Session 批量删除请求") - public static class SessionBatchDeleteReq implements Serializable { - @Schema(description = "会话 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED) - @JsonProperty("ids") - @NotEmpty(message = "ID列表不能为空") - private List ids; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Session 响应对象") - public static class SessionVO implements Serializable { - @Schema(description = "Session ID") - @JsonProperty("id") - private String id; - - @Schema(description = "Agent ID") - @JsonProperty("agent_id") - private String agentId; - - @Schema(description = "用户 ID") - @JsonProperty("user_id") - private String userId; - - @Schema(description = "来源") - @JsonProperty("source") - private String source; - - @Schema(description = "DSL 定义") - @JsonProperty("dsl") - private Map dsl; - - @Schema(description = "消息列表") - @JsonProperty("messages") - private List> messages; - } - - // ========== 4. Agent 对话 (Completion) - 对应 RAGFlow_Agent_Dify接口详解 ========== - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Completion 对话请求") - public static class CompletionReq implements Serializable { - @Schema(description = "会话 ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "会话 ID 不能为空") - @JsonProperty("session_id") - private String sessionId; - - @Schema(description = "用户问题") - @JsonProperty("question") - private String question; - - @Schema(description = "是否流式返回", defaultValue = "true") - @JsonProperty("stream") - @Builder.Default - private Boolean stream = true; - - @Schema(description = "是否返回追踪信息", defaultValue = "false") - @JsonProperty("return_trace") - @Builder.Default - private Boolean returnTrace = false; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Completion 对话响应") - public static class CompletionVO implements Serializable { - @Schema(description = "会话 ID") - @JsonProperty("id") - private String id; - - @Schema(description = "回复内容") - @JsonProperty("content") - private String content; - - @Schema(description = "引用来源") - @JsonProperty("reference") - private Map reference; - - @Schema(description = "追踪信息") - @JsonProperty("trace") - private List trace; - } - - // ========== 5. Dify 兼容检索 - 对应 RAGFlow_Agent_Dify接口详解 ========== - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Dify 兼容检索请求") - public static class DifyRetrievalReq implements Serializable { - @Schema(description = "知识库 ID") - @JsonProperty("knowledge_id") - private String knowledgeId; - - @Schema(description = "查询词") - @JsonProperty("query") - private String query; - - @Schema(description = "检索设置") - @JsonProperty("retrieval_setting") - private Map retrievalSetting; - - @Schema(description = "元数据过滤条件") - @JsonProperty("metadata_condition") - private Map metadataCondition; - - @Schema(description = "是否使用知识图谱") - @JsonProperty("use_kg") - private Boolean useKg; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "Dify 兼容检索响应") - public static class DifyRetrievalVO implements Serializable { - @Schema(description = "检索结果列表") - @JsonProperty("records") - private List records; - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "检索记录") - public static class Record implements Serializable { - @Schema(description = "内容") - @JsonProperty("content") - private String content; - - @Schema(description = "相似度分数") - @JsonProperty("score") - private Double score; - - @Schema(description = "标题") - @JsonProperty("title") - private String title; - - @Schema(description = "元数据") - @JsonProperty("metadata") - private Map metadata; - } - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/bot/BotDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/bot/BotDTO.java deleted file mode 100644 index 53d4ac43..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/bot/BotDTO.java +++ /dev/null @@ -1,126 +0,0 @@ -package xiaozhi.modules.knowledge.dto.bot; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.*; - -@Schema(description = "外部机器人 (Bot) 聚合 DTO") -public class BotDTO { - - // ========== 1. SearchBot (检索机器人) ========== - - // 对应 /api/v1/searchbots/ask - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "SearchBot 提问请求") - public static class SearchAskReq implements Serializable { - @Schema(description = "用户问题", requiredMode = Schema.RequiredMode.REQUIRED, example = "What is RAG?") - @NotBlank(message = "问题不能为空") - @JsonProperty("question") - private String question; - - @Schema(description = "是否返回引用", defaultValue = "false") - @JsonProperty("quote") - @Builder.Default - private Boolean quote = false; - - @Schema(description = "是否流式返回", defaultValue = "true") - @JsonProperty("stream") - @Builder.Default - private Boolean stream = true; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "SearchBot 提问响应") - public static class SearchAskVO implements Serializable { - @Schema(description = "回答内容") - @JsonProperty("answer") - private String answer; - - @Schema(description = "引用来源 (Value 结构通常对应 RetrievalDTO.HitVO)") - @JsonProperty("reference") - private Map reference; - } - - // 对应 /api/v1/searchbots/related_questions - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "相关问题请求") - public static class RelatedQuestionReq implements Serializable { - @Schema(description = "用户问题", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "问题不能为空") - @JsonProperty("question") - private String question; - } - - // 对应 /api/v1/searchbots/mindmap - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "思维导图请求") - public static class MindMapReq implements Serializable { - @Schema(description = "用户问题", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "问题不能为空") - @JsonProperty("question") - private String question; - } - - // ========== 2. AgentBot (嵌入式 Agent) ========== - - // 对应 /api/v1/agentbots/{id}/inputs - @Data - @Builder - @AllArgsConstructor - @Schema(description = "AgentBot 输入参数请求") - public static class AgentInputsReq implements Serializable { - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "AgentBot 输入参数定义响应") - public static class AgentInputsVO implements Serializable { - @Schema(description = "表单变量定义列表") - @JsonProperty("variables") - private List> variables; - } - - // 对应 /api/v1/agentbots/{id}/completions - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "AgentBot 对话请求") - public static class AgentCompletionReq implements Serializable { - @Schema(description = "输入参数值") - @JsonProperty("inputs") - private Map inputs; - - @Schema(description = "用户查询", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "查询内容不能为空") - @JsonProperty("question") - private String question; - - @Schema(description = "是否流式返回", defaultValue = "true") - @JsonProperty("stream") - @Builder.Default - private Boolean stream = true; - - @Schema(description = "会话 ID") - @JsonProperty("session_id") - private String sessionId; - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatCompletionRequest.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatCompletionRequest.java deleted file mode 100644 index 681b13d3..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatCompletionRequest.java +++ /dev/null @@ -1,50 +0,0 @@ -package xiaozhi.modules.knowledge.dto.chat; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -/** - * 聊天对话请求 DTO (OpenAI 兼容格式) - */ -@Data -@Schema(description = "聊天对话请求") -public class ChatCompletionRequest implements Serializable { - - @Schema(description = "模型标识 (对应 agent_id 或 bot_id)", requiredMode = Schema.RequiredMode.REQUIRED) - @JsonProperty("model") - private String model; - - @Schema(description = "对话消息列表", requiredMode = Schema.RequiredMode.REQUIRED) - @JsonProperty("messages") - private List messages; - - @Schema(description = "是否流式返回", defaultValue = "false") - @JsonProperty("stream") - private Boolean stream = false; - - @Schema(description = "温度系数 (0-1)", defaultValue = "0.7") - @JsonProperty("temperature") - private Double temperature; - - @Schema(description = "Session ID (可选,用于延续会话)") - @JsonProperty("session_id") - private String sessionId; - - @Schema(description = "其他RAGFlow特定参数 (可选)") - private Map extra; - - @Data - public static class Message implements Serializable { - @Schema(description = "角色 (system, user, assistant)", requiredMode = Schema.RequiredMode.REQUIRED) - private String role; - - @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED) - private String content; - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatDTO.java deleted file mode 100644 index d7ca8d60..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/chat/ChatDTO.java +++ /dev/null @@ -1,523 +0,0 @@ -package xiaozhi.modules.knowledge.dto.chat; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.*; - -/** - * 对话管理聚合 DTO - *

- * 容器类,内含对话助手、会话和消息的所有请求/响应对象。 - *

- */ -@Schema(description = "对话管理聚合 DTO") -public class ChatDTO { - - // ========== 1. 对话助手 (Assistant/Bot) 相关 ========== - - /** - * 提示词配置 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "提示词配置") - public static class PromptConfig implements Serializable { - - @Schema(description = "系统提示词", example = "你是一个专业的客服助手...") - @JsonProperty("prompt") - private String systemPrompt; - - @Schema(description = "开场白", example = "您好,我是您的智能助手,请问有什么可以帮您?") - private String opener; - - @Schema(description = "空结果回复", example = "抱歉,我没有找到相关信息。") - @JsonProperty("empty_response") - private String emptyResponse; - - @Schema(description = "是否展示引用", example = "true") - @JsonProperty("show_quote") - private Boolean quote; - - @Schema(description = "是否启用 TTS", example = "false") - private Boolean tts; - - @Schema(description = "相似度阈值 (0.0 - 1.0)", example = "0.2") - @JsonProperty("similarity_threshold") - private Float similarityThreshold; - - @Schema(description = "关键词相似度权重 (0.0 - 1.0)", example = "0.7") - @JsonProperty("keywords_similarity_weight") - private Float vectorSimilarityWeight; - - @Schema(description = "检索 Top N", example = "6") - @JsonProperty("top_n") - private Integer topK; - - @Schema(description = "Rerank 模型", example = "rerank_model_001") - @JsonProperty("rerank_model") - private String rerankId; - - @Schema(description = "是否启用多轮对话优化", example = "false") - @JsonProperty("refine_multiturn") - private Boolean refineMultigraph; - - @Schema(description = "变量列表") - private List> variables; - } - - /** - * LLM 配置 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "LLM 模型配置") - public static class LLMConfig implements Serializable { - - @NotBlank(message = "模型名称不能为空") - @Schema(description = "模型名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "gpt-4") - @JsonProperty("model_name") - private String modelName; - - @Schema(description = "温度参数 (0.0 - 2.0)", example = "0.7") - private Float temperature; - - @Schema(description = "Top P 采样", example = "0.9") - @JsonProperty("top_p") - private Float topP; - - @Schema(description = "最大 Token 数", example = "4096") - @JsonProperty("max_tokens") - private Integer maxTokens; - - @Schema(description = "存在惩罚", example = "0.0") - @JsonProperty("presence_penalty") - private Float presencePenalty; - - @Schema(description = "频率惩罚", example = "0.0") - @JsonProperty("frequency_penalty") - private Float frequencyPenalty; - } - - /** - * 创建助手请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "创建助手请求") - public static class AssistantCreateReq implements Serializable { - - @NotBlank(message = "助手名称不能为空") - @Schema(description = "助手名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "智能客服助手") - private String name; - - @Schema(description = "助手头像 (Base64 编码)", example = "") - private String avatar; - - @Schema(description = "关联的知识库 ID 列表", example = "[\"kb_001\", \"kb_002\"]") - @JsonProperty("dataset_ids") - private List datasetIds; - - @Schema(description = "助手描述", example = "这是一个智能客服助手") - private String description; - - @Schema(description = "LLM 模型配置") - @JsonProperty("llm") - private LLMConfig llm; - - @Schema(description = "提示词配置") - @JsonProperty("prompt") - private PromptConfig promptConfig; - } - - /** - * 更新助手请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "更新助手请求") - public static class AssistantUpdateReq implements Serializable { - - @Schema(description = "助手名称", example = "智能客服助手 V2") - private String name; - - @Schema(description = "助手头像 (Base64 编码)", example = "") - private String avatar; - - @Schema(description = "关联的知识库 ID 列表", example = "[\"kb_001\", \"kb_002\"]") - @JsonProperty("dataset_ids") - private List datasetIds; - - @Schema(description = "助手描述", example = "这是一个智能客服助手") - private String description; - - @Schema(description = "LLM 模型配置") - @JsonProperty("llm") - private LLMConfig llm; - - @Schema(description = "提示词配置") - @JsonProperty("prompt") - private PromptConfig promptConfig; - } - - /** - * 查询助手列表请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "查询助手列表请求") - public static class AssistantListReq implements Serializable { - - @Schema(description = "页码 (从 1 开始)", example = "1") - private Integer page; - - @Schema(description = "每页数量", example = "30") - @JsonProperty("page_size") - private Integer pageSize; - - @Schema(description = "按名称过滤 (模糊匹配)", example = "客服") - private String name; - - @Schema(description = "排序字段: create_time / update_time", example = "create_time") - private String orderby; - - @Schema(description = "是否降序", example = "true") - private Boolean desc; - - @Schema(description = "按 ID 精确筛选", example = "assistant_001") - private String id; - } - - /** - * 助手详情 VO - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "助手详情 VO") - public static class AssistantVO implements Serializable { - - @Schema(description = "助手 ID", example = "assistant_001") - private String id; - - @Schema(description = "租户 ID", example = "tenant_001") - @JsonProperty("tenant_id") - private String tenantId; - - @Schema(description = "助手名称", example = "智能客服助手") - private String name; - - @Schema(description = "助手头像", example = "") - private String avatar; - - @Schema(description = "关联的知识库 ID 列表") - @JsonProperty("dataset_ids") - private List datasetIds; - - @Schema(description = "关联的知识库列表 (详情)") - private List datasets; - - @Schema(description = "助手描述") - private String description; - - @Schema(description = "LLM 模型配置") - @JsonProperty("llm") - private LLMConfig llm; - - @Schema(description = "提示词配置") - @JsonProperty("prompt") - private PromptConfig promptConfig; - - @Schema(description = "创建时间 (时间戳)", example = "1700000000000") - @JsonProperty("create_time") - private Long createTime; - - @Schema(description = "更新时间 (时间戳)", example = "1700000001000") - @JsonProperty("update_time") - private Long updateTime; - } - - /** - * 删除助手请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "删除助手请求") - public static class AssistantDeleteReq implements Serializable { - - @Schema(description = "要删除的助手 ID 列表", example = "[\"assistant_001\", \"assistant_002\"]") - private List ids; - } - - // ========== 2. 会话 (Session) 相关 ========== - - /** - * 创建会话请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "创建会话请求") - public static class SessionCreateReq implements Serializable { - - @Schema(description = "会话名称", example = "技术咨询会话") - private String name; - - @Schema(description = "用户 ID", example = "user_001") - @JsonProperty("user_id") - private String userId; - } - - /** - * 更新会话请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "更新会话请求") - public static class SessionUpdateReq implements Serializable { - - @Schema(description = "会话名称", example = "技术咨询会话 - 更新") - private String name; - } - - /** - * 查询会话列表请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "查询会话列表请求") - public static class SessionListReq implements Serializable { - - @Schema(description = "助手 ID", example = "assistant_001") - @JsonProperty("assistant_id") - private String assistantId; - - @Schema(description = "页码 (从 1 开始)", example = "1") - private Integer page; - - @Schema(description = "每页数量", example = "30") - @JsonProperty("page_size") - private Integer pageSize; - - @Schema(description = "按名称过滤", example = "技术") - private String name; - - @Schema(description = "排序字段", example = "create_time") - private String orderby; - - @Schema(description = "是否降序", example = "true") - private Boolean desc; - - @Schema(description = "会话 ID 精确筛选", example = "session_001") - private String id; - - @Schema(description = "用户标识筛选", example = "user_001") - @JsonProperty("user_id") - private String userId; - } - - /** - * 会话详情 VO - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "会话详情 VO") - public static class SessionVO implements Serializable { - - @Schema(description = "会话 ID", example = "session_001") - private String id; - - @Schema(description = "助手 ID", example = "assistant_001") - @JsonProperty("chat_id") - private String chatId; - - @Schema(description = "助手 ID (兼容旧版)", example = "assistant_001") - @JsonProperty("assistant_id") - private String assistantId; - - @Schema(description = "会话名称", example = "技术咨询会话") - private String name; - - @Schema(description = "创建时间 (时间戳)", example = "1700000000000") - @JsonProperty("create_time") - private Long createTime; - - @Schema(description = "更新时间 (时间戳)", example = "1700000001000") - @JsonProperty("update_time") - private Long updateTime; - - @Schema(description = "创建日期", example = "2024-05-01 10:00:00") - @JsonProperty("create_date") - private String createDate; - - @Schema(description = "更新日期", example = "2024-05-01 10:00:00") - @JsonProperty("update_date") - private String updateDate; - - @Schema(description = "用户 ID", example = "user_001") - @JsonProperty("user_id") - private String userId; - - @Schema(description = "对话历史消息列表") - private List> messages; - } - - /** - * 删除会话请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "删除会话请求") - public static class SessionDeleteReq implements Serializable { - - @Schema(description = "要删除的会话 ID 列表", example = "[\"session_001\", \"session_002\"]") - private List ids; - } - - // ========== 3. 消息/对话 (Completion) 相关 ========== - - /** - * 发送消息请求 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "发送消息请求") - public static class CompletionReq implements Serializable { - - @NotBlank(message = "问题内容不能为空") - @Schema(description = "用户问题", requiredMode = Schema.RequiredMode.REQUIRED, example = "请介绍一下你们的产品") - private String question; - - @Schema(description = "是否使用流式响应 (SSE)", example = "true") - @Builder.Default - private Boolean stream = true; - - @NotBlank(message = "会话 ID 不能为空") - @Schema(description = "会话 ID (可选,不传则创建新会话)", example = "session_001") - @JsonProperty("session_id") - private String sessionId; - - @Schema(description = "是否展示引用", example = "true") - private Boolean quote; - - @Schema(description = "指定检索的文档 ID 列表 (逗号分隔)", example = "doc_001,doc_002") - @JsonProperty("doc_ids") - private String docIds; - - @Schema(description = "元数据过滤条件") - @JsonProperty("metadata_condition") - private Map metadataCondition; - } - - /** - * 消息响应 VO - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "消息响应 VO") - public static class CompletionVO implements Serializable { - - @Schema(description = "AI 回答内容") - private String answer; - - @Schema(description = "引用信息") - private Reference reference; - - @Schema(description = "会话 ID", example = "session_001") - @JsonProperty("session_id") - private String sessionId; - - @Schema(description = "任务 ID (用于流式响应追踪)", example = "task_001") - @JsonProperty("task_id") - private String taskId; - - /** - * 引用信息 (检索命中结果) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "引用信息") - public static class Reference implements Serializable { - - @Schema(description = "命中的文档块列表") - private List chunks; - - @Schema(description = "文档聚合信息") - @JsonProperty("doc_aggs") - private List docAggs; - } - - /** - * 文档聚合信息 - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文档聚合信息") - public static class DocAgg implements Serializable { - - @Schema(description = "文档 ID", example = "doc_001") - @JsonProperty("doc_id") - private String docId; - - @Schema(description = "文档名称", example = "产品手册.pdf") - @JsonProperty("doc_name") - private String docName; - - @Schema(description = "命中次数", example = "3") - private Integer count; - } - } - - /** - * 简易知识库 VO (用于 Assistant 列表) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "简易知识库 VO") - public static class SimpleDatasetVO implements Serializable { - @Schema(description = "知识库 ID") - private String id; - @Schema(description = "知识库名称") - private String name; - @Schema(description = "头像") - private String avatar; - @Schema(description = "分块数量") - @JsonProperty("chunk_num") - private Integer chunkNum; - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/common/CommonDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/common/CommonDTO.java deleted file mode 100644 index ec3b597e..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/common/CommonDTO.java +++ /dev/null @@ -1,79 +0,0 @@ -package xiaozhi.modules.knowledge.dto.common; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.*; - -@Schema(description = "通用扩展功能 DTO") -public class CommonDTO { - - // ========== 1. 引用详情 (detail_share_embedded) ========== - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "引用详情请求") - public static class ReferenceDetailReq implements Serializable { - @Schema(description = "切片 ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "切片 ID 不能为空") - @JsonProperty("chunk_id") - private String chunkId; - - @Schema(description = "知识库 ID") - @JsonProperty("knowledge_id") - private String knowledgeId; - } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "引用详情响应") - public static class ReferenceDetailVO implements Serializable { - @Schema(description = "切片 ID") - @JsonProperty("chunk_id") - private String chunkId; - - @Schema(description = "完整内容") - @JsonProperty("content_with_weight") - private String contentWithWeight; - - @Schema(description = "文档名称") - @JsonProperty("doc_name") - private String docName; - - @Schema(description = "图片 ID 列表") - @JsonProperty("img_id") - private String imageId; // 注意:RAGFlow 有时返回 String 有时返回 List,需根据实际情况确认,暂定 String 用于 ID - - @Schema(description = "文档 ID") - @JsonProperty("doc_id") - private String docId; - } - - // ========== 2. 通用问答 (ask_about) - 调试用 ========== - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @Schema(description = "通用问答请求 (调试用)") - public static class AskAboutReq implements Serializable { - @Schema(description = "用户问题", requiredMode = Schema.RequiredMode.REQUIRED, example = "What is this dataset about?") - @NotBlank(message = "问题不能为空") - @JsonProperty("question") - private String question; - - @Schema(description = "数据集 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "数据集列表不能为空") - @JsonProperty("dataset_ids") - private List datasetIds; - } - - // 响应通常复用 String 或者简单的 Map 结构,视具体实现而定,暂不定义专用 VO -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/file/FileDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/file/FileDTO.java deleted file mode 100644 index 816ed8ee..00000000 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/dto/file/FileDTO.java +++ /dev/null @@ -1,363 +0,0 @@ -package xiaozhi.modules.knowledge.dto.file; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import java.io.Serializable; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.*; -import org.springframework.web.multipart.MultipartFile; - -/** - * 文件管理聚合 DTO - *

- * 容器类,内含文件模块所有请求/响应对象的静态内部类定义。 - *

- */ -@Schema(description = "文件管理聚合 DTO") -public class FileDTO { - - // ========== 请求类 ========== - - /** - * 文件上传请求 (对应接口 1: upload) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文件上传请求") - public static class UploadReq implements Serializable { - - @NotNull(message = "文件不能为空") - @Schema(description = "上传的文件", requiredMode = Schema.RequiredMode.REQUIRED) - private MultipartFile file; - - @Schema(description = "父文件夹 ID (为空则上传到根目录)", example = "folder_001") - @JsonProperty("parent_id") - private String parentId; - } - - /** - * 新建文件夹请求 (对应接口 2: create) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "新建文件夹请求") - public static class CreateReq implements Serializable { - - @NotBlank(message = "文件夹名称不能为空") - @Schema(description = "文件夹名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "新建文件夹") - private String name; - - @Schema(description = "父文件夹 ID (为空则创建在根目录)", example = "folder_001") - @JsonProperty("parent_id") - private String parentId; - - @NotBlank(message = "类型不能为空") - @Schema(description = "类型: FOLDER", requiredMode = Schema.RequiredMode.REQUIRED, example = "FOLDER") - @Builder.Default - private String type = "FOLDER"; - } - - /** - * 重命名请求 (对应接口 6: rename) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "重命名请求") - public static class RenameReq implements Serializable { - - @NotBlank(message = "文件 ID 不能为空") - @Schema(description = "文件/文件夹 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "file_001") - @JsonProperty("file_id") - private String fileId; - - @NotBlank(message = "新名称不能为空") - @Schema(description = "新名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "重命名后的文件") - private String name; - } - - /** - * 移动请求 (对应接口 7: move) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "移动请求") - public static class MoveReq implements Serializable { - - @NotEmpty(message = "源文件 ID 列表不能为空") - @Schema(description = "源文件/文件夹 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[\"file_001\", \"file_002\"]") - @JsonProperty("src_file_ids") - private List srcFileIds; - - @NotBlank(message = "目标文件夹 ID 不能为空") - @Schema(description = "目标文件夹 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "folder_002") - @JsonProperty("dest_file_id") - private String destFileId; - } - - /** - * 批量删除请求 (对应接口 8: rm) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "批量删除请求") - public static class RemoveReq implements Serializable { - - @NotEmpty(message = "文件 ID 列表不能为空") - @Schema(description = "文件/文件夹 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[\"file_001\", \"file_002\"]") - @JsonProperty("file_ids") - private List fileIds; - } - - /** - * 导入知识库请求 (对应接口 9: convert) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "导入知识库请求") - public static class ConvertReq implements Serializable { - - @NotEmpty(message = "文件 ID 列表不能为空") - @Schema(description = "文件 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[\"file_001\", \"file_002\"]") - @JsonProperty("file_ids") - private List fileIds; - - @NotEmpty(message = "知识库 ID 列表不能为空") - @Schema(description = "目标知识库 ID 列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "[\"kb_001\"]") - @JsonProperty("kb_ids") - private List kbIds; - } - - /** - * 列表查询请求 (对应接口 3: list_files) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "列表查询请求") - public static class ListReq implements Serializable { - - @Schema(description = "父文件夹 ID (为空则查询根目录)", example = "folder_001") - @JsonProperty("parent_id") - private String parentId; - - @Schema(description = "关键词搜索", example = "文档") - private String keywords; - - @Schema(description = "页码 (从 1 开始)", example = "1") - private Integer page; - - @Schema(description = "每页数量", example = "30") - @JsonProperty("page_size") - private Integer pageSize; - - @Schema(description = "排序字段: create_time / update_time / name / size", example = "create_time") - private String orderby; - - @Schema(description = "是否降序", example = "true") - private Boolean desc; - } - - // ========== 响应类 ========== - - /** - * 文件/文件夹基础信息 VO - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文件/文件夹基础信息") - public static class InfoVO implements Serializable { - - @Schema(description = "文件/文件夹 ID", example = "file_001") - private String id; - - @Schema(description = "父文件夹 ID", example = "folder_001") - @JsonProperty("parent_id") - private String parentId; - - @Schema(description = "租户 ID", example = "tenant_001") - @JsonProperty("tenant_id") - private String tenantId; - - @Schema(description = "创建者 ID", example = "user_001") - @JsonProperty("created_by") - private String createdBy; - - @Schema(description = "类型: FOLDER / FILE", example = "FOLDER") - private String type; - - @Schema(description = "名称", example = "我的文件夹") - private String name; - - @Schema(description = "路径位置", example = "/root/folder") - private String location; - - @Schema(description = "文件大小 (字节)", example = "1024") - private Long size; - - @Schema(description = "来源类型", example = "local") - @JsonProperty("source_type") - private String sourceType; - - @Schema(description = "创建时间 (时间戳)", example = "1700000000000") - @JsonProperty("create_time") - private Long createTime; - - @Schema(description = "创建日期 (格式化)", example = "2024-01-15 10:30:00") - @JsonProperty("create_date") - private String createDate; - - @Schema(description = "更新时间 (时间戳)", example = "1700000001000") - @JsonProperty("update_time") - private Long updateTime; - - @Schema(description = "更新日期 (格式化)", example = "2024-01-15 11:00:00") - @JsonProperty("update_date") - private String updateDate; - - @Schema(description = "文件扩展名", example = "pdf") - private String extension; - } - - /** - * 列表响应 VO (对应接口 3: list_files) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文件列表响应") - public static class ListVO implements Serializable { - - @Schema(description = "总记录数", example = "100") - private Long total; - - @Schema(description = "当前父文件夹信息") - @JsonProperty("parent_folder") - private InfoVO parentFolder; - - @Schema(description = "文件/文件夹列表") - private List files; - - @Schema(description = "面包屑导航路径") - private List breadcrumb; - } - - /** - * 转换结果项 VO (对应接口 9: convert) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文件转换结果项") - public static class ConvertVO implements Serializable { - - @Schema(description = "转换记录 ID", example = "convert_001") - private String id; - - @Schema(description = "源文件 ID", example = "file_001") - @JsonProperty("file_id") - private String fileId; - - @Schema(description = "目标文档 ID", example = "doc_001") - @JsonProperty("document_id") - private String documentId; - - @Schema(description = "创建时间 (时间戳)", example = "1700000000000") - @JsonProperty("create_time") - private Long createTime; - - @Schema(description = "创建日期 (格式化)", example = "2024-01-15 10:30:00") - @JsonProperty("create_date") - private String createDate; - - @Schema(description = "更新时间 (时间戳)", example = "1700000001000") - @JsonProperty("update_time") - private Long updateTime; - - @Schema(description = "更新日期 (格式化)", example = "2024-01-15 11:00:00") - @JsonProperty("update_date") - private String updateDate; - } - - /** - * 转换状态 VO (对应接口 10: get_convert_status) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "文件转换状态") - public static class ConvertStatusVO implements Serializable { - - @Schema(description = "转换状态: pending / processing / completed / failed", example = "completed") - private String status; - - @Schema(description = "转换进度 (0.0 - 1.0)", example = "1.0") - private Float progress; - - @Schema(description = "状态消息", example = "转换完成") - private String message; - } - - /** - * 面包屑 VO (对应接口 12: all_parent_folder) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "面包屑导航 (所有父文件夹)") - public static class BreadcrumbVO implements Serializable { - - @Schema(description = "父文件夹列表 (从根到当前的路径)") - @JsonProperty("parent_folders") - private List parentFolders; - } - - /** - * 根目录信息 VO (对应接口 10: get_root_folder) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "根目录信息") - public static class RootFolderVO implements Serializable { - - @Schema(description = "根文件夹信息") - @JsonProperty("root_folder") - private InfoVO rootFolder; - } - - /** - * 父目录信息 VO (对应接口 11: get_parent_folder) - */ - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @Schema(description = "父目录信息") - public static class ParentFolderVO implements Serializable { - - @Schema(description = "父文件夹信息") - @JsonProperty("parent_folder") - private InfoVO parentFolder; - } -} diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/rag/impl/RAGFlowAdapter.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/rag/impl/RAGFlowAdapter.java index 13a6decf..f66623f7 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/rag/impl/RAGFlowAdapter.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/rag/impl/RAGFlowAdapter.java @@ -485,16 +485,11 @@ public class RAGFlowAdapter extends KnowledgeBaseAdapter { @Override public Integer getDocumentCount(String datasetId) { - try { - DatasetDTO.InfoVO info = getDatasetInfo(datasetId); - if (info != null && info.getDocumentCount() != null) { - return info.getDocumentCount().intValue(); - } - return 0; - } catch (Exception e) { - log.warn("获取文档数量失败: {}", e.getMessage()); - return 0; + DatasetDTO.InfoVO info = getDatasetInfo(datasetId); + if (info != null && info.getDocumentCount() != null) { + return info.getDocumentCount().intValue(); } + return 0; } @Override @@ -518,7 +513,7 @@ public class RAGFlowAdapter extends KnowledgeBaseAdapter { return null; } catch (Exception e) { log.warn("获取数据集信息失败: datasetId={}, error={}", datasetId, e.getMessage()); - return null; + throw convertToRenException(e); } } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java index 94958bd1..918148d1 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/knowledge/service/impl/KnowledgeBaseServiceImpl.java @@ -100,9 +100,9 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl + custom-class="add-model-dialog" :show-close="false" class="center-dialog">
{{ $t('modelConfigDialog.addModel') }} @@ -298,7 +298,7 @@ export default {