From 66404f3cc4a58750690715a7c88a392e0538ce41 Mon Sep 17 00:00:00 2001 From: Linnea Lin <1604326066@qq.com> Date: Mon, 20 Oct 2025 08:16:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=B1=BB&=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=9A=84=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xfg/frame/common/AssistantType.java | 70 +++++++++++++ .../xfg/frame/config/RagflowProperties.java | 58 +++++++++++ .../xfg/frame/config/Retrofit2Config.java | 4 +- .../xfg/frame/domain/req/CreateChatReq.java | 46 +++++++++ .../frame/domain/req/CreateSessionReq.java | 22 +++++ .../xfg/frame/domain/res/ChatIdRes.java | 36 +++++++ .../xfg/frame/domain/res/SessionRes.java | 97 +++++++++++++++++++ 7 files changed, 330 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cn/bugstack/xfg/frame/common/AssistantType.java create mode 100644 src/main/java/cn/bugstack/xfg/frame/config/RagflowProperties.java create mode 100644 src/main/java/cn/bugstack/xfg/frame/domain/req/CreateChatReq.java create mode 100644 src/main/java/cn/bugstack/xfg/frame/domain/req/CreateSessionReq.java create mode 100644 src/main/java/cn/bugstack/xfg/frame/domain/res/ChatIdRes.java create mode 100644 src/main/java/cn/bugstack/xfg/frame/domain/res/SessionRes.java diff --git a/src/main/java/cn/bugstack/xfg/frame/common/AssistantType.java b/src/main/java/cn/bugstack/xfg/frame/common/AssistantType.java new file mode 100644 index 0000000..9053aa1 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/common/AssistantType.java @@ -0,0 +1,70 @@ +package cn.bugstack.xfg.frame.common; + +/** + * 助手类型枚举 + * 用于管理不同类型的AI助手及其配置 + */ +public enum AssistantType { + + /** + * 通用助手 - 适用于一般性问题解答 + */ + GENERAL("general", "通用助手", "prompts/general-assistant.txt"), + + /** + * 技术助手 - 专门处理技术相关问题 + */ + TECHNICAL("technical", "技术助手", "prompts/technical-assistant.txt"), + + /** + * 客服助手 - 专门处理客户服务相关问题 + */ + CUSTOMER_SERVICE("customer-service", "客服助手", "prompts/customer-service.txt"); + + /** + * 配置键名 + */ + private final String configKey; + + /** + * 助手描述 + */ + private final String description; + + /** + * prompt 文件路径 + */ + private final String promptFilePath; + + AssistantType(String configKey, String description, String promptFilePath) { + this.configKey = configKey; + this.description = description; + this.promptFilePath = promptFilePath; + } + + public String getConfigKey() { + return configKey; + } + + public String getDescription() { + return description; + } + + public String getPromptFilePath() { + return promptFilePath; + } + + /** + * 根据配置键名获取助手类型 + * @param configKey 配置键名 + * @return 助手类型 + */ + public static AssistantType fromConfigKey(String configKey) { + for (AssistantType type : values()) { + if (type.configKey.equals(configKey)) { + return type; + } + } + throw new IllegalArgumentException("Unknown assistant type: " + configKey); + } +} \ No newline at end of file diff --git a/src/main/java/cn/bugstack/xfg/frame/config/RagflowProperties.java b/src/main/java/cn/bugstack/xfg/frame/config/RagflowProperties.java new file mode 100644 index 0000000..a30aaa6 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/config/RagflowProperties.java @@ -0,0 +1,58 @@ +package cn.bugstack.xfg.frame.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * RagFlow 配置属性类 + * 用于读取 application.yml 中的 ragflow 配置 + */ +@Data +@Component +@ConfigurationProperties(prefix = "ragflow") +public class RagflowProperties { + + /** + * API 配置 + */ + private Api api; + + /** + * 多个助手类型的 prompt 配置 + */ + private Map prompts; + + @Data + public static class Api { + /** + * API 基础 URL + */ + private String baseUrl; + + /** + * API 密钥 + */ + private String apiKey; + } + + @Data + public static class PromptConfig { + /** + * prompt 文件路径 + */ + private String file; + + /** + * 开场白 + */ + private String opener; + + /** + * 空响应消息 + */ + private String emptyResponse; + } +} \ No newline at end of file diff --git a/src/main/java/cn/bugstack/xfg/frame/config/Retrofit2Config.java b/src/main/java/cn/bugstack/xfg/frame/config/Retrofit2Config.java index b6c0cf3..c4f02df 100644 --- a/src/main/java/cn/bugstack/xfg/frame/config/Retrofit2Config.java +++ b/src/main/java/cn/bugstack/xfg/frame/config/Retrofit2Config.java @@ -20,9 +20,7 @@ public class Retrofit2Config { @Resource private RagflowProperties ragflowProperties; - - @Resource - private AuthInterceptor authInterceptor; + @Bean public Retrofit retrofit() { diff --git a/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateChatReq.java b/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateChatReq.java new file mode 100644 index 0000000..e099e62 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateChatReq.java @@ -0,0 +1,46 @@ +package cn.bugstack.xfg.frame.domain.req; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 创建聊天请求类 + * 用于调用 RagFlow API 创建 AI 助手 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CreateChatReq { + + /** + * 助手名称 + */ + private String name; + + + /** + * Prompt 配置 + */ + @JsonProperty("prompt") + private PromptConfig promptConfig; + + + + @Data + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class PromptConfig { + /** + * 系统提示词 + */ + private String prompt; + + } +} \ No newline at end of file diff --git a/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateSessionReq.java b/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateSessionReq.java new file mode 100644 index 0000000..b631623 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/domain/req/CreateSessionReq.java @@ -0,0 +1,22 @@ +package cn.bugstack.xfg.frame.domain.req; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建会话请求类 + * 用于在指定的助手下创建新的聊天会话 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CreateSessionReq { + + /** + * 会话名称 + */ + private String name; +} \ No newline at end of file diff --git a/src/main/java/cn/bugstack/xfg/frame/domain/res/ChatIdRes.java b/src/main/java/cn/bugstack/xfg/frame/domain/res/ChatIdRes.java new file mode 100644 index 0000000..0f87a82 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/domain/res/ChatIdRes.java @@ -0,0 +1,36 @@ +package cn.bugstack.xfg.frame.domain.res; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSetter; +import lombok.Data; + +/** + * 创建聊天响应类 + * 用于接收 RagFlow API 创建助手的响应,只提取 chat_id + */ +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ChatIdRes { + + /** + * 聊天 ID + */ + private String id; + + /** + * 从嵌套的 data 字段中提取 id + * @param data 响应数据 + */ + @JsonSetter("data") + public void setData(DataWrapper data) { + if (data != null) { + this.id = data.getId(); + } + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DataWrapper { + private String id; + } +} \ No newline at end of file diff --git a/src/main/java/cn/bugstack/xfg/frame/domain/res/SessionRes.java b/src/main/java/cn/bugstack/xfg/frame/domain/res/SessionRes.java new file mode 100644 index 0000000..988cd80 --- /dev/null +++ b/src/main/java/cn/bugstack/xfg/frame/domain/res/SessionRes.java @@ -0,0 +1,97 @@ +package cn.bugstack.xfg.frame.domain.res; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * 创建会话响应类 + * 用于接收 RagFlow API 创建会话的响应 + */ +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class SessionRes { + + /** + * 响应码 + */ + private Integer code; + + /** + * 会话数据 + */ + private SessionData data; + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class SessionData { + + /** + * 聊天 ID + */ + @JsonProperty("chat_id") + private String chatId; + + /** + * 创建日期 + */ + @JsonProperty("create_date") + private String createDate; + + /** + * 创建时间戳 + */ + @JsonProperty("create_time") + private Long createTime; + + /** + * 会话 ID + */ + private String id; + + /** + * 消息列表 + */ + private List messages; + + /** + * 会话名称 + */ + private String name; + + /** + * 更新日期 + */ + @JsonProperty("update_date") + private String updateDate; + + /** + * 更新时间戳 + */ + @JsonProperty("update_time") + private Long updateTime; + + /** + * 用户 ID + */ + @JsonProperty("user_id") + private String userId; + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Message { + + /** + * 消息内容 + */ + private String content; + + /** + * 角色(assistant/user) + */ + private String role; + } +} \ No newline at end of file -- GitLab