mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 09:30:05 +08:00
【优化】代码优化,统一增加ai前缀
This commit is contained in:
parent
5cec6d52e0
commit
71e3240af6
@ -13,7 +13,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ChatConversationTypeEnum {
|
||||
public enum AiChatConversationTypeEnum {
|
||||
|
||||
// roleChat、userChat
|
||||
ROLE_CHAT("roleChat", "角色对话"),
|
||||
@ -25,8 +25,8 @@ public enum ChatConversationTypeEnum {
|
||||
|
||||
private String name;
|
||||
|
||||
public static ChatConversationTypeEnum valueOfType(String type) {
|
||||
for (ChatConversationTypeEnum itemEnum : ChatConversationTypeEnum.values()) {
|
||||
public static AiChatConversationTypeEnum valueOfType(String type) {
|
||||
for (AiChatConversationTypeEnum itemEnum : AiChatConversationTypeEnum.values()) {
|
||||
if (itemEnum.getType().equals(type)) {
|
||||
return itemEnum;
|
||||
}
|
@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ChatRoleClassifyEnum {
|
||||
public enum AiChatRoleClassifyEnum {
|
||||
|
||||
WRITING("writing", "写作"),
|
||||
|
||||
@ -26,8 +26,8 @@ public enum ChatRoleClassifyEnum {
|
||||
private String name;
|
||||
|
||||
|
||||
public static ChatRoleClassifyEnum valueOfClassify(String classify) {
|
||||
for (ChatRoleClassifyEnum itemEnum : ChatRoleClassifyEnum.values()) {
|
||||
public static AiChatRoleClassifyEnum valueOfClassify(String classify) {
|
||||
for (AiChatRoleClassifyEnum itemEnum : AiChatRoleClassifyEnum.values()) {
|
||||
if (itemEnum.getClassify().equals(classify)) {
|
||||
return itemEnum;
|
||||
}
|
@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ChatRoleSourceEnum {
|
||||
public enum AiChatRoleSourceEnum {
|
||||
|
||||
SYSTEM("system", "系统"),
|
||||
CUSTOMER("customer", "用户自定义"),
|
||||
@ -25,8 +25,8 @@ public enum ChatRoleSourceEnum {
|
||||
private String name;
|
||||
|
||||
|
||||
public static ChatRoleSourceEnum valueOfType(String type) {
|
||||
for (ChatRoleSourceEnum itemEnum : ChatRoleSourceEnum.values()) {
|
||||
public static AiChatRoleSourceEnum valueOfType(String type) {
|
||||
for (AiChatRoleSourceEnum itemEnum : AiChatRoleSourceEnum.values()) {
|
||||
if (itemEnum.getType().equals(type)) {
|
||||
return itemEnum;
|
||||
}
|
@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ChatRoleVisibilityEnum {
|
||||
public enum AiChatRoleVisibilityEnum {
|
||||
|
||||
PUBLIC("public", "公开"),
|
||||
PRIVATE("private", "私有的"),
|
||||
@ -24,8 +24,8 @@ public enum ChatRoleVisibilityEnum {
|
||||
private String name;
|
||||
|
||||
|
||||
public static ChatRoleVisibilityEnum valueOfType(String type) {
|
||||
for (ChatRoleVisibilityEnum itemEnum : ChatRoleVisibilityEnum.values()) {
|
||||
public static AiChatRoleVisibilityEnum valueOfType(String type) {
|
||||
for (AiChatRoleVisibilityEnum itemEnum : AiChatRoleVisibilityEnum.values()) {
|
||||
if (itemEnum.getType().equals(type)) {
|
||||
return itemEnum;
|
||||
}
|
@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ChatTypeEnum {
|
||||
public enum AiChatTypeEnum {
|
||||
|
||||
ROLE_CHAT("roleChat", "角色模板聊天"),
|
||||
USER_CHAT("userChat", "用户普通聊天"),
|
||||
@ -23,8 +23,8 @@ public enum ChatTypeEnum {
|
||||
|
||||
private String name;
|
||||
|
||||
public static ChatTypeEnum valueOfType(String type) {
|
||||
for (ChatTypeEnum itemEnum : ChatTypeEnum.values()) {
|
||||
public static AiChatTypeEnum valueOfType(String type) {
|
||||
for (AiChatTypeEnum itemEnum : AiChatTypeEnum.values()) {
|
||||
if (itemEnum.getType().equals(type)) {
|
||||
return itemEnum;
|
||||
}
|
@ -10,7 +10,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OpenAiModelEnum {
|
||||
public enum AiOpenAiModelEnum {
|
||||
|
||||
/**
|
||||
* open ai 3.5模型
|
@ -1,10 +1,8 @@
|
||||
package cn.iocoder.yudao.module.ai.controller;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.ai.chat.ChatResponse;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatReq;
|
||||
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;
|
||||
@ -17,10 +15,6 @@ 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;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* ia 模块
|
||||
@ -34,21 +28,21 @@ import java.util.function.Consumer;
|
||||
@RequestMapping("/ai")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ChatController {
|
||||
public class AiChatController {
|
||||
|
||||
@Autowired
|
||||
private final ChatService chatService;
|
||||
private final AiChatService chatService;
|
||||
|
||||
@Operation(summary = "聊天-chat", description = "这个一般等待时间比较久,需要全部完成才会返回!")
|
||||
@GetMapping("/chat")
|
||||
public CommonResult<String> chat(@Validated @ModelAttribute ChatReq req) {
|
||||
public CommonResult<String> 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 ChatReq req) {
|
||||
public SseEmitter chatStream(@Validated @ModelAttribute AiChatReq req) {
|
||||
Utf8SseEmitter sseEmitter = new Utf8SseEmitter();
|
||||
chatService.chatStream(req, sseEmitter);
|
||||
return sseEmitter;
|
@ -1,11 +1,11 @@
|
||||
package cn.iocoder.yudao.module.ai.controller;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatConversationService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateRoleReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateUserReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationListReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationRes;
|
||||
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;
|
||||
@ -27,31 +27,31 @@ import java.util.List;
|
||||
@RequestMapping("/ai/chat/conversation")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ChatConversationController {
|
||||
public class AiChatConversationController {
|
||||
|
||||
private final ChatConversationService chatConversationService;
|
||||
private final AiChatConversationService chatConversationService;
|
||||
|
||||
@Operation(summary = "创建 - 对话普通对话")
|
||||
@PostMapping("/createConversation")
|
||||
public CommonResult<ChatConversationRes> createConversation(@RequestBody @Validated ChatConversationCreateUserReq req) {
|
||||
public CommonResult<AiChatConversationRes> createConversation(@RequestBody @Validated AiChatConversationCreateUserReq req) {
|
||||
return CommonResult.success(chatConversationService.createConversation(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "创建 - 对话角色对话")
|
||||
@PostMapping("/createRoleConversation")
|
||||
public CommonResult<ChatConversationRes> createRoleConversation(@RequestBody @Validated ChatConversationCreateRoleReq req) {
|
||||
public CommonResult<AiChatConversationRes> createRoleConversation(@RequestBody @Validated AiChatConversationCreateRoleReq req) {
|
||||
return CommonResult.success(chatConversationService.createRoleConversation(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取 - 获取对话")
|
||||
@GetMapping("/{id}")
|
||||
public CommonResult<ChatConversationRes> getConversation(@PathVariable("id") Long id) {
|
||||
public CommonResult<AiChatConversationRes> getConversation(@PathVariable("id") Long id) {
|
||||
return CommonResult.success(chatConversationService.getConversation(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取 - 获取对话list")
|
||||
@GetMapping("/list")
|
||||
public CommonResult<List<ChatConversationRes>> listConversation(@ModelAttribute @Validated ChatConversationListReq req) {
|
||||
public CommonResult<List<AiChatConversationRes>> listConversation(@ModelAttribute @Validated AiChatConversationListReq req) {
|
||||
return CommonResult.success(chatConversationService.listConversation(req));
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ 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.ChatMessageService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageReq;
|
||||
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;
|
||||
@ -24,13 +24,13 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/ai/chat/message")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ChatMessageController {
|
||||
public class AiChatMessageController {
|
||||
|
||||
private final ChatMessageService chatMessageService;
|
||||
private final AiChatMessageService chatMessageService;
|
||||
|
||||
@Operation(summary = "聊天记录", description = "查询个人的聊天记录")
|
||||
@GetMapping("/list")
|
||||
public PageResult<ChatMessageListRes> list(@Validated @ModelAttribute ChatMessageReq req) {
|
||||
public PageResult<AiChatMessageListRes> list(@Validated @ModelAttribute AiChatMessageReq req) {
|
||||
return chatMessageService.list(req);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ 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.ChatRoleService;
|
||||
import cn.iocoder.yudao.module.ai.service.AiChatRoleService;
|
||||
import cn.iocoder.yudao.module.ai.vo.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -22,19 +22,19 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/ai/chat")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ChatRoleController {
|
||||
public class AiChatRoleController {
|
||||
|
||||
private final ChatRoleService chatRoleService;
|
||||
private final AiChatRoleService chatRoleService;
|
||||
|
||||
@Operation(summary = "chat角色 - 角色列表")
|
||||
@GetMapping("/role/list")
|
||||
public PageResult<ChatRoleListRes> list(@Validated @ModelAttribute ChatRoleListReq req) {
|
||||
public PageResult<AiChatRoleListRes> list(@Validated @ModelAttribute AiChatRoleListReq req) {
|
||||
return chatRoleService.list(req);
|
||||
}
|
||||
|
||||
@Operation(summary = "chat角色 - 添加")
|
||||
@PutMapping("/role")
|
||||
public CommonResult<Void> add(@Validated @RequestBody ChatRoleAddReq req) {
|
||||
public CommonResult<Void> add(@Validated @RequestBody AiChatRoleAddReq req) {
|
||||
chatRoleService.add(req);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class ChatRoleController {
|
||||
@Operation(summary = "chat角色 - 修改")
|
||||
@PostMapping("/role/{id}")
|
||||
public CommonResult<Void> update(@PathVariable("id") Long id,
|
||||
@Validated @RequestBody ChatRoleUpdateReq req) {
|
||||
@Validated @RequestBody AiChatRoleUpdateReq req) {
|
||||
chatRoleService.update(id, req);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
@ -50,7 +50,7 @@ public class ChatRoleController {
|
||||
@Operation(summary = "chat角色 - 修改可见性")
|
||||
@PostMapping("/role/{id}/update-visibility")
|
||||
public CommonResult<Void> updateVisibility(@PathVariable("id") Long id,
|
||||
@Validated @RequestBody ChatRoleUpdateVisibilityReq req) {
|
||||
@Validated @RequestBody AiChatRoleUpdateVisibilityReq req) {
|
||||
chatRoleService.updateVisibility(id, req);
|
||||
return CommonResult.success(null);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.ai.convert;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatConversationDO;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatConversationRes;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -15,9 +15,9 @@ import java.util.List;
|
||||
* @since 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatConversationConvert {
|
||||
public interface AiChatConversationConvert {
|
||||
|
||||
ChatConversationConvert INSTANCE = Mappers.getMapper(ChatConversationConvert.class);
|
||||
AiChatConversationConvert INSTANCE = Mappers.getMapper(AiChatConversationConvert.class);
|
||||
|
||||
/**
|
||||
* 转换 - 多个 ChatConversationRes
|
||||
@ -25,7 +25,7 @@ public interface ChatConversationConvert {
|
||||
* @param top100Conversation
|
||||
* @return
|
||||
*/
|
||||
List<ChatConversationRes> covnertChatConversationResList(List<AiChatConversationDO> top100Conversation);
|
||||
List<AiChatConversationRes> covnertChatConversationResList(List<AiChatConversationDO> top100Conversation);
|
||||
|
||||
/**
|
||||
* 转换 - 单个 ChatConversationRes
|
||||
@ -33,5 +33,5 @@ public interface ChatConversationConvert {
|
||||
* @param aiChatConversationDO
|
||||
* @return
|
||||
*/
|
||||
ChatConversationRes covnertChatConversationRes(AiChatConversationDO aiChatConversationDO);
|
||||
AiChatConversationRes covnertChatConversationRes(AiChatConversationDO aiChatConversationDO);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.ai.convert;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -15,9 +15,9 @@ import java.util.List;
|
||||
* @since 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatMessageConvert {
|
||||
public interface AiChatMessageConvert {
|
||||
|
||||
ChatMessageConvert INSTANCE = Mappers.getMapper(ChatMessageConvert.class);
|
||||
AiChatMessageConvert INSTANCE = Mappers.getMapper(AiChatMessageConvert.class);
|
||||
|
||||
/**
|
||||
* 转换 ChatMessageListRes
|
||||
@ -25,5 +25,5 @@ public interface ChatMessageConvert {
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
List<ChatMessageListRes> convert(List<AiChatMessageDO> list);
|
||||
List<AiChatMessageListRes> convert(List<AiChatMessageDO> list);
|
||||
}
|
@ -16,9 +16,9 @@ import java.util.List;
|
||||
* @since 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatModalConvert {
|
||||
public interface AiChatModalConvert {
|
||||
|
||||
ChatModalConvert INSTANCE = Mappers.getMapper(ChatModalConvert.class);
|
||||
AiChatModalConvert INSTANCE = Mappers.getMapper(AiChatModalConvert.class);
|
||||
|
||||
/**
|
||||
* 转换 - AiChatModalListRes
|
@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.ai.convert;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatRoleAddReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatRoleListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatRoleUpdateReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatRoleAddReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatRoleUpdateReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatRoleListRes;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -17,9 +17,9 @@ import java.util.List;
|
||||
* @since 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatRoleConvert {
|
||||
public interface AiChatRoleConvert {
|
||||
|
||||
ChatRoleConvert INSTANCE = Mappers.getMapper(ChatRoleConvert.class);
|
||||
AiChatRoleConvert INSTANCE = Mappers.getMapper(AiChatRoleConvert.class);
|
||||
|
||||
/**
|
||||
* 转换 - ChatRoleListRes
|
||||
@ -27,7 +27,7 @@ public interface ChatRoleConvert {
|
||||
* @param roleList
|
||||
* @return
|
||||
*/
|
||||
List<ChatRoleListRes> convertChatRoleListRes(List<AiChatRoleDO> roleList);
|
||||
List<AiChatRoleListRes> convertChatRoleListRes(List<AiChatRoleDO> roleList);
|
||||
|
||||
/**
|
||||
* 转换 - AiChatRoleDO
|
||||
@ -35,7 +35,7 @@ public interface ChatRoleConvert {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
AiChatRoleDO convertAiChatRoleDO(ChatRoleAddReq req);
|
||||
AiChatRoleDO convertAiChatRoleDO(AiChatRoleAddReq req);
|
||||
|
||||
/**
|
||||
* 转换 - AiChatRoleDO
|
||||
@ -43,5 +43,5 @@ public interface ChatRoleConvert {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
AiChatRoleDO convertAiChatRoleDO(ChatRoleUpdateReq req);
|
||||
AiChatRoleDO convertAiChatRoleDO(AiChatRoleUpdateReq req);
|
||||
}
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.ai.mapper;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* chat 对话
|
||||
*
|
||||
* @fansili
|
||||
* @since v1.0
|
||||
*/
|
||||
public interface AiChatConversationService {
|
||||
|
||||
/**
|
||||
* 对话 - 创建普通对话
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
AiChatConversationRes createConversation(AiChatConversationCreateUserReq req);
|
||||
|
||||
/**
|
||||
* 对话 - 创建role对话
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
AiChatConversationRes createRoleConversation(AiChatConversationCreateRoleReq req);
|
||||
|
||||
|
||||
/**
|
||||
* 获取 - 对话
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
AiChatConversationRes getConversation(Long id);
|
||||
|
||||
/**
|
||||
* 获取 - 对话列表
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
List<AiChatConversationRes> listConversation(AiChatConversationListReq req);
|
||||
|
||||
/**
|
||||
* 删除 - 根据id
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void delete(Long id);
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package cn.iocoder.yudao.module.ai.service;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatMessageListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatMessageReq;
|
||||
|
||||
/**
|
||||
* chat message
|
||||
@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.ai.vo.ChatMessageReq;
|
||||
* @time 2024/4/24 17:25
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface ChatMessageService {
|
||||
public interface AiChatMessageService {
|
||||
|
||||
/**
|
||||
* message - 列表
|
||||
@ -19,7 +19,7 @@ public interface ChatMessageService {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
PageResult<ChatMessageListRes> list(ChatMessageReq req);
|
||||
PageResult<AiChatMessageListRes> list(AiChatMessageReq req);
|
||||
|
||||
/**
|
||||
* message - 删除
|
@ -1,18 +1,15 @@
|
||||
package cn.iocoder.yudao.module.ai.service;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.ai.vo.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* chat 角色
|
||||
*
|
||||
* @fansili
|
||||
* @since v1.0
|
||||
*/
|
||||
public interface ChatRoleService {
|
||||
public interface AiChatRoleService {
|
||||
|
||||
/**
|
||||
* 获取聊天角色列表
|
||||
@ -20,7 +17,7 @@ public interface ChatRoleService {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
PageResult<ChatRoleListRes> list(ChatRoleListReq req);
|
||||
PageResult<AiChatRoleListRes> list(AiChatRoleListReq req);
|
||||
|
||||
/**
|
||||
* chat角色 - 添加
|
||||
@ -28,7 +25,7 @@ public interface ChatRoleService {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
void add(ChatRoleAddReq req);
|
||||
void add(AiChatRoleAddReq req);
|
||||
|
||||
/**
|
||||
* chat角色 - 修改
|
||||
@ -36,7 +33,7 @@ public interface ChatRoleService {
|
||||
* @param id
|
||||
* @param req
|
||||
*/
|
||||
void update(Long id, ChatRoleUpdateReq req);
|
||||
void update(Long id, AiChatRoleUpdateReq req);
|
||||
|
||||
|
||||
/**
|
||||
@ -45,7 +42,7 @@ public interface ChatRoleService {
|
||||
* @param id
|
||||
* @param req
|
||||
*/
|
||||
void updateVisibility(Long id, ChatRoleUpdateVisibilityReq req);
|
||||
void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req);
|
||||
|
||||
/**
|
||||
* chat角色 - 删除
|
@ -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.ChatReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.AiChatReq;
|
||||
|
||||
/**
|
||||
* 聊天 chat
|
||||
@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.ai.vo.ChatReq;
|
||||
* @time 2024/4/14 15:55
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface ChatService {
|
||||
public interface AiChatService {
|
||||
|
||||
/**
|
||||
* chat
|
||||
@ -18,7 +18,7 @@ public interface ChatService {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
String chat(ChatReq req);
|
||||
String chat(AiChatReq req);
|
||||
|
||||
/**
|
||||
* chat stream
|
||||
@ -27,5 +27,5 @@ public interface ChatService {
|
||||
* @param sseEmitter
|
||||
* @return
|
||||
*/
|
||||
void chatStream(ChatReq req, Utf8SseEmitter sseEmitter);
|
||||
void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter);
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package cn.iocoder.yudao.module.ai.service;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateRoleReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateUserReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationListReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationRes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* chat 对话
|
||||
*
|
||||
* @fansili
|
||||
* @since v1.0
|
||||
*/
|
||||
public interface ChatConversationService {
|
||||
|
||||
/**
|
||||
* 对话 - 创建普通对话
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
ChatConversationRes createConversation(ChatConversationCreateUserReq req);
|
||||
|
||||
/**
|
||||
* 对话 - 创建role对话
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
ChatConversationRes createRoleConversation(ChatConversationCreateRoleReq req);
|
||||
|
||||
|
||||
/**
|
||||
* 获取 - 对话
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
ChatConversationRes getConversation(Long id);
|
||||
|
||||
/**
|
||||
* 获取 - 对话列表
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
List<ChatConversationRes> listConversation(ChatConversationListReq req);
|
||||
|
||||
/**
|
||||
* 删除 - 根据id
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void delete(Long id);
|
||||
|
||||
}
|
@ -3,17 +3,17 @@ 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.convert.ChatConversationConvert;
|
||||
import cn.iocoder.yudao.module.ai.convert.AiChatConversationConvert;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatConversationDO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO;
|
||||
import cn.iocoder.yudao.module.ai.enums.ChatConversationTypeEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiChatConversationTypeEnum;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatConversationService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateRoleReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationCreateUserReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationListReq;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationRes;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -30,51 +30,51 @@ import java.util.List;
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ChatConversationServiceImpl implements ChatConversationService {
|
||||
public class AiChatConversationServiceImpl implements AiChatConversationService {
|
||||
|
||||
private final AiChatRoleMapper aiChatRoleMapper;
|
||||
private final AiChatConversationMapper aiChatConversationMapper;
|
||||
|
||||
@Override
|
||||
public ChatConversationRes createConversation(ChatConversationCreateUserReq req) {
|
||||
public AiChatConversationRes createConversation(AiChatConversationCreateUserReq req) {
|
||||
// 获取用户id
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// 查询最新的对话
|
||||
AiChatConversationDO latestConversation = aiChatConversationMapper.selectLatestConversation(loginUserId);
|
||||
// 如果有对话没有被使用过,那就返回这个
|
||||
if (latestConversation != null && latestConversation.getChatCount() <= 0) {
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation);
|
||||
}
|
||||
// 创建新的 Conversation
|
||||
AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId,
|
||||
null, null, ChatConversationTypeEnum.USER_CHAT);
|
||||
null, null, AiChatConversationTypeEnum.USER_CHAT);
|
||||
// 转换 res
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatConversationRes createRoleConversation(ChatConversationCreateRoleReq req) {
|
||||
public AiChatConversationRes createRoleConversation(AiChatConversationCreateRoleReq req) {
|
||||
// 获取用户id
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// 查询最新的对话
|
||||
AiChatConversationDO latestConversation = aiChatConversationMapper.selectLatestConversation(loginUserId);
|
||||
// 如果有对话没有被使用过,那就返回这个
|
||||
if (latestConversation != null && latestConversation.getChatCount() <= 0) {
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(latestConversation);
|
||||
}
|
||||
AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getChatRoleId());
|
||||
// 创建新的 Conversation
|
||||
AiChatConversationDO insertConversation = saveConversation(req.getTitle(), loginUserId,
|
||||
req.getChatRoleId(), aiChatRoleDO.getRoleName(), ChatConversationTypeEnum.ROLE_CHAT);
|
||||
req.getChatRoleId(), aiChatRoleDO.getRoleName(), AiChatConversationTypeEnum.ROLE_CHAT);
|
||||
// 转换 res
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(insertConversation);
|
||||
}
|
||||
|
||||
private @NotNull AiChatConversationDO saveConversation(String title,
|
||||
Long userId,
|
||||
Long chatRoleId,
|
||||
String chatRoleName,
|
||||
ChatConversationTypeEnum typeEnum) {
|
||||
AiChatConversationTypeEnum typeEnum) {
|
||||
AiChatConversationDO insertConversation = new AiChatConversationDO();
|
||||
insertConversation.setId(null);
|
||||
insertConversation.setUserId(userId);
|
||||
@ -88,22 +88,22 @@ public class ChatConversationServiceImpl implements ChatConversationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatConversationRes getConversation(Long id) {
|
||||
public AiChatConversationRes getConversation(Long id) {
|
||||
AiChatConversationDO aiChatConversationDO = aiChatConversationMapper.selectById(id);
|
||||
if (aiChatConversationDO == null) {
|
||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CHAT_CONTINUE_NOT_EXIST);
|
||||
}
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationRes(aiChatConversationDO);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationRes(aiChatConversationDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatConversationRes> listConversation(ChatConversationListReq req) {
|
||||
public List<AiChatConversationRes> listConversation(AiChatConversationListReq req) {
|
||||
// 获取用户id
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// 查询前100对话
|
||||
List<AiChatConversationDO> top100Conversation
|
||||
= aiChatConversationMapper.selectTop100Conversation(loginUserId, req.getSearch());
|
||||
return ChatConversationConvert.INSTANCE.covnertChatConversationResList(top100Conversation);
|
||||
return AiChatConversationConvert.INSTANCE.covnertChatConversationResList(top100Conversation);
|
||||
}
|
||||
|
||||
@Override
|
@ -5,14 +5,14 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
|
||||
import cn.iocoder.yudao.module.ai.convert.ChatMessageConvert;
|
||||
import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatConversationDO;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatMessageService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageListRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatMessageReq;
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -29,13 +29,13 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ChatMessageServiceImpl implements ChatMessageService {
|
||||
public class AiChatMessageServiceImpl implements AiChatMessageService {
|
||||
|
||||
private final AiChatMessageMapper aiChatMessageMapper;
|
||||
private final AiChatConversationMapper aiChatConversationMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<ChatMessageListRes> list(ChatMessageReq req) {
|
||||
public PageResult<AiChatMessageListRes> list(AiChatMessageReq req) {
|
||||
// 查询
|
||||
LambdaQueryWrapperX<AiChatMessageDO> queryWrapperX = new LambdaQueryWrapperX<>();
|
||||
queryWrapperX.eq(AiChatMessageDO::getChatConversationId, req.getChatConversationId());
|
||||
@ -43,7 +43,7 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
||||
queryWrapperX.orderByDesc(AiChatMessageDO::getId);
|
||||
PageResult<AiChatMessageDO> pageResult = aiChatMessageMapper.selectPage(req, queryWrapperX);
|
||||
// 转换 res
|
||||
List<ChatMessageListRes> messageListResList = ChatMessageConvert.INSTANCE.convert(pageResult.getList());
|
||||
List<AiChatMessageListRes> messageListResList = AiChatMessageConvert.INSTANCE.convert(pageResult.getList());
|
||||
return new PageResult(messageListResList, pageResult.getTotal());
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
|
||||
import cn.iocoder.yudao.module.ai.convert.ChatModalConvert;
|
||||
import cn.iocoder.yudao.module.ai.convert.AiChatModalConvert;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatModalMapper;
|
||||
@ -47,14 +47,14 @@ public class AiChatModalServiceImpl implements AiChatModalService {
|
||||
// 查询
|
||||
PageResult<AiChatModalDO> aiChatModalDOPageResult = aiChatModalMapper.selectPage(req, queryWrapperX);
|
||||
// 转换 res
|
||||
List<AiChatModalListRes> resList = ChatModalConvert.INSTANCE.convertAiChatModalListRes(aiChatModalDOPageResult.getList());
|
||||
List<AiChatModalListRes> resList = AiChatModalConvert.INSTANCE.convertAiChatModalListRes(aiChatModalDOPageResult.getList());
|
||||
return new PageResult<>(resList, aiChatModalDOPageResult.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(AiChatModalAddReq req) {
|
||||
// 转换 do
|
||||
AiChatModalDO insertChatModalDO = ChatModalConvert.INSTANCE.convertAiChatModalDO(req);
|
||||
AiChatModalDO insertChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req);
|
||||
//
|
||||
insertChatModalDO.setDisable(AiChatModalDisableEnum.NO.getValue());
|
||||
// 保存数据库
|
||||
@ -66,7 +66,7 @@ public class AiChatModalServiceImpl implements AiChatModalService {
|
||||
// 校验模型是否存在
|
||||
validateChatModalExists(id);
|
||||
// 转换 updateChatModalDO
|
||||
AiChatModalDO updateChatModalDO = ChatModalConvert.INSTANCE.convertAiChatModalDO(req);
|
||||
AiChatModalDO updateChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req);
|
||||
updateChatModalDO.setId(id);
|
||||
// 更新数据库
|
||||
aiChatModalMapper.updateById(updateChatModalDO);
|
||||
|
@ -6,13 +6,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
|
||||
import cn.iocoder.yudao.module.ai.convert.ChatRoleConvert;
|
||||
import cn.iocoder.yudao.module.ai.convert.AiChatRoleConvert;
|
||||
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO;
|
||||
import cn.iocoder.yudao.module.ai.enums.ChatRoleClassifyEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.ChatRoleSourceEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.ChatRoleVisibilityEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiChatRoleClassifyEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiChatRoleSourceEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiChatRoleVisibilityEnum;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatRoleService;
|
||||
import cn.iocoder.yudao.module.ai.service.AiChatRoleService;
|
||||
import cn.iocoder.yudao.module.ai.vo.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -29,12 +29,12 @@ import java.util.List;
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class ChatRoleServiceImpl implements ChatRoleService {
|
||||
public class AiChatRoleServiceImpl implements AiChatRoleService {
|
||||
|
||||
private final AiChatRoleMapper aiChatRoleMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<ChatRoleListRes> list(ChatRoleListReq req) {
|
||||
public PageResult<AiChatRoleListRes> list(AiChatRoleListReq req) {
|
||||
// 查询条件
|
||||
LambdaQueryWrapperX<AiChatRoleDO> queryWrapperX = new LambdaQueryWrapperX<>();
|
||||
// search 查询
|
||||
@ -48,18 +48,18 @@ public class ChatRoleServiceImpl implements ChatRoleService {
|
||||
Long total = aiChatRoleDOPageResult.getTotal();
|
||||
List<AiChatRoleDO> roleList = aiChatRoleDOPageResult.getList();
|
||||
// 换货res
|
||||
List<ChatRoleListRes> chatRoleListResList = ChatRoleConvert.INSTANCE.convertChatRoleListRes(roleList);
|
||||
List<AiChatRoleListRes> chatRoleListResList = AiChatRoleConvert.INSTANCE.convertChatRoleListRes(roleList);
|
||||
return new PageResult<>(chatRoleListResList, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ChatRoleAddReq req) {
|
||||
public void add(AiChatRoleAddReq req) {
|
||||
// 转换enum,并校验enum
|
||||
ChatRoleClassifyEnum.valueOfClassify(req.getClassify());
|
||||
ChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
ChatRoleSourceEnum.valueOfType(req.getRoleSource());
|
||||
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
|
||||
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
|
||||
// 转换do
|
||||
AiChatRoleDO insertAiChatRoleDO = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
|
||||
AiChatRoleDO insertAiChatRoleDO = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
|
||||
insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId());
|
||||
insertAiChatRoleDO.setUseCount(0);
|
||||
// 保存
|
||||
@ -67,24 +67,24 @@ public class ChatRoleServiceImpl implements ChatRoleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Long id, ChatRoleUpdateReq req) {
|
||||
public void update(Long id, AiChatRoleUpdateReq req) {
|
||||
// 转换enum,并校验enum
|
||||
ChatRoleClassifyEnum.valueOfClassify(req.getClassify());
|
||||
ChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
ChatRoleSourceEnum.valueOfType(req.getRoleSource());
|
||||
AiChatRoleClassifyEnum.valueOfClassify(req.getClassify());
|
||||
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
AiChatRoleSourceEnum.valueOfType(req.getRoleSource());
|
||||
// 检查角色是否存在
|
||||
validateChatRoleExists(id);
|
||||
// 转换do
|
||||
AiChatRoleDO updateChatRole = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
|
||||
AiChatRoleDO updateChatRole = AiChatRoleConvert.INSTANCE.convertAiChatRoleDO(req);
|
||||
updateChatRole.setId(id);
|
||||
aiChatRoleMapper.updateById(updateChatRole);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateVisibility(Long id, ChatRoleUpdateVisibilityReq req) {
|
||||
public void updateVisibility(Long id, AiChatRoleUpdateVisibilityReq req) {
|
||||
// 转换enum,并校验enum
|
||||
ChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
AiChatRoleVisibilityEnum.valueOfType(req.getVisibility());
|
||||
// 检查角色是否存在
|
||||
validateChatRoleExists(id);
|
||||
// 更新
|
@ -12,10 +12,10 @@ import cn.iocoder.yudao.module.ai.enums.AiClientNameEnum;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper;
|
||||
import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatConversationService;
|
||||
import cn.iocoder.yudao.module.ai.service.ChatService;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatConversationRes;
|
||||
import cn.iocoder.yudao.module.ai.vo.ChatReq;
|
||||
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.vo.AiChatReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -36,13 +36,13 @@ import java.util.function.Consumer;
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
public class AiChatServiceImpl implements AiChatService {
|
||||
|
||||
private final AiClient aiClient;
|
||||
private final AiChatRoleMapper aiChatRoleMapper;
|
||||
private final AiChatMessageMapper aiChatMessageMapper;
|
||||
private final AiChatConversationMapper aiChatConversationMapper;
|
||||
private final ChatConversationService chatConversationService;
|
||||
private final AiChatConversationService chatConversationService;
|
||||
|
||||
/**
|
||||
* chat
|
||||
@ -51,12 +51,12 @@ public class ChatServiceImpl implements ChatService {
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String chat(ChatReq req) {
|
||||
public String chat(AiChatReq req) {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// 获取 client 类型
|
||||
AiClientNameEnum clientNameEnum = AiClientNameEnum.valueOfName(req.getModal());
|
||||
// 获取对话信息
|
||||
ChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId());
|
||||
AiChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId());
|
||||
// 保存 chat message
|
||||
saveChatMessage(req, conversationRes, loginUserId);
|
||||
String content = null;
|
||||
@ -80,7 +80,7 @@ public class ChatServiceImpl implements ChatService {
|
||||
return content;
|
||||
}
|
||||
|
||||
private void saveChatMessage(ChatReq req, ChatConversationRes conversationRes, Long loginUserId) {
|
||||
private void saveChatMessage(AiChatReq req, AiChatConversationRes conversationRes, Long loginUserId) {
|
||||
Long chatConversationId = conversationRes.getId();
|
||||
// 增加 chat message 记录
|
||||
aiChatMessageMapper.insert(
|
||||
@ -98,7 +98,7 @@ public class ChatServiceImpl implements ChatService {
|
||||
aiChatConversationMapper.updateIncrChatCount(req.getConversationId());
|
||||
}
|
||||
|
||||
public void saveSystemChatMessage(ChatReq req, ChatConversationRes conversationRes, Long loginUserId, String systemPrompts) {
|
||||
public void saveSystemChatMessage(AiChatReq req, AiChatConversationRes conversationRes, Long loginUserId, String systemPrompts) {
|
||||
Long chatConversationId = conversationRes.getId();
|
||||
// 增加 chat message 记录
|
||||
aiChatMessageMapper.insert(
|
||||
@ -125,12 +125,12 @@ public class ChatServiceImpl implements ChatService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void chatStream(ChatReq req, Utf8SseEmitter sseEmitter) {
|
||||
public void chatStream(AiChatReq req, Utf8SseEmitter sseEmitter) {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
// 获取 client 类型
|
||||
AiClientNameEnum clientNameEnum = AiClientNameEnum.valueOfName(req.getModal());
|
||||
// 获取对话信息
|
||||
ChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId());
|
||||
AiChatConversationRes conversationRes = chatConversationService.getConversation(req.getConversationId());
|
||||
// 创建 chat 需要的 Prompt
|
||||
Prompt prompt = new Prompt(req.getPrompt());
|
||||
req.setTopK(req.getTopK());
|
@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatConversationCreateRoleReq {
|
||||
public class AiChatConversationCreateRoleReq {
|
||||
|
||||
@Schema(description = "chat角色Id")
|
||||
@NotNull(message = "聊天角色id不能为空!")
|
@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatConversationCreateUserReq {
|
||||
public class AiChatConversationCreateUserReq {
|
||||
|
||||
@Schema(description = "对话标题")
|
||||
@NotNull(message = "标题不能为空!")
|
@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatConversationListReq {
|
||||
public class AiChatConversationListReq {
|
||||
|
||||
@Schema(description = "查询根据title")
|
||||
private String search;
|
@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatConversationRes {
|
||||
public class AiChatConversationRes {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatMessageDeleteReq extends PageParam {
|
||||
public class AiChatMessageDeleteReq extends PageParam {
|
||||
|
||||
@Schema(description = "id")
|
||||
@NotNull
|
@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatMessageListRes {
|
||||
public class AiChatMessageListRes {
|
||||
|
||||
@Schema(description = "编号")
|
||||
private Long id;
|
@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatMessageReq extends PageParam {
|
||||
public class AiChatMessageReq extends PageParam {
|
||||
|
||||
@Schema(description = "聊天ID,关联到特定的会话或对话")
|
||||
@NotNull
|
@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatReq {
|
||||
public class AiChatReq {
|
||||
|
||||
@Schema(description = "ai模型(查看 AiClientNameEnum)")
|
||||
@NotNull(message = "模型不能为空!")
|
@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.ai.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.ai.enums.OpenAiModelEnum;
|
||||
import cn.iocoder.yudao.module.ai.enums.AiOpenAiModelEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@ -16,6 +16,6 @@ public class AiChatReqVO {
|
||||
|
||||
@Schema(description = "AI模型", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "AI模型不能为空")
|
||||
private OpenAiModelEnum aiModel;
|
||||
private AiOpenAiModelEnum aiModel;
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatRoleAddReq extends PageParam {
|
||||
public class AiChatRoleAddReq extends PageParam {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "模型编号,关联到角色使用的特定模型")
|
@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatRoleListReq extends PageParam {
|
||||
public class AiChatRoleListReq extends PageParam {
|
||||
|
||||
@Schema(description = "查询")
|
||||
private String search;
|
@ -12,7 +12,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatRoleListRes {
|
||||
public class AiChatRoleListRes {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatRoleUpdateReq extends PageParam {
|
||||
public class AiChatRoleUpdateReq extends PageParam {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "模型编号,关联到角色使用的特定模型")
|
@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ChatRoleUpdateVisibilityReq extends PageParam {
|
||||
public class AiChatRoleUpdateVisibilityReq extends PageParam {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用")
|
Loading…
Reference in New Issue
Block a user