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 0000000000000000000000000000000000000000..9053aa13b2351a6eafad5f27a0ad6eb6d1c3bf0d --- /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 0000000000000000000000000000000000000000..a30aaa6afbfc37bb8668ba7d9aa267e46cedee29 --- /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 b6c0cf37c75cd1099b0a4d9722d5fb1bf22f4ac8..c4f02df3fcf14c22c5fd3ffb1992e79ea86ac573 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 0000000000000000000000000000000000000000..e099e627c44734b1efef3a205b1b44119f6d6c44 --- /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 0000000000000000000000000000000000000000..b6316232012cbd2dcdd6e821c679a37f7a04ef6d --- /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 0000000000000000000000000000000000000000..0f87a82350a15702342848d0d854e2ac8405dfa6 --- /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 0000000000000000000000000000000000000000..988cd8096a34cd9a1918a0f9c6a7a17fcd521252 --- /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