Commit aea7cc000b4ca9d1c40fb58b45df91ad73e53260
1 parent
2df0babc
【代码评审】AI:调整 message 接口
Showing
18 changed files
with
137 additions
and
283 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatController.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.AiChatService; | ||
| 5 | -import cn.iocoder.yudao.module.ai.vo.AiChatReq; | ||
| 6 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 7 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 8 | -import lombok.AllArgsConstructor; | ||
| 9 | -import lombok.extern.slf4j.Slf4j; | ||
| 10 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | -import org.springframework.http.MediaType; | ||
| 12 | -import org.springframework.validation.annotation.Validated; | ||
| 13 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 14 | -import org.springframework.web.bind.annotation.ModelAttribute; | ||
| 15 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | -import org.springframework.web.bind.annotation.RestController; | ||
| 17 | -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
| 18 | - | ||
| 19 | -/** | ||
| 20 | - * ia 模块 | ||
| 21 | - * | ||
| 22 | - * @author fansili | ||
| 23 | - * @time 2024/4/13 17:44 | ||
| 24 | - * @since 1.0 | ||
| 25 | - */ | ||
| 26 | -@Tag(name = "A1-AI聊天") | ||
| 27 | -@RestController | ||
| 28 | -@RequestMapping("/ai") | ||
| 29 | -@Slf4j | ||
| 30 | -@AllArgsConstructor | ||
| 31 | -public class AiChatController { | ||
| 32 | - | ||
| 33 | - @Autowired | ||
| 34 | - private final AiChatService chatService; | ||
| 35 | - | ||
| 36 | - @Operation(summary = "聊天-chat", description = "这个一般等待时间比较久,需要全部完成才会返回!") | ||
| 37 | - @GetMapping("/chat") | ||
| 38 | - public CommonResult<String> chat(@Validated @ModelAttribute AiChatReq req) { | ||
| 39 | - return CommonResult.success(chatService.chat(req)); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - // TODO @芋艿:调用这个方法异常,Unable to handle the Spring Security Exception because the response is already committed. | ||
| 43 | - @Operation(summary = "聊天-stream", description = "这里跟通义千问一样采用的是 Server-Sent Events (SSE) 通讯模式") | ||
| 44 | - @GetMapping(value = "/chatStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
| 45 | - public SseEmitter chatStream(@Validated @ModelAttribute AiChatReq req) { | ||
| 46 | - Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); | ||
| 47 | - chatService.chatStream(req, sseEmitter); | ||
| 48 | - return sseEmitter; | ||
| 49 | - } | ||
| 50 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/AiChatMessageController.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.framework.common.pojo.PageResult; | ||
| 5 | -import cn.iocoder.yudao.module.ai.service.AiChatMessageService; | ||
| 6 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; | ||
| 7 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; | ||
| 8 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 9 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 10 | -import lombok.AllArgsConstructor; | ||
| 11 | -import lombok.extern.slf4j.Slf4j; | ||
| 12 | -import org.springframework.validation.annotation.Validated; | ||
| 13 | -import org.springframework.web.bind.annotation.*; | ||
| 14 | - | ||
| 15 | -/** | ||
| 16 | - * chat message | ||
| 17 | - * | ||
| 18 | - * @author fansili | ||
| 19 | - * @time 2024/4/24 17:22 | ||
| 20 | - * @since 1.0 | ||
| 21 | - */ | ||
| 22 | -@Tag(name = "A3-聊天-对话") | ||
| 23 | -@RestController | ||
| 24 | -@RequestMapping("/ai/chat/message") | ||
| 25 | -@Slf4j | ||
| 26 | -@AllArgsConstructor | ||
| 27 | -public class AiChatMessageController { | ||
| 28 | - | ||
| 29 | - private final AiChatMessageService chatMessageService; | ||
| 30 | - | ||
| 31 | - @Operation(summary = "聊天记录", description = "查询个人的聊天记录") | ||
| 32 | - @GetMapping("/list") | ||
| 33 | - public PageResult<AiChatMessageListRes> list(@Validated @ModelAttribute AiChatMessageReq req) { | ||
| 34 | - return chatMessageService.list(req); | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - @Operation(summary = "聊天记录 - 删除", description = "删除记录") | ||
| 38 | - @DeleteMapping("/{chatConversationId}/{id}") | ||
| 39 | - public CommonResult delete(@PathVariable("chatConversationId") Long chatConversationId, | ||
| 40 | - @PathVariable("id") Long id) { | ||
| 41 | - chatMessageService.delete(chatConversationId, id); | ||
| 42 | - return CommonResult.success(null); | ||
| 43 | - } | ||
| 44 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.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.Utf8SseEmitter; | ||
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; | ||
| 6 | +import cn.iocoder.yudao.module.ai.service.AiChatService; | ||
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; | ||
| 8 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 9 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 10 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 11 | +import jakarta.annotation.Resource; | ||
| 12 | +import lombok.extern.slf4j.Slf4j; | ||
| 13 | +import org.springframework.http.MediaType; | ||
| 14 | +import org.springframework.validation.annotation.Validated; | ||
| 15 | +import org.springframework.web.bind.annotation.*; | ||
| 16 | +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
| 17 | + | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 21 | + | ||
| 22 | +// TODO @芋艿:权限标识; | ||
| 23 | +@Tag(name = "管理后台 - 聊天消息") | ||
| 24 | +@RestController | ||
| 25 | +@RequestMapping("/ai/chat/message") | ||
| 26 | +@Slf4j | ||
| 27 | +public class AiChatMessageController { | ||
| 28 | + @Resource | ||
| 29 | + private AiChatService chatService; | ||
| 30 | + | ||
| 31 | + @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") | ||
| 32 | + @PostMapping("/send") | ||
| 33 | + public CommonResult<AiChatMessageRespVO> sendMessage(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { | ||
| 34 | + // TODO @fan:使用 static import;这样就 success 就行了; | ||
| 35 | + return success(null); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + // TODO @芋艿:调用这个方法异常,Unable to handle the Spring Security Exception because the response is already committed.;可以再试试 | ||
| 39 | + // TODO @fan:要不要使用 Flux 来返回;可以使用 Flux<AiChatMessageRespVO> | ||
| 40 | + @Operation(summary = "发送消息(流式)", description = "流式返回,响应较快") | ||
| 41 | + @PostMapping(value = "/send-stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) | ||
| 42 | + public SseEmitter sendMessageStream(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { | ||
| 43 | + Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); | ||
| 44 | + chatService.chatStream(sendReqVO, sseEmitter); | ||
| 45 | + return sseEmitter; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @Operation(summary = "获得指定会话的消息列表") | ||
| 49 | + @GetMapping("/list-by-conversation-id") | ||
| 50 | + @Parameter(name = "conversationId", required = true, description = "会话编号", example = "1024") | ||
| 51 | + public CommonResult<List<AiChatMessageRespVO>> getMessageListByConversationId(@RequestParam("conversationId") Long conversationId) { | ||
| 52 | + return success(null); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Operation(summary = "删除消息") | ||
| 56 | + @DeleteMapping("/delete") | ||
| 57 | + @Parameter(name = "id", required = true, description = "消息编号", example = "1024") | ||
| 58 | + public CommonResult<Boolean> delete(@RequestParam("id") Long id) { | ||
| 59 | + return success(null); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | +} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Schema(description = "管理后台 - AI 聊天消息 Response VO") | ||
| 7 | +@Data | ||
| 8 | +public class AiChatMessageRespVO { | ||
| 9 | + | ||
| 10 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 11 | + private Long id; | ||
| 12 | + | ||
| 13 | + @Schema(description = "会话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | ||
| 14 | + private Long conversationId; | ||
| 15 | + | ||
| 16 | + @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "role") | ||
| 17 | + private String type; // 参见 MessageType 枚举类 | ||
| 18 | + | ||
| 19 | + @Schema(description = "用户编号", example = "4096") | ||
| 20 | + private Long userId; // 仅当 user 发送时非空 | ||
| 21 | + | ||
| 22 | + @Schema(description = "角色编号", example = "888") | ||
| 23 | + private Long roleId; // 仅当 assistant 回复时非空 | ||
| 24 | + | ||
| 25 | + @Schema(description = "模型标志", requiredMode = Schema.RequiredMode.REQUIRED, example = "gpt-3.5-turbo") | ||
| 26 | + private String model; // 参见 AiOpenAiModelEnum 枚举类 | ||
| 27 | + | ||
| 28 | + @Schema(description = "模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") | ||
| 29 | + private Long modelId; | ||
| 30 | + | ||
| 31 | + @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "你好,你好啊") | ||
| 32 | + private String content; | ||
| 33 | + | ||
| 34 | + @Schema(description = "消耗 Token 数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") | ||
| 35 | + private Integer tokens; | ||
| 36 | + | ||
| 37 | +} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/AiChatMessageSendReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import jakarta.validation.constraints.NotNull; | ||
| 6 | +import jakarta.validation.constraints.Size; | ||
| 7 | +import lombok.Data; | ||
| 8 | +import lombok.experimental.Accessors; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - AI 聊天消息发送 Request VO") | ||
| 11 | +@Data | ||
| 12 | +public class AiChatMessageSendReqVO { | ||
| 13 | + | ||
| 14 | + @Schema(description = "聊天对话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 15 | + @NotNull(message = "聊天对话编号不能为空") | ||
| 16 | + private Long conversationId; | ||
| 17 | + | ||
| 18 | + @Schema(description = "聊天内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "帮我写个 Java 算法") | ||
| 19 | + @NotEmpty(message = "聊天内容不能为空") | ||
| 20 | + private String content; | ||
| 21 | + | ||
| 22 | +} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/vo/message/package-info.java deleted
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java
| 1 | package cn.iocoder.yudao.module.ai.convert; | 1 | package cn.iocoder.yudao.module.ai.convert; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | 3 | import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; |
| 4 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; | 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 5 | import org.mapstruct.Mapper; | 5 | import org.mapstruct.Mapper; |
| 6 | import org.mapstruct.factory.Mappers; | 6 | import org.mapstruct.factory.Mappers; |
| 7 | 7 | ||
| @@ -25,5 +25,5 @@ public interface AiChatMessageConvert { | @@ -25,5 +25,5 @@ public interface AiChatMessageConvert { | ||
| 25 | * @param list | 25 | * @param list |
| 26 | * @return | 26 | * @return |
| 27 | */ | 27 | */ |
| 28 | - List<AiChatMessageListRes> convert(List<AiChatMessageDO> list); | 28 | + List<AiChatMessageRespVO> convert(List<AiChatMessageDO> list); |
| 29 | } | 29 | } |
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 { | @@ -81,7 +81,7 @@ public class AiChatMessageDO extends BaseDO { | ||
| 81 | /** | 81 | /** |
| 82 | * 消耗 Token 数量 | 82 | * 消耗 Token 数量 |
| 83 | */ | 83 | */ |
| 84 | - private Integer usedTokens; | 84 | + private Integer tokens; |
| 85 | 85 | ||
| 86 | // TODO 芋艿:是否作为上下文语料?use_context,待定 | 86 | // TODO 芋艿:是否作为上下文语料?use_context,待定 |
| 87 | 87 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/pageinfo.java deleted
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatMessageService.java
| 1 | package cn.iocoder.yudao.module.ai.service; | 1 | package cn.iocoder.yudao.module.ai.service; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; | ||
| 5 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; | 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 6 | 5 | ||
| 7 | /** | 6 | /** |
| 8 | * chat message | 7 | * chat message |
| @@ -19,7 +18,7 @@ public interface AiChatMessageService { | @@ -19,7 +18,7 @@ public interface AiChatMessageService { | ||
| 19 | * @param req | 18 | * @param req |
| 20 | * @return | 19 | * @return |
| 21 | */ | 20 | */ |
| 22 | - PageResult<AiChatMessageListRes> list(AiChatMessageReq req); | 21 | + PageResult<AiChatMessageRespVO> list(AiChatMessageReq req); |
| 23 | 22 | ||
| 24 | /** | 23 | /** |
| 25 | * message - 删除 | 24 | * message - 删除 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java
| 1 | package cn.iocoder.yudao.module.ai.service; | 1 | package cn.iocoder.yudao.module.ai.service; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; | 3 | import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; |
| 4 | -import cn.iocoder.yudao.module.ai.vo.AiChatReq; | 4 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; |
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | * 聊天 chat | 7 | * 聊天 chat |
| @@ -18,7 +18,7 @@ public interface AiChatService { | @@ -18,7 +18,7 @@ public interface AiChatService { | ||
| 18 | * @param req | 18 | * @param req |
| 19 | * @return | 19 | * @return |
| 20 | */ | 20 | */ |
| 21 | - String chat(AiChatReq req); | 21 | + String chat(AiChatMessageSendReqVO req); |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | * chat stream | 24 | * chat stream |
| @@ -27,5 +27,5 @@ public interface AiChatService { | @@ -27,5 +27,5 @@ public interface AiChatService { | ||
| 27 | * @param sseEmitter | 27 | * @param sseEmitter |
| 28 | * @return | 28 | * @return |
| 29 | */ | 29 | */ |
| 30 | - void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter); | 30 | + void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter); |
| 31 | } | 31 | } |
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; | @@ -11,8 +11,7 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; | ||
| 11 | import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper; | 11 | import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper; |
| 12 | import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper; | 12 | import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper; |
| 13 | import cn.iocoder.yudao.module.ai.service.AiChatMessageService; | 13 | import cn.iocoder.yudao.module.ai.service.AiChatMessageService; |
| 14 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes; | ||
| 15 | -import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq; | 14 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; |
| 16 | import lombok.AllArgsConstructor; | 15 | import lombok.AllArgsConstructor; |
| 17 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| @@ -35,7 +34,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { | @@ -35,7 +34,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { | ||
| 35 | private final AiChatConversationMapper aiChatConversationMapper; | 34 | private final AiChatConversationMapper aiChatConversationMapper; |
| 36 | 35 | ||
| 37 | @Override | 36 | @Override |
| 38 | - public PageResult<AiChatMessageListRes> list(AiChatMessageReq req) { | 37 | + public PageResult<AiChatMessageRespVO> list(AiChatMessageReq req) { |
| 39 | // 查询 | 38 | // 查询 |
| 40 | LambdaQueryWrapperX<AiChatMessageDO> queryWrapperX = new LambdaQueryWrapperX<>(); | 39 | LambdaQueryWrapperX<AiChatMessageDO> queryWrapperX = new LambdaQueryWrapperX<>(); |
| 41 | queryWrapperX.eq(AiChatMessageDO::getConversationId, req.getChatConversationId()); | 40 | queryWrapperX.eq(AiChatMessageDO::getConversationId, req.getChatConversationId()); |
| @@ -43,7 +42,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { | @@ -43,7 +42,7 @@ public class AiChatMessageServiceImpl implements AiChatMessageService { | ||
| 43 | queryWrapperX.orderByDesc(AiChatMessageDO::getId); | 42 | queryWrapperX.orderByDesc(AiChatMessageDO::getId); |
| 44 | PageResult<AiChatMessageDO> pageResult = aiChatMessageMapper.selectPage(req, queryWrapperX); | 43 | PageResult<AiChatMessageDO> pageResult = aiChatMessageMapper.selectPage(req, queryWrapperX); |
| 45 | // 转换 res | 44 | // 转换 res |
| 46 | - List<AiChatMessageListRes> messageListResList = AiChatMessageConvert.INSTANCE.convert(pageResult.getList()); | 45 | + List<AiChatMessageRespVO> messageListResList = AiChatMessageConvert.INSTANCE.convert(pageResult.getList()); |
| 47 | return new PageResult(messageListResList, pageResult.getTotal()); | 46 | return new PageResult(messageListResList, pageResult.getTotal()); |
| 48 | } | 47 | } |
| 49 | 48 |
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; | @@ -17,7 +17,7 @@ import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; | ||
| 17 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; | 17 | import cn.iocoder.yudao.module.ai.service.AiChatConversationService; |
| 18 | import cn.iocoder.yudao.module.ai.service.AiChatService; | 18 | import cn.iocoder.yudao.module.ai.service.AiChatService; |
| 19 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; | 19 | import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; |
| 20 | -import cn.iocoder.yudao.module.ai.vo.AiChatReq; | 20 | +import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; |
| 21 | import lombok.AllArgsConstructor; | 21 | import lombok.AllArgsConstructor; |
| 22 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| 23 | import org.springframework.http.MediaType; | 23 | import org.springframework.http.MediaType; |
| @@ -53,7 +53,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -53,7 +53,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 53 | * @return | 53 | * @return |
| 54 | */ | 54 | */ |
| 55 | @Transactional(rollbackFor = Exception.class) | 55 | @Transactional(rollbackFor = Exception.class) |
| 56 | - public String chat(AiChatReq req) { | 56 | + public String chat(AiChatMessageSendReqVO req) { |
| 57 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); | 57 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 58 | // 获取 client 类型 | 58 | // 获取 client 类型 |
| 59 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); | 59 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); |
| @@ -83,7 +83,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -83,7 +83,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 83 | return content; | 83 | return content; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | - private void saveChatMessage(AiChatReq req, AiChatConversationRespVO conversationRes, Long loginUserId) { | 86 | + private void saveChatMessage(AiChatMessageSendReqVO req, AiChatConversationRespVO conversationRes, Long loginUserId) { |
| 87 | Long chatConversationId = conversationRes.getId(); | 87 | Long chatConversationId = conversationRes.getId(); |
| 88 | // 增加 chat message 记录 | 88 | // 增加 chat message 记录 |
| 89 | aiChatMessageMapper.insert( | 89 | aiChatMessageMapper.insert( |
| @@ -101,7 +101,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -101,7 +101,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 101 | aiChatConversationMapper.updateIncrChatCount(req.getConversationId()); | 101 | aiChatConversationMapper.updateIncrChatCount(req.getConversationId()); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | - public void saveSystemChatMessage(AiChatReq req, AiChatConversationRespVO conversationRes, Long loginUserId, String systemPrompts) { | 104 | + public void saveSystemChatMessage(AiChatMessageSendReqVO req, AiChatConversationRespVO conversationRes, Long loginUserId, String systemPrompts) { |
| 105 | Long chatConversationId = conversationRes.getId(); | 105 | Long chatConversationId = conversationRes.getId(); |
| 106 | // 增加 chat message 记录 | 106 | // 增加 chat message 记录 |
| 107 | aiChatMessageMapper.insert( | 107 | aiChatMessageMapper.insert( |
| @@ -128,7 +128,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -128,7 +128,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 128 | * @return | 128 | * @return |
| 129 | */ | 129 | */ |
| 130 | @Override | 130 | @Override |
| 131 | - public void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter) { | 131 | + public void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter) { |
| 132 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); | 132 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 133 | // 获取 client 类型 | 133 | // 获取 client 类型 |
| 134 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); | 134 | AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getModal()); |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageDeleteReq.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | -import jakarta.validation.constraints.NotNull; | ||
| 6 | -import lombok.Data; | ||
| 7 | -import lombok.experimental.Accessors; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * chat message list req | ||
| 11 | - * | ||
| 12 | - * @author fansili | ||
| 13 | - * @time 2024/4/14 16:12 | ||
| 14 | - * @since 1.0 | ||
| 15 | - */ | ||
| 16 | -@Data | ||
| 17 | -@Accessors(chain = true) | ||
| 18 | -public class AiChatMessageDeleteReq extends PageParam { | ||
| 19 | - | ||
| 20 | - @Schema(description = "id") | ||
| 21 | - @NotNull | ||
| 22 | - private Long id; | ||
| 23 | - | ||
| 24 | - @Schema(description = "聊天ID,关联到特定的会话或对话") | ||
| 25 | - @NotNull | ||
| 26 | - private Long chatConversationId; | ||
| 27 | - | ||
| 28 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageListRes.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 | - * 看板 message list req | ||
| 9 | - * | ||
| 10 | - * @author fansili | ||
| 11 | - * @time 2024/4/24 17:28 | ||
| 12 | - * @since 1.0 | ||
| 13 | - */ | ||
| 14 | -@Data | ||
| 15 | -@Accessors(chain = true) | ||
| 16 | -public class AiChatMessageListRes { | ||
| 17 | - | ||
| 18 | - @Schema(description = "编号") | ||
| 19 | - private Long id; | ||
| 20 | - | ||
| 21 | - @Schema(description = "聊天ID,关联到特定的会话或对话") | ||
| 22 | - private Long chatConversationId; | ||
| 23 | - | ||
| 24 | - @Schema(description = "角色ID,用于标识发送消息的用户或系统的身份") | ||
| 25 | - private Long userId; | ||
| 26 | - | ||
| 27 | - @Schema(description = "消息具体内容,存储用户的发言或者系统响应的文字信息") | ||
| 28 | - private String message; | ||
| 29 | - | ||
| 30 | - @Schema(description = "消息类型,枚举值可能包括'system'(系统消息)、'user'(用户消息)和'assistant'(助手消息)") | ||
| 31 | - private String messageType; | ||
| 32 | - | ||
| 33 | - @Schema(description = "在生成消息时采用的Top-K采样大小") | ||
| 34 | - private Double topK; | ||
| 35 | - | ||
| 36 | - @Schema(description = "Top-P核采样方法的概率阈值") | ||
| 37 | - private Double topP; | ||
| 38 | - | ||
| 39 | - @Schema(description = "温度参数,用于调整生成回复的随机性和多样性程度,") | ||
| 40 | - private Double temperature; | ||
| 41 | - | ||
| 42 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatMessageReq.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | -import jakarta.validation.constraints.NotNull; | ||
| 6 | -import lombok.Data; | ||
| 7 | -import lombok.experimental.Accessors; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * chat message list req | ||
| 11 | - * | ||
| 12 | - * @author fansili | ||
| 13 | - * @time 2024/4/14 16:12 | ||
| 14 | - * @since 1.0 | ||
| 15 | - */ | ||
| 16 | -@Data | ||
| 17 | -@Accessors(chain = true) | ||
| 18 | -public class AiChatMessageReq extends PageParam { | ||
| 19 | - | ||
| 20 | - @Schema(description = "聊天ID,关联到特定的会话或对话") | ||
| 21 | - @NotNull | ||
| 22 | - private Long chatConversationId; | ||
| 23 | - | ||
| 24 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReq.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 jakarta.validation.constraints.Size; | ||
| 6 | -import lombok.Data; | ||
| 7 | -import lombok.experimental.Accessors; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * chat req | ||
| 11 | - * | ||
| 12 | - * @author fansili | ||
| 13 | - * @time 2024/4/14 16:12 | ||
| 14 | - * @since 1.0 | ||
| 15 | - */ | ||
| 16 | -@Data | ||
| 17 | -@Accessors(chain = true) | ||
| 18 | -public class AiChatReq { | ||
| 19 | - | ||
| 20 | - @Schema(description = "ai模型(查看 AiClientNameEnum)") | ||
| 21 | - @NotNull(message = "模型不能为空!") | ||
| 22 | - @Size(max = 30, message = "模型字符最大 30个字符!") | ||
| 23 | - private String modal; | ||
| 24 | - | ||
| 25 | - @Schema(description = "对话Id") | ||
| 26 | - @NotNull(message = "对话id不能为空") | ||
| 27 | - private Long conversationId; | ||
| 28 | - | ||
| 29 | - @Schema(description = "chat角色模板") | ||
| 30 | - private Long chatRoleId; | ||
| 31 | - | ||
| 32 | - @NotNull(message = "提示词不能为空!") | ||
| 33 | - @Size(max = 5000, message = "提示词最大5000个字符!") | ||
| 34 | - @Schema(description = "填入固定值,1 issues, 2 pr") | ||
| 35 | - private String prompt; | ||
| 36 | - | ||
| 37 | - @Schema(description = "用于控制随机性和多样性的温度参数") | ||
| 38 | - private Double temperature; | ||
| 39 | - | ||
| 40 | - @Schema(description = "生成时,核采样方法的概率阈值。例如,取值为0.8时,仅保留累计概率之和大于等于0.8的概率分布中的token,\n" + | ||
| 41 | - " * 作为随机采样的候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的随机性越低。\n" + | ||
| 42 | - " * 默认值为0.8。注意,取值不要大于等于1\n") | ||
| 43 | - private Double topP; | ||
| 44 | - | ||
| 45 | - @Schema(description = "在生成消息时采用的Top-K采样大小,表示模型生成回复时考虑的候选项集合的大小") | ||
| 46 | - private Double topK; | ||
| 47 | - | ||
| 48 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/AiChatReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.ai.enums.AiOpenAiModelEnum; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | -import jakarta.validation.constraints.NotNull; | ||
| 6 | -import lombok.Data; | ||
| 7 | - | ||
| 8 | -// TODO done @fansili 1)swagger 注释不太对;2)有了 swagger 注释,就不用类注释了 | ||
| 9 | -@Data | ||
| 10 | -@Schema(description = "用户 App - 上传文件 Request VO") | ||
| 11 | -public class AiChatReqVO { | ||
| 12 | - | ||
| 13 | - @Schema(description = "提示词", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 14 | - @NotNull(message = "提示词不能为空!") | ||
| 15 | - private String prompt; | ||
| 16 | - | ||
| 17 | - @Schema(description = "AI模型", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 18 | - @NotNull(message = "AI模型不能为空") | ||
| 19 | - private AiOpenAiModelEnum aiModel; | ||
| 20 | - | ||
| 21 | -} |