Commit 2df0babc36cad69f579e9dcefa0d938f855ad3d5
1 parent
e9cbee9d
【代码评审】AI:调整 conversation 接口
Showing
21 changed files
with
233 additions
and
263 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatConversationController.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.controller; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | -import cn.iocoder.yudao.module.ai.service.AiChatConversationService; | |
| 5 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateRoleReq; | |
| 6 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateUserReq; | |
| 7 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationListReq; | |
| 8 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes; | |
| 9 | -import io.swagger.v3.oas.annotations.Operation; | |
| 10 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | -import lombok.AllArgsConstructor; | |
| 12 | -import lombok.extern.slf4j.Slf4j; | |
| 13 | -import org.springframework.validation.annotation.Validated; | |
| 14 | -import org.springframework.web.bind.annotation.*; | |
| 15 | - | |
| 16 | -import java.util.List; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * ia 模块 | |
| 20 | - * | |
| 21 | - * @author fansili | |
| 22 | - * @time 2024/4/13 17:44 | |
| 23 | - * @since 1.0 | |
| 24 | - */ | |
| 25 | -@Tag(name = "A2-聊天-对话") | |
| 26 | -@RestController | |
| 27 | -@RequestMapping("/ai/chat/conversation") | |
| 28 | -@Slf4j | |
| 29 | -@AllArgsConstructor | |
| 30 | -public class AiChatConversationController { | |
| 31 | - | |
| 32 | - private final AiChatConversationService chatConversationService; | |
| 33 | - | |
| 34 | - @Operation(summary = "创建 - 对话普通对话") | |
| 35 | - @PutMapping("/createConversation") | |
| 36 | - public CommonResult<AiChatConversationRes> createConversation(@RequestBody @Validated AiChatConversationCreateUserReq req) { | |
| 37 | - return CommonResult.success(chatConversationService.createConversation(req)); | |
| 38 | - } | |
| 39 | - | |
| 40 | - @Operation(summary = "创建 - 对话角色对话") | |
| 41 | - @PutMapping("/createRoleConversation") | |
| 42 | - public CommonResult<AiChatConversationRes> createRoleConversation(@RequestBody @Validated AiChatConversationCreateRoleReq req) { | |
| 43 | - return CommonResult.success(chatConversationService.createRoleConversation(req)); | |
| 44 | - } | |
| 45 | - | |
| 46 | - @Operation(summary = "获取 - 获取对话") | |
| 47 | - @GetMapping("/{id}") | |
| 48 | - public CommonResult<AiChatConversationRes> getConversation(@PathVariable("id") Long id) { | |
| 49 | - return CommonResult.success(chatConversationService.getConversation(id)); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Operation(summary = "获取 - 获取对话list") | |
| 53 | - @GetMapping("/list") | |
| 54 | - public CommonResult<List<AiChatConversationRes>> listConversation(@ModelAttribute @Validated AiChatConversationListReq req) { | |
| 55 | - return CommonResult.success(chatConversationService.listConversation(req)); | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Operation(summary = "更新 - 更新模型") | |
| 59 | - @PostMapping("/{id}/modal") | |
| 60 | - public CommonResult<Void> updateModal(@PathVariable("id") Long id, | |
| 61 | - @RequestParam("modalId") Long modalId) { | |
| 62 | - chatConversationService.updateModal(id, modalId); | |
| 63 | - return CommonResult.success(null); | |
| 64 | - } | |
| 65 | - | |
| 66 | - @Operation(summary = "删除") | |
| 67 | - @DeleteMapping("/{id}") | |
| 68 | - public CommonResult<Void> delete(@PathVariable("id") Long id) { | |
| 69 | - chatConversationService.delete(id); | |
| 70 | - return CommonResult.success(null); | |
| 71 | - } | |
| 72 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; | |
| 7 | +import io.swagger.v3.oas.annotations.Operation; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 10 | +import jakarta.validation.Valid; | |
| 11 | +import lombok.extern.slf4j.Slf4j; | |
| 12 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 13 | +import org.springframework.web.bind.annotation.*; | |
| 14 | + | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 18 | + | |
| 19 | +@Tag(name = "管理后台 - 聊天会话") | |
| 20 | +@RestController | |
| 21 | +@RequestMapping("/ai/chat/conversation") | |
| 22 | +@Slf4j | |
| 23 | +public class AiChatConversationController { | |
| 24 | + | |
| 25 | + // TODO @fan:实现一下 | |
| 26 | + @PostMapping("/create") | |
| 27 | + @Operation(summary = "创建聊天会话") | |
| 28 | + @PreAuthorize("@ss.hasPermission('ai:chat-conversation:create')") | |
| 29 | + public CommonResult<Long> createConversation(@RequestBody @Valid AiChatConversationCreateReqVO createReqVO) { | |
| 30 | + return success(1L); | |
| 31 | + } | |
| 32 | + | |
| 33 | + // TODO @fan:实现一下 | |
| 34 | + @PutMapping("/update") | |
| 35 | + @Operation(summary = "更新聊天会话") | |
| 36 | + @PreAuthorize("@ss.hasPermission('ai:chat-conversation:create')") | |
| 37 | + public CommonResult<Boolean> updateConversation(@RequestBody @Valid AiChatConversationUpdateReqVO updateReqVO) { | |
| 38 | + return success(true); | |
| 39 | + } | |
| 40 | + | |
| 41 | + // TODO @fan:实现一下 | |
| 42 | + @GetMapping("/list") | |
| 43 | + @Operation(summary = "获得聊天会话列表") | |
| 44 | + public CommonResult<List<AiChatConversationRespVO>> getConversationList() { | |
| 45 | + return success(null); | |
| 46 | + } | |
| 47 | + | |
| 48 | + // TODO @fan:实现一下 | |
| 49 | + @GetMapping("/get") | |
| 50 | + @Operation(summary = "获得聊天会话") | |
| 51 | + @Parameter(name = "id", required = true, description = "会话编号", example = "1024") | |
| 52 | + public CommonResult<AiChatConversationRespVO> getConversation(@RequestParam("id") Long id) { | |
| 53 | + return success(null); | |
| 54 | + } | |
| 55 | + | |
| 56 | + // TODO @fan:实现一下 | |
| 57 | + @DeleteMapping("/delete") | |
| 58 | + @Operation(summary = "删除聊天会话") | |
| 59 | + @Parameter(name = "id", required = true, description = "会话编号", example = "1024") | |
| 60 | + public CommonResult<Boolean> deleteConversation(@RequestParam("id") Long id) { | |
| 61 | + return success(null); | |
| 62 | + } | |
| 63 | + | |
| 64 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationControllerV2.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.controller.admin.chat; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 5 | -import lombok.extern.slf4j.Slf4j; | |
| 6 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | -import org.springframework.web.bind.annotation.RestController; | |
| 8 | - | |
| 9 | -@Tag(name = "管理后台 - 聊天会话") | |
| 10 | -@RestController | |
| 11 | -@RequestMapping("/ai/chat/conversation") | |
| 12 | -@Slf4j | |
| 13 | -public class AiChatConversationControllerV2 { | |
| 14 | - | |
| 15 | - public CommonResult<List<>> | |
| 16 | - | |
| 17 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/conversation/AiChatConversationCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import lombok.experimental.Accessors; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - AI 聊天会话创建 Request VO") | |
| 11 | +@Data | |
| 12 | +public class AiChatConversationCreateReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "角色编号", example = "666") | |
| 15 | + private Long roleId; | |
| 16 | + | |
| 17 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/conversation/AiChatConversationRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.experimental.Accessors; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - AI 聊天会话 Response VO") | |
| 9 | +@Data | |
| 10 | +public class AiChatConversationRespVO { | |
| 11 | + | |
| 12 | + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 13 | + private Long id; | |
| 14 | + | |
| 15 | + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 16 | + private Long userId; | |
| 17 | + | |
| 18 | + @Schema(description = "会话标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是一个标题") | |
| 19 | + private String title; | |
| 20 | + | |
| 21 | + @Schema(description = "是否置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 22 | + private Boolean pinned; | |
| 23 | + | |
| 24 | + @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 25 | + private Long modelId; | |
| 26 | + | |
| 27 | + @Schema(description = "模型标志", requiredMode = Schema.RequiredMode.REQUIRED, example = "ERNIE-Bot-turbo-0922") | |
| 28 | + private String model; | |
| 29 | + | |
| 30 | + @Schema(description = "温度参数", requiredMode = Schema.RequiredMode.REQUIRED, example = "0.8") | |
| 31 | + private Double temperature; | |
| 32 | + | |
| 33 | + @Schema(description = "单条回复的最大 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096") | |
| 34 | + private Integer maxTokens; | |
| 35 | + | |
| 36 | + @Schema(description = "上下文的最大 Message 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 37 | + private Integer maxContexts; | |
| 38 | + | |
| 39 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/conversation/AiChatConversationUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@Schema(description = "管理后台 - AI 聊天会话更新 Request VO") | |
| 8 | +@Data | |
| 9 | +public class AiChatConversationUpdateReqVO { | |
| 10 | + | |
| 11 | + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 12 | + @NotNull(message = "会话编号不能为空") | |
| 13 | + private Long id; | |
| 14 | + | |
| 15 | + @Schema(description = "会话标题", example = "我是一个标题") | |
| 16 | + private String title; | |
| 17 | + | |
| 18 | + @Schema(description = "是否置顶", example = "true") | |
| 19 | + private Boolean pinned; | |
| 20 | + | |
| 21 | + @Schema(description = "模型编号", example = "1") | |
| 22 | + private Long modelId; | |
| 23 | + | |
| 24 | + @Schema(description = "温度参数", example = "0.8") | |
| 25 | + private Double temperature; | |
| 26 | + | |
| 27 | + @Schema(description = "单条回复的最大 Token 数量", example = "4096") | |
| 28 | + private Integer maxTokens; | |
| 29 | + | |
| 30 | + @Schema(description = "上下文的最大 Message 数量", example = "10") | |
| 31 | + private Integer maxContexts; | |
| 32 | + | |
| 33 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java
0 → 100644
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/package-info.java deleted
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/package-info.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/package-info.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatConversationConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.convert; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; |
| 4 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | |
| 5 | 5 | import org.mapstruct.Mapper; |
| 6 | 6 | import org.mapstruct.factory.Mappers; |
| 7 | 7 | |
| ... | ... | @@ -25,7 +25,7 @@ public interface AiChatConversationConvert { |
| 25 | 25 | * @param top100Conversation |
| 26 | 26 | * @return |
| 27 | 27 | */ |
| 28 | - List<AiChatConversationRes> covnertChatConversationResList(List<AiChatConversationDO> top100Conversation); | |
| 28 | + List<AiChatConversationRespVO> covnertChatConversationResList(List<AiChatConversationDO> top100Conversation); | |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 转换 - 单个 ChatConversationRes |
| ... | ... | @@ -33,5 +33,5 @@ public interface AiChatConversationConvert { |
| 33 | 33 | * @param aiChatConversationDO |
| 34 | 34 | * @return |
| 35 | 35 | */ |
| 36 | - AiChatConversationRes covnertChatConversationRes(AiChatConversationDO aiChatConversationDO); | |
| 36 | + AiChatConversationRespVO covnertChatConversationRes(AiChatConversationDO aiChatConversationDO); | |
| 37 | 37 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatConversationDO.java
| ... | ... | @@ -40,11 +40,15 @@ public class AiChatConversationDO extends BaseDO { |
| 40 | 40 | private Long userId; |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * 标题 | |
| 43 | + * 会话标题 | |
| 44 | 44 | * |
| 45 | 45 | * 默认由系统自动生成,可用户手动修改 |
| 46 | 46 | */ |
| 47 | 47 | private String title; |
| 48 | + /** | |
| 49 | + * 是否置顶 | |
| 50 | + */ | |
| 51 | + private Boolean pinned; | |
| 48 | 52 | |
| 49 | 53 | /** |
| 50 | 54 | * 角色编号 |
| ... | ... | @@ -52,12 +56,6 @@ public class AiChatConversationDO extends BaseDO { |
| 52 | 56 | * 关联 {@link AiChatRoleDO#getId()} |
| 53 | 57 | */ |
| 54 | 58 | private Long roleId; |
| 55 | - /** | |
| 56 | - * 模型标志 | |
| 57 | - * | |
| 58 | - * 枚举 {@link AiOpenAiModelEnum} | |
| 59 | - */ | |
| 60 | - private String model; | |
| 61 | 59 | |
| 62 | 60 | /** |
| 63 | 61 | * 模型编号 |
| ... | ... | @@ -65,6 +63,12 @@ public class AiChatConversationDO extends BaseDO { |
| 65 | 63 | * 关联 {@link AiChatModalDO#getId()} 字段 |
| 66 | 64 | */ |
| 67 | 65 | private Long modelId; |
| 66 | + /** | |
| 67 | + * 模型标志 | |
| 68 | + * | |
| 69 | + * 枚举 {@link AiOpenAiModelEnum} | |
| 70 | + */ | |
| 71 | + private String model; | |
| 68 | 72 | |
| 69 | 73 | // ========== 会话配置 ========== |
| 70 | 74 | |
| ... | ... | @@ -75,12 +79,12 @@ public class AiChatConversationDO extends BaseDO { |
| 75 | 79 | */ |
| 76 | 80 | private Double temperature; |
| 77 | 81 | /** |
| 78 | - * 上下文数量 | |
| 82 | + * 单条回复的最大 Token 数量 | |
| 79 | 83 | */ |
| 80 | - private Integer contextCount; | |
| 84 | + private Integer maxTokens; | |
| 81 | 85 | /** |
| 82 | - * 单条回复的 Token 数量 | |
| 86 | + * 上下文的最大 Message 数量 | |
| 83 | 87 | */ |
| 84 | - private Integer maxTokens; | |
| 88 | + private Integer maxContexts; | |
| 85 | 89 | |
| 86 | 90 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatMessageDO.java
| ... | ... | @@ -88,22 +88,22 @@ public class AiChatMessageDO extends BaseDO { |
| 88 | 88 | // ========== 会话配置 ========== |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * 上下文数量 | |
| 92 | - * | |
| 93 | - * 冗余 {@link AiChatConversationDO#getContextCount()} | |
| 94 | - */ | |
| 95 | - private Integer contextCount; | |
| 96 | - /** | |
| 97 | 91 | * 温度参数 |
| 98 | 92 | * |
| 99 | 93 | * 冗余 {@link AiChatConversationDO#getTemperature()} |
| 100 | 94 | */ |
| 101 | 95 | private Double temperature; |
| 102 | 96 | /** |
| 103 | - * 单条回复的 Token 数量 | |
| 97 | + * 单条回复的最大 Token 数量 | |
| 104 | 98 | * |
| 105 | 99 | * 冗余 {@link AiChatConversationDO#getMaxTokens()} |
| 106 | 100 | */ |
| 107 | 101 | private Integer maxTokens; |
| 102 | + /** | |
| 103 | + * 上下文的最大 Message 数量 | |
| 104 | + * | |
| 105 | + * 冗余 {@link AiChatConversationDO#getMaxContexts()} | |
| 106 | + */ | |
| 107 | + private Integer maxContexts; | |
| 108 | 108 | |
| 109 | 109 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/model/AiChatModalDO.java
| ... | ... | @@ -3,21 +3,25 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.model; |
| 3 | 3 | import cn.iocoder.yudao.framework.ai.AiPlatformEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 6 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 7 | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | -import lombok.Data; | |
| 9 | +import lombok.*; | |
| 9 | 10 | import lombok.experimental.Accessors; |
| 10 | 11 | |
| 11 | 12 | /** |
| 12 | 13 | * AI 聊天模型 DO |
| 13 | 14 | * |
| 14 | 15 | * @author fansili |
| 15 | - * @time 2024/4/24 19:39 | |
| 16 | - * @since 1.0 | |
| 16 | + * @since 2024/4/24 19:39 | |
| 17 | 17 | */ |
| 18 | +@TableName("ai_chat_model") | |
| 19 | +@KeySequence("ai_chat_model_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 18 | 20 | @Data |
| 19 | -@Accessors(chain = true) | |
| 20 | -@TableName("ai_chat_modal") | |
| 21 | +@EqualsAndHashCode(callSuper = true) | |
| 22 | +@Builder | |
| 23 | +@NoArgsConstructor | |
| 24 | +@AllArgsConstructor | |
| 21 | 25 | public class AiChatModalDO extends BaseDO { |
| 22 | 26 | |
| 23 | 27 | /** |
| ... | ... | @@ -30,7 +34,7 @@ public class AiChatModalDO extends BaseDO { |
| 30 | 34 | * |
| 31 | 35 | * 关联 {@link AiApiKeyDO#getId()} |
| 32 | 36 | */ |
| 33 | - private Long key_id; | |
| 37 | + private Long keyId; | |
| 34 | 38 | /** |
| 35 | 39 | * 模型名称 |
| 36 | 40 | */ |
| ... | ... | @@ -66,10 +70,12 @@ public class AiChatModalDO extends BaseDO { |
| 66 | 70 | */ |
| 67 | 71 | private Double temperature; |
| 68 | 72 | /** |
| 69 | - * 单条回复的 Token 数量 | |
| 73 | + * 单条回复的最大 Token 数量 | |
| 70 | 74 | */ |
| 71 | 75 | private Integer maxTokens; |
| 72 | - | |
| 73 | - // TODO 芋艿:到底使用 max_context、还是 contextCount,待定!一个是轮次,一个是长度数量;貌似轮次更常用一点; | |
| 76 | + /** | |
| 77 | + * 上下文的最大 Message 数量 | |
| 78 | + */ | |
| 79 | + private Integer maxContexts; | |
| 74 | 80 | |
| 75 | 81 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/model/AiChatRoleDO.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.dal.dataobject.model; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.ai.chat.messages.MessageType; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 4 | 6 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import com.baomidou.mybatisplus.annotation.IdType; | |
| 6 | -import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | -import lombok.Data; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler; | |
| 9 | +import lombok.*; | |
| 9 | 10 | import lombok.experimental.Accessors; |
| 10 | 11 | |
| 12 | +import java.io.Serializable; | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 11 | 15 | /** |
| 12 | - * ai 聊天角色 | |
| 16 | + * AI 聊天角色 DO | |
| 13 | 17 | * |
| 14 | - * @fansili | |
| 15 | - * @since v1.0 | |
| 18 | + * @author fansili | |
| 19 | + * @since 2024/4/24 19:39 | |
| 16 | 20 | */ |
| 21 | +@TableName(value = "ai_chat_role", autoResultMap = true) | |
| 22 | +@KeySequence("ai_chat_role_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | 23 | @Data |
| 18 | -@Accessors(chain = true) | |
| 19 | -@TableName("ai_chat_role") | |
| 24 | +@EqualsAndHashCode(callSuper = true) | |
| 25 | +@Builder | |
| 26 | +@NoArgsConstructor | |
| 27 | +@AllArgsConstructor | |
| 20 | 28 | public class AiChatRoleDO extends BaseDO { |
| 21 | 29 | |
| 22 | 30 | /** |
| ... | ... | @@ -44,6 +52,10 @@ public class AiChatRoleDO extends BaseDO { |
| 44 | 52 | * 角色欢迎语 |
| 45 | 53 | */ |
| 46 | 54 | private String welcomeMessage; |
| 55 | + /** | |
| 56 | + * 角色设定(消息) | |
| 57 | + */ | |
| 58 | + private String systemMessage; | |
| 47 | 59 | |
| 48 | 60 | /** |
| 49 | 61 | * 用户编号 |
| ... | ... | @@ -77,6 +89,4 @@ public class AiChatRoleDO extends BaseDO { |
| 77 | 89 | */ |
| 78 | 90 | private Integer status; |
| 79 | 91 | |
| 80 | - // TODO 芋艿:要不要加一个 context,内置的上下文 | |
| 81 | - | |
| 82 | 92 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateRoleReq; | |
| 4 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationCreateUserReq; | |
| 5 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationListReq; | |
| 6 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes; | |
| 3 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | |
| 7 | 5 | |
| 8 | 6 | import java.util.List; |
| 9 | 7 | |
| ... | ... | @@ -21,7 +19,7 @@ public interface AiChatConversationService { |
| 21 | 19 | * @param req |
| 22 | 20 | * @return |
| 23 | 21 | */ |
| 24 | - AiChatConversationRes createConversation(AiChatConversationCreateUserReq req); | |
| 22 | + AiChatConversationRespVO createConversation(AiChatConversationCreateUserReq req); | |
| 25 | 23 | |
| 26 | 24 | /** |
| 27 | 25 | * 对话 - 创建role对话 |
| ... | ... | @@ -29,7 +27,7 @@ public interface AiChatConversationService { |
| 29 | 27 | * @param req |
| 30 | 28 | * @return |
| 31 | 29 | */ |
| 32 | - AiChatConversationRes createRoleConversation(AiChatConversationCreateRoleReq req); | |
| 30 | + AiChatConversationRespVO createRoleConversation(AiChatConversationCreateReqVO req); | |
| 33 | 31 | |
| 34 | 32 | |
| 35 | 33 | /** |
| ... | ... | @@ -38,7 +36,7 @@ public interface AiChatConversationService { |
| 38 | 36 | * @param id |
| 39 | 37 | * @return |
| 40 | 38 | */ |
| 41 | - AiChatConversationRes getConversation(Long id); | |
| 39 | + AiChatConversationRespVO getConversation(Long id); | |
| 42 | 40 | |
| 43 | 41 | /** |
| 44 | 42 | * 获取 - 对话列表 |
| ... | ... | @@ -46,7 +44,7 @@ public interface AiChatConversationService { |
| 46 | 44 | * @param req |
| 47 | 45 | * @return |
| 48 | 46 | */ |
| 49 | - List<AiChatConversationRes> listConversation(AiChatConversationListReq req); | |
| 47 | + List<AiChatConversationRespVO> listConversation(AiChatConversationListReq req); | |
| 50 | 48 | |
| 51 | 49 | /** |
| 52 | 50 | * 更新 - 更新模型 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java
| ... | ... | @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.ai.service.impl; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.ErrorCodeConstants; |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | |
| 6 | 8 | import cn.iocoder.yudao.module.ai.convert.AiChatConversationConvert; |
| 7 | 9 | import cn.iocoder.yudao.module.ai.enums.AiChatConversationTypeEnum; |
| 8 | 10 | import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum; |
| ... | ... | @@ -38,7 +40,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 38 | 40 | private final AiChatRoleService aiChatRoleService; |
| 39 | 41 | |
| 40 | 42 | @Override |
| 41 | - public AiChatConversationRes createConversation(AiChatConversationCreateUserReq req) { | |
| 43 | + public AiChatConversationRespVO createConversation(AiChatConversationCreateUserReq req) { | |
| 42 | 44 | // 获取用户id |
| 43 | 45 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 44 | 46 | // 查询最新的对话 |
| ... | ... | @@ -58,7 +60,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | @Override |
| 61 | - public AiChatConversationRes createRoleConversation(AiChatConversationCreateRoleReq req) { | |
| 63 | + public AiChatConversationRespVO createRoleConversation(AiChatConversationCreateReqVO req) { | |
| 62 | 64 | // 获取用户id |
| 63 | 65 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 64 | 66 | // 查询最新的对话 |
| ... | ... | @@ -101,7 +103,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 101 | 103 | } |
| 102 | 104 | |
| 103 | 105 | @Override |
| 104 | - public AiChatConversationRes getConversation(Long id) { | |
| 106 | + public AiChatConversationRespVO getConversation(Long id) { | |
| 105 | 107 | AiChatConversationDO aiChatConversationDO = validateExists(id); |
| 106 | 108 | return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(aiChatConversationDO); |
| 107 | 109 | } |
| ... | ... | @@ -115,7 +117,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | 119 | @Override |
| 118 | - public List<AiChatConversationRes> listConversation(AiChatConversationListReq req) { | |
| 120 | + public List<AiChatConversationRespVO> listConversation(AiChatConversationListReq req) { | |
| 119 | 121 | // 获取用户id |
| 120 | 122 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 121 | 123 | // 查询前100对话 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java
| ... | ... | @@ -16,7 +16,7 @@ import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper; |
| 16 | 16 | import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; |
| 17 | 17 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; |
| 18 | 18 | import cn.iocoder.yudao.module.ai.service.AiChatService; |
| 19 | -import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes; | |
| 19 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | |
| 20 | 20 | import cn.iocoder.yudao.module.ai.vo.AiChatReq; |
| 21 | 21 | import lombok.AllArgsConstructor; |
| 22 | 22 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -58,7 +58,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 58 | 58 | // 获取 client 类型 |
| 59 | 59 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); |
| 60 | 60 | // 获取对话信息 |
| 61 | - AiChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId()); | |
| 61 | + AiChatConversationRespVO conversationRes = chatConversationService.getConversation(req.getConversationId()); | |
| 62 | 62 | // 保存 chat message |
| 63 | 63 | saveChatMessage(req, conversationRes, loginUserId); |
| 64 | 64 | String content = null; |
| ... | ... | @@ -83,7 +83,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 83 | 83 | return content; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private void saveChatMessage(AiChatReq req, AiChatConversationRes conversationRes, Long loginUserId) { | |
| 86 | + private void saveChatMessage(AiChatReq req, AiChatConversationRespVO conversationRes, Long loginUserId) { | |
| 87 | 87 | Long chatConversationId = conversationRes.getId(); |
| 88 | 88 | // 增加 chat message 记录 |
| 89 | 89 | aiChatMessageMapper.insert( |
| ... | ... | @@ -101,7 +101,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 101 | 101 | aiChatConversationMapper.updateIncrChatCount(req.getConversationId()); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public void saveSystemChatMessage(AiChatReq req, AiChatConversationRes conversationRes, Long loginUserId, String systemPrompts) { | |
| 104 | + public void saveSystemChatMessage(AiChatReq req, AiChatConversationRespVO conversationRes, Long loginUserId, String systemPrompts) { | |
| 105 | 105 | Long chatConversationId = conversationRes.getId(); |
| 106 | 106 | // 增加 chat message 记录 |
| 107 | 107 | aiChatMessageMapper.insert( |
| ... | ... | @@ -133,7 +133,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 133 | 133 | // 获取 client 类型 |
| 134 | 134 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); |
| 135 | 135 | // 获取对话信息 |
| 136 | - AiChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId()); | |
| 136 | + AiChatConversationRespVO conversationRes = chatConversationService.getConversation(req.getConversationId()); | |
| 137 | 137 | // 创建 chat 需要的 Prompt |
| 138 | 138 | Prompt prompt = new Prompt(req.getPrompt()); |
| 139 | 139 | req.setTopK(req.getTopK()); | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationCreateRoleReq.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import jakarta.validation.constraints.NotNull; | |
| 5 | -import lombok.Data; | |
| 6 | -import lombok.experimental.Accessors; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 聊天对话 | |
| 10 | - * | |
| 11 | - * @author fansili | |
| 12 | - * @time 2024/4/18 16:24 | |
| 13 | - * @since 1.0 | |
| 14 | - */ | |
| 15 | -@Data | |
| 16 | -@Accessors(chain = true) | |
| 17 | -public class AiChatConversationCreateRoleReq { | |
| 18 | - | |
| 19 | - @Schema(description = "chat角色Id") | |
| 20 | - @NotNull(message = "聊天角色id不能为空!") | |
| 21 | - private Long roleId; | |
| 22 | - | |
| 23 | - @Schema(description = "标题(有程序自动生成)") | |
| 24 | - @NotNull(message = "标题不能为空!") | |
| 25 | - private String title; | |
| 26 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationCreateUserReq.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import jakarta.validation.constraints.NotNull; | |
| 5 | -import lombok.Data; | |
| 6 | -import lombok.experimental.Accessors; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 聊天对话 | |
| 10 | - * | |
| 11 | - * @author fansili | |
| 12 | - * @time 2024/4/18 16:24 | |
| 13 | - * @since 1.0 | |
| 14 | - */ | |
| 15 | -@Data | |
| 16 | -@Accessors(chain = true) | |
| 17 | -public class AiChatConversationCreateUserReq { | |
| 18 | - | |
| 19 | - @Schema(description = "对话标题") | |
| 20 | - @NotNull(message = "标题不能为空!") | |
| 21 | - private String title; | |
| 22 | - | |
| 23 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationListReq.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.experimental.Accessors; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 聊天对话 list req | |
| 9 | - * | |
| 10 | - * @author fansili | |
| 11 | - * @time 2024/4/18 16:24 | |
| 12 | - * @since 1.0 | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -@Accessors(chain = true) | |
| 16 | -public class AiChatConversationListReq { | |
| 17 | - | |
| 18 | - @Schema(description = "查询根据title") | |
| 19 | - private String search; | |
| 20 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatConversationRes.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.experimental.Accessors; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 聊天对话 res | |
| 9 | - * | |
| 10 | - * @author fansili | |
| 11 | - * @time 2024/4/18 16:24 | |
| 12 | - * @since 1.0 | |
| 13 | - */ | |
| 14 | -@Data | |
| 15 | -@Accessors(chain = true) | |
| 16 | -public class AiChatConversationRes { | |
| 17 | - | |
| 18 | - @Schema(description = "id") | |
| 19 | - private Long id; | |
| 20 | - | |
| 21 | - @Schema(description = "用户id") | |
| 22 | - private Long userId; | |
| 23 | - | |
| 24 | - @Schema(description = "chat角色Id") | |
| 25 | - private Long roleId; | |
| 26 | - | |
| 27 | - @Schema(description = "chat角色名称") | |
| 28 | - private String roleName; | |
| 29 | - | |
| 30 | - @Schema(description = "模型id") | |
| 31 | - private Long modalId; | |
| 32 | - | |
| 33 | - @Schema(description = "使用的模型") | |
| 34 | - private String modal; | |
| 35 | - | |
| 36 | - @Schema(description = "标题(有程序自动生成)") | |
| 37 | - private String title; | |
| 38 | - | |
| 39 | - @Schema(description = "对话类型(roleChat、userChat)") | |
| 40 | - private String type; | |
| 41 | - | |
| 42 | - @Schema(description = "聊天次数(有程序自动生成)") | |
| 43 | - private Integer chatCount; | |
| 44 | - | |
| 45 | -} |