From aea7cc000b4ca9d1c40fb58b45df91ad73e53260 Mon Sep 17 00:00:00 2001 From: "zhijiantianya@gmail.com" Date: Mon, 6 May 2024 22:28:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91AI=EF=BC=9A=E8=B0=83=E6=95=B4=20message=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/controller/AiChatController.java | 50 --------------- .../controller/AiChatMessageController.java | 44 ------------- .../admin/chat/AiChatMessageController.java | 62 +++++++++++++++++++ .../chat/vo/message/AiChatMessageRespVO.java | 37 +++++++++++ .../vo/message/AiChatMessageSendReqVO.java | 22 +++++++ .../admin/chat/vo/message/package-info.java | 1 - .../ai/convert/AiChatMessageConvert.java | 4 +- .../dal/dataobject/chat/AiChatMessageDO.java | 2 +- .../iocoder/yudao/module/ai/dal/pageinfo.java | 7 --- .../ai/service/AiChatMessageService.java | 5 +- .../module/ai/service/AiChatService.java | 6 +- .../impl/AiChatMessageServiceImpl.java | 7 +-- .../ai/service/impl/AiChatServiceImpl.java | 10 +-- .../module/ai/vo/AiChatMessageDeleteReq.java | 28 --------- .../module/ai/vo/AiChatMessageListRes.java | 42 ------------- .../yudao/module/ai/vo/AiChatMessageReq.java | 24 ------- .../iocoder/yudao/module/ai/vo/AiChatReq.java | 48 -------------- .../yudao/module/ai/vo/AiChatReqVO.java | 21 ------- 18 files changed, 137 insertions(+), 283 deletions(-) delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatController.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatMessageController.java create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageSendReqVO.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/pageinfo.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageDeleteReq.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageListRes.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageReq.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReq.java delete mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReqVO.java diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatController.java deleted file mode 100644 index 09b83fcad..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatController.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.ai.service.AiChatService; -import cn.iocoder.yudao.module.ai.vo.AiChatReq; -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.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - -/** - * ia 模块 - * - * @author fansili - * @time 2024/4/13 17:44 - * @since 1.0 - */ -@Tag(name = "A1-AI聊天") -@RestController -@RequestMapping("/ai") -@Slf4j -@AllArgsConstructor -public class AiChatController { - - @Autowired - private final AiChatService chatService; - - @Operation(summary = "聊天-chat", description = "这个一般等待时间比较久,需要全部完成才会返回!") - @GetMapping("/chat") - public CommonResult chat(@Validated @ModelAttribute AiChatReq req) { - return CommonResult.success(chatService.chat(req)); - } - - // TODO @芋艿:调用这个方法异常,Unable to handle the Spring Security Exception because the response is already committed. - @Operation(summary = "聊天-stream", description = "这里跟通义千问一样采用的是 Server-Sent Events (SSE) 通讯模式") - @GetMapping(value = "/chatStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) - public SseEmitter chatStream(@Validated @ModelAttribute AiChatReq req) { - Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); - chatService.chatStream(req, sseEmitter); - return sseEmitter; - } -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatMessageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatMessageController.java deleted file mode 100644 index ecfb6c865..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatMessageController.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.ai.service.AiChatMessageService; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; -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.*; - -/** - * chat message - * - * @author fansili - * @time 2024/4/24 17:22 - * @since 1.0 - */ -@Tag(name = "A3-聊天-对话") -@RestController -@RequestMapping("/ai/chat/message") -@Slf4j -@AllArgsConstructor -public class AiChatMessageController { - - private final AiChatMessageService chatMessageService; - - @Operation(summary = "聊天记录", description = "查询个人的聊天记录") - @GetMapping("/list") - public PageResult list(@Validated @ModelAttribute AiChatMessageReq req) { - return chatMessageService.list(req); - } - - @Operation(summary = "聊天记录 - 删除", description = "删除记录") - @DeleteMapping("/{chatConversationId}/{id}") - public CommonResult delete(@PathVariable("chatConversationId") Long chatConversationId, - @PathVariable("id") Long id) { - chatMessageService.delete(chatConversationId, id); - return CommonResult.success(null); - } -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java new file mode 100644 index 000000000..473f1c856 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.ai.controller.admin.chat; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; +import cn.iocoder.yudao.module.ai.service.AiChatService; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +// TODO @芋艿:权限标识; +@Tag(name = "管理后台 - 聊天消息") +@RestController +@RequestMapping("/ai/chat/message") +@Slf4j +public class AiChatMessageController { + @Resource + private AiChatService chatService; + + @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") + @PostMapping("/send") + public CommonResult sendMessage(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { + // TODO @fan:使用 static import;这样就 success 就行了; + return success(null); + } + + // TODO @芋艿:调用这个方法异常,Unable to handle the Spring Security Exception because the response is already committed.;可以再试试 + // TODO @fan:要不要使用 Flux 来返回;可以使用 Flux + @Operation(summary = "发送消息(流式)", description = "流式返回,响应较快") + @PostMapping(value = "/send-stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public SseEmitter sendMessageStream(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { + Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); + chatService.chatStream(sendReqVO, sseEmitter); + return sseEmitter; + } + + @Operation(summary = "获得指定会话的消息列表") + @GetMapping("/list-by-conversation-id") + @Parameter(name = "conversationId", required = true, description = "会话编号", example = "1024") + public CommonResult> getMessageListByConversationId(@RequestParam("conversationId") Long conversationId) { + return success(null); + } + + @Operation(summary = "删除消息") + @DeleteMapping("/delete") + @Parameter(name = "id", required = true, description = "消息编号", example = "1024") + public CommonResult delete(@RequestParam("id") Long id) { + return success(null); + } + +} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java new file mode 100644 index 000000000..d5f830d17 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - AI 聊天消息 Response VO") +@Data +public class AiChatMessageRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") + private Long conversationId; + + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "role") + private String type; // 参见 MessageType 枚举类 + + @Schema(description = "用户编号", example = "4096") + private Long userId; // 仅当 user 发送时非空 + + @Schema(description = "角色编号", example = "888") + private Long roleId; // 仅当 assistant 回复时非空 + + @Schema(description = "模型标志", requiredMode = Schema.RequiredMode.REQUIRED, example = "gpt-3.5-turbo") + private String model; // 参见 AiOpenAiModelEnum 枚举类 + + @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") + private Long modelId; + + @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,你好啊") + private String content; + + @Schema(description = "消耗 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") + private Integer tokens; + +} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageSendReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageSendReqVO.java new file mode 100644 index 000000000..9592da347 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageSendReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.experimental.Accessors; + +@Schema(description = "管理后台 - AI 聊天消息发送 Request VO") +@Data +public class AiChatMessageSendReqVO { + + @Schema(description = "聊天对话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "聊天对话编号不能为空") + private Long conversationId; + + @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "帮我写个 Java 算法") + @NotEmpty(message = "聊天内容不能为空") + private String content; + +} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java deleted file mode 100644 index 5fee7106d..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java index 14f410a1e..c84ecb404 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.ai.convert; import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -25,5 +25,5 @@ public interface AiChatMessageConvert { * @param list * @return */ - List convert(List list); + List convert(List list); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatMessageDO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatMessageDO.java index 4d44e82a0..f5a5296a7 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatMessageDO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/chat/AiChatMessageDO.java @@ -81,7 +81,7 @@ public class AiChatMessageDO extends BaseDO { /** * 消耗 Token 数量 */ - private Integer usedTokens; + private Integer tokens; // TODO 芋艿:是否作为上下文语料?use_context,待定 diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/pageinfo.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/pageinfo.java deleted file mode 100644 index ce4001112..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/pageinfo.java +++ /dev/null @@ -1,7 +0,0 @@ -package cn.iocoder.yudao.module.ai.dal; - -/** - * @author fansili - * @time 2024/4/25 15:36 - * @since 1.0 - */ diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatMessageService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatMessageService.java index ef1cfa468..77450c63b 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatMessageService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatMessageService.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.module.ai.service; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; /** * chat message @@ -19,7 +18,7 @@ public interface AiChatMessageService { * @param req * @return */ - PageResult list(AiChatMessageReq req); + PageResult list(AiChatMessageReq req); /** * message - 删除 diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java index b3596e9cf..c054e41fa 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.ai.service; import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; -import cn.iocoder.yudao.module.ai.vo.AiChatReq; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; /** * 聊天 chat @@ -18,7 +18,7 @@ public interface AiChatService { * @param req * @return */ - String chat(AiChatReq req); + String chat(AiChatMessageSendReqVO req); /** * chat stream @@ -27,5 +27,5 @@ public interface AiChatService { * @param sseEmitter * @return */ - void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter); + void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatMessageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatMessageServiceImpl.java index ae691daee..ae5a594cb 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatMessageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatMessageServiceImpl.java @@ -11,8 +11,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper; import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper; import cn.iocoder.yudao.module.ai.service.AiChatMessageService; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -35,7 +34,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { private final AiChatConversationMapper aiChatConversationMapper; @Override - public PageResult list(AiChatMessageReq req) { + public PageResult list(AiChatMessageReq req) { // 查询 LambdaQueryWrapperX queryWrapperX = new LambdaQueryWrapperX<>(); queryWrapperX.eq(AiChatMessageDO::getConversationId, req.getChatConversationId()); @@ -43,7 +42,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { queryWrapperX.orderByDesc(AiChatMessageDO::getId); PageResult pageResult = aiChatMessageMapper.selectPage(req, queryWrapperX); // 转换 res - List messageListResList = AiChatMessageConvert.INSTANCE.convert(pageResult.getList()); + List messageListResList = AiChatMessageConvert.INSTANCE.convert(pageResult.getList()); return new PageResult(messageListResList, pageResult.getTotal()); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java index c70b56aa0..50f4ac0cb 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java @@ -17,7 +17,7 @@ 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.controller.admin.chat.vo.conversation.AiChatConversationRespVO; -import cn.iocoder.yudao.module.ai.vo.AiChatReq; +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -53,7 +53,7 @@ public class AiChatServiceImpl implements AiChatService { * @return */ @Transactional(rollbackFor = Exception.class) - public String chat(AiChatReq req) { + public String chat(AiChatMessageSendReqVO req) { Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); // 获取 client 类型 AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); @@ -83,7 +83,7 @@ public class AiChatServiceImpl implements AiChatService { return content; } - private void saveChatMessage(AiChatReq req, AiChatConversationRespVO conversationRes, Long loginUserId) { + private void saveChatMessage(AiChatMessageSendReqVO 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, AiChatConversationRespVO conversationRes, Long loginUserId, String systemPrompts) { + public void saveSystemChatMessage(AiChatMessageSendReqVO req, AiChatConversationRespVO conversationRes, Long loginUserId, String systemPrompts) { Long chatConversationId = conversationRes.getId(); // 增加 chat message 记录 aiChatMessageMapper.insert( @@ -128,7 +128,7 @@ public class AiChatServiceImpl implements AiChatService { * @return */ @Override - public void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter) { + public void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter) { Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); // 获取 client 类型 AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageDeleteReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageDeleteReq.java deleted file mode 100644 index dafd7d84f..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageDeleteReq.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.ai.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * chat message list req - * - * @author fansili - * @time 2024/4/14 16:12 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiChatMessageDeleteReq extends PageParam { - - @Schema(description = "id") - @NotNull - private Long id; - - @Schema(description = "聊天ID,关联到特定的会话或对话") - @NotNull - private Long chatConversationId; - -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageListRes.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageListRes.java deleted file mode 100644 index ecfbc009c..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageListRes.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.ai.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 看板 message list req - * - * @author fansili - * @time 2024/4/24 17:28 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiChatMessageListRes { - - @Schema(description = "编号") - private Long id; - - @Schema(description = "聊天ID,关联到特定的会话或对话") - private Long chatConversationId; - - @Schema(description = "角色ID,用于标识发送消息的用户或系统的身份") - private Long userId; - - @Schema(description = "消息具体内容,存储用户的发言或者系统响应的文字信息") - private String message; - - @Schema(description = "消息类型,枚举值可能包括'system'(系统消息)、'user'(用户消息)和'assistant'(助手消息)") - private String messageType; - - @Schema(description = "在生成消息时采用的Top-K采样大小") - private Double topK; - - @Schema(description = "Top-P核采样方法的概率阈值") - private Double topP; - - @Schema(description = "温度参数,用于调整生成回复的随机性和多样性程度,") - private Double temperature; - -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageReq.java deleted file mode 100644 index 60b7e91ee..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageReq.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.ai.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * chat message list req - * - * @author fansili - * @time 2024/4/14 16:12 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiChatMessageReq extends PageParam { - - @Schema(description = "聊天ID,关联到特定的会话或对话") - @NotNull - private Long chatConversationId; - -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReq.java deleted file mode 100644 index 0597f8990..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReq.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.yudao.module.ai.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * chat req - * - * @author fansili - * @time 2024/4/14 16:12 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiChatReq { - - @Schema(description = "ai模型(查看 AiClientNameEnum)") - @NotNull(message = "模型不能为空!") - @Size(max = 30, message = "模型字符最大 30个字符!") - private String modal; - - @Schema(description = "对话Id") - @NotNull(message = "对话id不能为空") - private Long conversationId; - - @Schema(description = "chat角色模板") - private Long chatRoleId; - - @NotNull(message = "提示词不能为空!") - @Size(max = 5000, message = "提示词最大5000个字符!") - @Schema(description = "填入固定值,1 issues, 2 pr") - private String prompt; - - @Schema(description = "用于控制随机性和多样性的温度参数") - private Double temperature; - - @Schema(description = "生成时,核采样方法的概率阈值。例如,取值为0.8时,仅保留累计概率之和大于等于0.8的概率分布中的token,\n" + - " * 作为随机采样的候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的随机性越低。\n" + - " * 默认值为0.8。注意,取值不要大于等于1\n") - private Double topP; - - @Schema(description = "在生成消息时采用的Top-K采样大小,表示模型生成回复时考虑的候选项集合的大小") - private Double topK; - -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReqVO.java deleted file mode 100644 index f4bca2fd6..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.ai.vo; - -import cn.iocoder.yudao.module.ai.enums.AiOpenAiModelEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -// TODO done @fansili 1)swagger 注释不太对;2)有了 swagger 注释,就不用类注释了 -@Data -@Schema(description = "用户 App - 上传文件 Request VO") -public class AiChatReqVO { - - @Schema(description = "提示词", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "提示词不能为空!") - private String prompt; - - @Schema(description = "AI模型", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "AI模型不能为空") - private AiOpenAiModelEnum aiModel; - -}