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