Commit 929f3597fdfb00da67dfbf821379267e27fd9859
1 parent
f0a1666e
【调整】调整Ai model
Showing
10 changed files
with
161 additions
and
165 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiChatModalDisableEnum.java deleted
| 1 | -package cn.iocoder.yudao.module.ai.enums; | |
| 2 | - | |
| 3 | -import lombok.AllArgsConstructor; | |
| 4 | -import lombok.Getter; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * ai modal disable | |
| 8 | - * | |
| 9 | - * @author fansili | |
| 10 | - * @time 2024/4/24 20:15 | |
| 11 | - * @since 1.0 | |
| 12 | - */ | |
| 13 | -@AllArgsConstructor | |
| 14 | -@Getter | |
| 15 | -public enum AiChatModalDisableEnum { | |
| 16 | - | |
| 17 | - NO(0, "未禁用"), | |
| 18 | - YES(1, "禁用"), | |
| 19 | - | |
| 20 | - | |
| 21 | - ; | |
| 22 | - | |
| 23 | - private Integer value; | |
| 24 | - | |
| 25 | - private String name; | |
| 26 | -} |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiChatModalController.java
| ... | ... | @@ -2,19 +2,19 @@ package cn.iocoder.yudao.module.ai.controller.admin.model; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.ai.service.AiChatModalService; | |
| 6 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReq; | |
| 7 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReq; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 8 | +import cn.iocoder.yudao.module.ai.service.AiChatModalService; | |
| 9 | 9 | import io.swagger.v3.oas.annotations.Operation; |
| 10 | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | 11 | import lombok.AllArgsConstructor; |
| 12 | 12 | import lombok.extern.slf4j.Slf4j; |
| 13 | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | 14 | import org.springframework.web.bind.annotation.*; |
| 15 | -import org.springframework.web.multipart.MultipartFile; | |
| 16 | 15 | |
| 17 | 16 | // TODO @fan:调整下接口;相关 vo 的命名等等;modal => model |
| 17 | + | |
| 18 | 18 | /** |
| 19 | 19 | * ai 模型 |
| 20 | 20 | * |
| ... | ... | @@ -24,7 +24,7 @@ import org.springframework.web.multipart.MultipartFile; |
| 24 | 24 | */ |
| 25 | 25 | @Tag(name = "A6-AI模型") |
| 26 | 26 | @RestController |
| 27 | -@RequestMapping("/ai/chat") | |
| 27 | +@RequestMapping("/ai/chat/modal") | |
| 28 | 28 | @Slf4j |
| 29 | 29 | @AllArgsConstructor |
| 30 | 30 | public class AiChatModalController { |
| ... | ... | @@ -32,37 +32,29 @@ public class AiChatModalController { |
| 32 | 32 | private final AiChatModalService aiChatModalService; |
| 33 | 33 | |
| 34 | 34 | @Operation(summary = "ai模型 - 模型列表") |
| 35 | - @GetMapping("/modal/list") | |
| 36 | - public PageResult<AiChatModalListRes> list(@ModelAttribute AiChatModalListReq req) { | |
| 35 | + @GetMapping("/list") | |
| 36 | + public PageResult<AiChatModalListRes> list(@ModelAttribute AiChatModalListReqVO req) { | |
| 37 | 37 | return aiChatModalService.list(req); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | @Operation(summary = "ai模型 - 添加") |
| 41 | - @PutMapping("/modal") | |
| 42 | - public CommonResult<Void> add(@RequestBody @Validated AiChatModalAddReq req) { | |
| 41 | + @PutMapping("/add") | |
| 42 | + public CommonResult<Void> add(@RequestBody @Validated AiChatModalAddReqVO req) { | |
| 43 | 43 | aiChatModalService.add(req); |
| 44 | 44 | return CommonResult.success(null); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - @Operation(summary = "ai模型 - 模型照片上传") | |
| 48 | - @PostMapping("/modal/{id}/updateImage") | |
| 49 | - public CommonResult<Void> updateImage(@PathVariable("id") Long id, | |
| 50 | - MultipartFile file) { | |
| 51 | - // todo yunai 文件上传这里放哪里 | |
| 52 | - return CommonResult.success(null); | |
| 53 | - } | |
| 54 | - | |
| 55 | 47 | @Operation(summary = "ai模型 - 修改") |
| 56 | - @PostMapping("/modal/{id}") | |
| 57 | - public CommonResult<Void> update(@PathVariable Long id, | |
| 58 | - @RequestBody @Validated AiChatModalAddReq req) { | |
| 48 | + @PostMapping("/update") | |
| 49 | + public CommonResult<Void> update(@RequestParam("id") Long id, | |
| 50 | + @RequestBody @Validated AiChatModalAddReqVO req) { | |
| 59 | 51 | aiChatModalService.update(id, req); |
| 60 | 52 | return CommonResult.success(null); |
| 61 | 53 | } |
| 62 | 54 | |
| 63 | 55 | @Operation(summary = "ai模型 - 删除") |
| 64 | - @DeleteMapping("/modal/{id}") | |
| 65 | - public CommonResult<Void> delete(@PathVariable Long id) { | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + public CommonResult<Void> delete(@RequestParam("id") Long id) { | |
| 66 | 58 | aiChatModalService.delete(id); |
| 67 | 59 | return CommonResult.success(null); |
| 68 | 60 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalAddReq.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalAddReqVO.java
| ... | ... | @@ -6,8 +6,6 @@ import jakarta.validation.constraints.Size; |
| 6 | 6 | import lombok.Data; |
| 7 | 7 | import lombok.experimental.Accessors; |
| 8 | 8 | |
| 9 | -import java.util.Map; | |
| 10 | - | |
| 11 | 9 | /** |
| 12 | 10 | * ai chat modal |
| 13 | 11 | * |
| ... | ... | @@ -17,32 +15,40 @@ import java.util.Map; |
| 17 | 15 | */ |
| 18 | 16 | @Data |
| 19 | 17 | @Accessors(chain = true) |
| 20 | -public class AiChatModalAddReq { | |
| 18 | +public class AiChatModalAddReqVO { | |
| 19 | + | |
| 20 | + @Schema(description = "API 秘钥编号") | |
| 21 | + @Size(max = 32, message = "API 秘钥编号最大32个字符") | |
| 22 | + @NotNull(message = "API 秘钥编号不能为空!") | |
| 23 | + private Long keyId; | |
| 21 | 24 | |
| 22 | 25 | @Schema(description = "模型名字") |
| 23 | 26 | @Size(max = 60, message = "模型名字最大60个字符") |
| 24 | 27 | @NotNull(message = "模型名字不能为空!") |
| 25 | 28 | private String name; |
| 26 | 29 | |
| 30 | + @Schema(description = "模型类型(qianwen、yiyan、xinghuo、openai)") | |
| 31 | + @Size(max = 32, message = "模型类型最大32个字符") | |
| 32 | + @NotNull(message = "model模型不能为空!") | |
| 33 | + private String model; | |
| 34 | + | |
| 27 | 35 | @Size(max = 32, message = "模型平台最大32个字符") |
| 28 | 36 | @Schema(description = "模型平台 参考 AiPlatformEnum") |
| 29 | 37 | @NotNull(message = "平台不能为空!") |
| 30 | 38 | private String platform; |
| 31 | 39 | |
| 32 | - @Schema(description = "模型类型(qianwen、yiyan、xinghuo、openai)") | |
| 33 | - @Size(max = 32, message = "模型类型最大32个字符") | |
| 34 | - @NotNull(message = "modal模型不能为空!") | |
| 35 | - private String modal; | |
| 36 | - | |
| 37 | - @Schema(description = "模型照片") | |
| 38 | - @Size(max = 256, message = "模型照片地址最大256个字符") | |
| 39 | - private String imageUrl; | |
| 40 | - | |
| 41 | 40 | @Schema(description = "排序") |
| 42 | 41 | @NotNull(message = "sort排序不能为空!") |
| 43 | 42 | private Integer sort; |
| 44 | 43 | |
| 45 | - @Schema(description = "模型配置JSON") | |
| 46 | -// @Size(max = 1024, message = "模型配置最大1024个字符") | |
| 47 | - private Map<String, Object> config; | |
| 44 | + // ========== 会话配置 ========== | |
| 45 | + | |
| 46 | + @Schema(description = "温度参数") | |
| 47 | + private Integer temperature; | |
| 48 | + | |
| 49 | + @Schema(description = "单条回复的最大 Token 数量") | |
| 50 | + private Integer maxTokens; | |
| 51 | + | |
| 52 | + @Schema(description = "上下文的最大 Message 数量") | |
| 53 | + private Integer maxContexts; | |
| 48 | 54 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalListReq.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalListReqVO.java
| ... | ... | @@ -14,7 +14,7 @@ import lombok.experimental.Accessors; |
| 14 | 14 | */ |
| 15 | 15 | @Data |
| 16 | 16 | @Accessors(chain = true) |
| 17 | -public class AiChatModalListReq extends PageParam { | |
| 17 | +public class AiChatModalListReqVO extends PageParam { | |
| 18 | 18 | |
| 19 | 19 | @Schema(description = "名字搜搜") |
| 20 | 20 | private String search; | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalRes.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.controller.admin.model.vo.model; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.constraints.Size; | |
| 4 | 5 | import lombok.Data; |
| 5 | 6 | import lombok.experimental.Accessors; |
| 6 | 7 | |
| ... | ... | @@ -15,27 +16,35 @@ import lombok.experimental.Accessors; |
| 15 | 16 | @Accessors(chain = true) |
| 16 | 17 | public class AiChatModalRes { |
| 17 | 18 | |
| 18 | - @Schema(description = "id") | |
| 19 | + @Schema(description = "编号") | |
| 19 | 20 | private Long id; |
| 20 | 21 | |
| 21 | - @Schema(description = "模型平台 参考 AiPlatformEnum") | |
| 22 | - private String platform; | |
| 23 | - | |
| 24 | - @Schema(description = "模型类型 参考 YiYanChatModel、XingHuoChatModel") | |
| 25 | - private String modal; | |
| 22 | + @Schema(description = "API 秘钥编号") | |
| 23 | + private Long keyId; | |
| 26 | 24 | |
| 27 | 25 | @Schema(description = "模型名字") |
| 28 | 26 | private String name; |
| 29 | 27 | |
| 30 | - @Schema(description = "模型照片") | |
| 31 | - private String image; | |
| 28 | + @Schema(description = "模型类型(qianwen、yiyan、xinghuo、openai)") | |
| 29 | + private String model; | |
| 32 | 30 | |
| 33 | - @Schema(description = "禁用 0、正常 1、禁用") | |
| 34 | - private Integer disable; | |
| 31 | + @Size(max = 32, message = "模型平台最大32个字符") | |
| 32 | + private String platform; | |
| 35 | 33 | |
| 36 | - @Schema(description = "排序 asc 排序") | |
| 34 | + @Schema(description = "排序") | |
| 37 | 35 | private Integer sort; |
| 38 | 36 | |
| 39 | - @Schema(description = "modal 配置") | |
| 40 | - private String config; | |
| 37 | + @Schema(description = "状态") | |
| 38 | + private Integer status; | |
| 39 | + | |
| 40 | + // ========== 会话配置 ========== | |
| 41 | + | |
| 42 | + @Schema(description = "温度参数") | |
| 43 | + private Integer temperature; | |
| 44 | + | |
| 45 | + @Schema(description = "单条回复的最大 Token 数量") | |
| 46 | + private Integer maxTokens; | |
| 47 | + | |
| 48 | + @Schema(description = "上下文的最大 Message 数量") | |
| 49 | + private Integer maxContexts; | |
| 41 | 50 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/model/AiChatModalUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.model.vo.model; | |
| 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 | + * ai chat modal | |
| 11 | + * | |
| 12 | + * @author fansili | |
| 13 | + * @time 2024/4/24 19:47 | |
| 14 | + * @since 1.0 | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +@Accessors(chain = true) | |
| 18 | +public class AiChatModalUpdateReqVO { | |
| 19 | + | |
| 20 | + @Schema(description = "编号") | |
| 21 | + @Size(max = 32, message = "编号最大32个字符") | |
| 22 | + @NotNull(message = "编号不能为空") | |
| 23 | + private Long id; | |
| 24 | + | |
| 25 | + @Schema(description = "API 秘钥编号") | |
| 26 | + @Size(max = 32, message = "API 秘钥编号最大32个字符") | |
| 27 | + @NotNull(message = "API 秘钥编号不能为空!") | |
| 28 | + private Long keyId; | |
| 29 | + | |
| 30 | + @Schema(description = "模型名字") | |
| 31 | + @Size(max = 60, message = "模型名字最大60个字符") | |
| 32 | + @NotNull(message = "模型名字不能为空!") | |
| 33 | + private String name; | |
| 34 | + | |
| 35 | + @Schema(description = "模型类型(qianwen、yiyan、xinghuo、openai)") | |
| 36 | + @Size(max = 32, message = "模型类型最大32个字符") | |
| 37 | + @NotNull(message = "model模型不能为空!") | |
| 38 | + private String model; | |
| 39 | + | |
| 40 | + @Size(max = 32, message = "模型平台最大32个字符") | |
| 41 | + @Schema(description = "模型平台 参考 AiPlatformEnum") | |
| 42 | + @NotNull(message = "平台不能为空!") | |
| 43 | + private String platform; | |
| 44 | + | |
| 45 | + @Schema(description = "排序") | |
| 46 | + @NotNull(message = "sort排序不能为空!") | |
| 47 | + private Integer sort; | |
| 48 | + | |
| 49 | + @Schema(description = "状态") | |
| 50 | + @NotNull(message = "状态不能为空!") | |
| 51 | + private Integer status; | |
| 52 | + | |
| 53 | + // ========== 会话配置 ========== | |
| 54 | + | |
| 55 | + @Schema(description = "温度参数") | |
| 56 | + private Integer temperature; | |
| 57 | + | |
| 58 | + @Schema(description = "单条回复的最大 Token 数量") | |
| 59 | + private Integer maxTokens; | |
| 60 | + | |
| 61 | + @Schema(description = "上下文的最大 Message 数量") | |
| 62 | + private Integer maxContexts; | |
| 63 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatModalConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.convert; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModalDO; | |
| 4 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReq; | |
| 3 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReqVO; | |
| 5 | 4 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 6 | 5 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; |
| 6 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModalDO; | |
| 7 | 7 | import org.mapstruct.Mapper; |
| 8 | -import org.mapstruct.Mapping; | |
| 9 | -import org.mapstruct.Mappings; | |
| 10 | 8 | import org.mapstruct.factory.Mappers; |
| 11 | 9 | |
| 12 | 10 | import java.util.List; |
| ... | ... | @@ -37,10 +35,7 @@ public interface AiChatModalConvert { |
| 37 | 35 | * @param req |
| 38 | 36 | * @return |
| 39 | 37 | */ |
| 40 | - @Mappings({ | |
| 41 | - @Mapping(target = "config", ignore = true) | |
| 42 | - }) | |
| 43 | - AiChatModalDO convertAiChatModalDO(AiChatModalAddReq req); | |
| 38 | + AiChatModalDO convertAiChatModalDO(AiChatModalAddReqVO req); | |
| 44 | 39 | |
| 45 | 40 | |
| 46 | 41 | /** | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatModalService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReq; | |
| 5 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReq; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReqVO; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReqVO; | |
| 6 | 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 7 | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; |
| 8 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModalDO; | |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * ai modal |
| ... | ... | @@ -21,14 +22,14 @@ public interface AiChatModalService { |
| 21 | 22 | * @param req |
| 22 | 23 | * @return |
| 23 | 24 | */ |
| 24 | - PageResult<AiChatModalListRes> list(AiChatModalListReq req); | |
| 25 | + PageResult<AiChatModalListRes> list(AiChatModalListReqVO req); | |
| 25 | 26 | |
| 26 | 27 | /** |
| 27 | 28 | * ai modal - 添加 |
| 28 | 29 | * |
| 29 | 30 | * @param req |
| 30 | 31 | */ |
| 31 | - void add(AiChatModalAddReq req); | |
| 32 | + void add(AiChatModalAddReqVO req); | |
| 32 | 33 | |
| 33 | 34 | /** |
| 34 | 35 | * ai modal - 更新 |
| ... | ... | @@ -36,7 +37,7 @@ public interface AiChatModalService { |
| 36 | 37 | * @param id |
| 37 | 38 | * @param req |
| 38 | 39 | */ |
| 39 | - void update(Long id, AiChatModalAddReq req); | |
| 40 | + void update(Long id, AiChatModalAddReqVO req); | |
| 40 | 41 | |
| 41 | 42 | /** |
| 42 | 43 | * ai modal - 删除 |
| ... | ... | @@ -54,6 +55,14 @@ public interface AiChatModalService { |
| 54 | 55 | AiChatModalRes getChatModalOfValidate(Long modalId); |
| 55 | 56 | |
| 56 | 57 | /** |
| 58 | + * 校验 - 是否存在 | |
| 59 | + * | |
| 60 | + * @param id | |
| 61 | + * @return | |
| 62 | + */ | |
| 63 | + AiChatModalDO validateExists(Long id); | |
| 64 | + | |
| 65 | + /** | |
| 57 | 66 | * 校验 - 校验是否可用 |
| 58 | 67 | * |
| 59 | 68 | * @param chatModal | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatModalServiceImpl.java
| ... | ... | @@ -3,26 +3,20 @@ package cn.iocoder.yudao.module.ai.service.impl; |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.hutool.extra.validation.ValidationUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.ai.AiPlatformEnum; |
| 6 | -import cn.iocoder.yudao.framework.ai.chatqianwen.QianWenChatModal; | |
| 7 | -import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; | |
| 8 | -import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatModel; | |
| 6 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 9 | 7 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 10 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 11 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 12 | 9 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 13 | 10 | import cn.iocoder.yudao.module.ai.ErrorCodeConstants; |
| 11 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReqVO; | |
| 12 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReqVO; | |
| 13 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; | |
| 14 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; | |
| 14 | 15 | import cn.iocoder.yudao.module.ai.convert.AiChatModalConvert; |
| 15 | 16 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModalDO; |
| 16 | -import cn.iocoder.yudao.module.ai.dal.vo.AiChatModalChatConfigVO; | |
| 17 | -import cn.iocoder.yudao.module.ai.dal.vo.AiChatModalConfigVO; | |
| 18 | -import cn.iocoder.yudao.module.ai.dal.vo.AiChatModalDallConfigVO; | |
| 19 | -import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum; | |
| 20 | 17 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatModalMapper; |
| 18 | +import cn.iocoder.yudao.module.ai.dal.vo.AiChatModalConfigVO; | |
| 21 | 19 | import cn.iocoder.yudao.module.ai.service.AiChatModalService; |
| 22 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalAddReq; | |
| 23 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListReq; | |
| 24 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; | |
| 25 | -import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; | |
| 26 | 20 | import jakarta.validation.ConstraintViolation; |
| 27 | 21 | import lombok.AllArgsConstructor; |
| 28 | 22 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -46,10 +40,10 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 46 | 40 | private final AiChatModalMapper aiChatModalMapper; |
| 47 | 41 | |
| 48 | 42 | @Override |
| 49 | - public PageResult<AiChatModalListRes> list(AiChatModalListReq req) { | |
| 43 | + public PageResult<AiChatModalListRes> list(AiChatModalListReqVO req) { | |
| 50 | 44 | LambdaQueryWrapperX<AiChatModalDO> queryWrapperX = new LambdaQueryWrapperX<>(); |
| 51 | 45 | // 查询的都是未禁用的模型 |
| 52 | - queryWrapperX.eq(AiChatModalDO::getDisable, AiChatModalDisableEnum.NO.getValue()); | |
| 46 | + queryWrapperX.eq(AiChatModalDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); | |
| 53 | 47 | // search |
| 54 | 48 | if (!StrUtil.isBlank(req.getSearch())) { |
| 55 | 49 | queryWrapperX.like(AiChatModalDO::getName, req.getSearch().trim()); |
| ... | ... | @@ -64,39 +58,26 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 64 | 58 | } |
| 65 | 59 | |
| 66 | 60 | @Override |
| 67 | - public void add(AiChatModalAddReq req) { | |
| 61 | + public void add(AiChatModalAddReqVO req) { | |
| 68 | 62 | // 校验 platform、type |
| 69 | 63 | validatePlatform(req.getPlatform()); |
| 70 | - validateModal(req.getPlatform(), req.getModal()); | |
| 71 | - // 转换config | |
| 72 | - AiChatModalConfigVO aiChatModalConfigVO = convertConfig(req); | |
| 73 | - // 校验 modal config | |
| 74 | - validateModalConfig(aiChatModalConfigVO); | |
| 75 | 64 | // 转换 do |
| 76 | 65 | AiChatModalDO insertChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req); |
| 77 | 66 | // 设置默认属性 |
| 78 | - insertChatModalDO.setDisable(AiChatModalDisableEnum.NO.getValue()); | |
| 79 | - insertChatModalDO.setConfig(JsonUtils.toJsonString(aiChatModalConfigVO)); | |
| 67 | + insertChatModalDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 80 | 68 | // 保存数据库 |
| 81 | 69 | aiChatModalMapper.insert(insertChatModalDO); |
| 82 | 70 | } |
| 83 | 71 | |
| 84 | 72 | @Override |
| 85 | - public void update(Long id, AiChatModalAddReq req) { | |
| 86 | - // 校验 platform、type | |
| 73 | + public void update(Long id, AiChatModalAddReqVO req) { | |
| 74 | + // 校验 platform | |
| 87 | 75 | validatePlatform(req.getPlatform()); |
| 88 | - validateModal(req.getPlatform(), req.getModal()); | |
| 89 | - // 转换config | |
| 90 | - AiChatModalConfigVO aiChatModalConfigVO = convertConfig(req); | |
| 91 | - // 校验 modal config | |
| 92 | - validateModalConfig(aiChatModalConfigVO); | |
| 93 | - | |
| 94 | 76 | // 校验模型是否存在 |
| 95 | - validateChatModalExists(id); | |
| 77 | + validateExists(id); | |
| 96 | 78 | // 转换 updateChatModalDO |
| 97 | 79 | AiChatModalDO updateChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req); |
| 98 | 80 | updateChatModalDO.setId(id); |
| 99 | - updateChatModalDO.setConfig(JsonUtils.toJsonString(aiChatModalConfigVO)); | |
| 100 | 81 | // 更新数据库 |
| 101 | 82 | aiChatModalMapper.updateById(updateChatModalDO); |
| 102 | 83 | } |
| ... | ... | @@ -104,7 +85,7 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 104 | 85 | @Override |
| 105 | 86 | public void delete(Long id) { |
| 106 | 87 | // 检查 modal 是否存在 |
| 107 | - validateChatModalExists(id); | |
| 88 | + validateExists(id); | |
| 108 | 89 | // 删除 delete |
| 109 | 90 | aiChatModalMapper.deleteById(id); |
| 110 | 91 | } |
| ... | ... | @@ -112,19 +93,19 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 112 | 93 | @Override |
| 113 | 94 | public AiChatModalRes getChatModalOfValidate(Long modalId) { |
| 114 | 95 | // 检查 modal 是否存在 |
| 115 | - AiChatModalDO aiChatModalDO = validateChatModalExists(modalId); | |
| 96 | + AiChatModalDO aiChatModalDO = validateExists(modalId); | |
| 116 | 97 | return AiChatModalConvert.INSTANCE.convertAiChatModalRes(aiChatModalDO); |
| 117 | 98 | } |
| 118 | 99 | |
| 119 | 100 | @Override |
| 120 | 101 | public void validateAvailable(AiChatModalRes chatModal) { |
| 121 | 102 | // 对话模型是否可用 |
| 122 | - if (AiChatModalDisableEnum.YES.getValue().equals(chatModal.getDisable())) { | |
| 103 | + if (CommonStatusEnum.ENABLE.getStatus().equals(chatModal.getStatus())) { | |
| 123 | 104 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_DISABLE_NOT_USED); |
| 124 | 105 | } |
| 125 | 106 | } |
| 126 | 107 | |
| 127 | - private AiChatModalDO validateChatModalExists(Long id) { | |
| 108 | + public AiChatModalDO validateExists(Long id) { | |
| 128 | 109 | AiChatModalDO aiChatModalDO = aiChatModalMapper.selectById(id); |
| 129 | 110 | if (aiChatModalDO == null) { |
| 130 | 111 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_EXIST); |
| ... | ... | @@ -132,23 +113,6 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 132 | 113 | return aiChatModalDO; |
| 133 | 114 | } |
| 134 | 115 | |
| 135 | - private void validateModal(String platform, String modal) { | |
| 136 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(platform); | |
| 137 | - try { | |
| 138 | - if (AiPlatformEnum.QIAN_WEN == platformEnum) { | |
| 139 | - QianWenChatModal.valueOfModel(modal); | |
| 140 | - } else if (AiPlatformEnum.XING_HUO == platformEnum) { | |
| 141 | - XingHuoChatModel.valueOfModel(modal); | |
| 142 | - } else if (AiPlatformEnum.YI_YAN == platformEnum) { | |
| 143 | - YiYanChatModel.valueOfModel(modal); | |
| 144 | - } else { | |
| 145 | - throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_SUPPORTED_MODAL, platform); | |
| 146 | - } | |
| 147 | - } catch (IllegalArgumentException e) { | |
| 148 | - throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_CONFIG_PARAMS_INCORRECT, e.getMessage()); | |
| 149 | - } | |
| 150 | - } | |
| 151 | - | |
| 152 | 116 | private void validatePlatform(String platform) { |
| 153 | 117 | try { |
| 154 | 118 | AiPlatformEnum.valueOfPlatform(platform); |
| ... | ... | @@ -163,20 +127,4 @@ public class AiChatModalServiceImpl implements AiChatModalService { |
| 163 | 127 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_CONFIG_PARAMS_INCORRECT, constraintViolation.getMessage()); |
| 164 | 128 | } |
| 165 | 129 | } |
| 166 | - | |
| 167 | - private static AiChatModalConfigVO convertConfig(AiChatModalAddReq req) { | |
| 168 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(req.getPlatform()); | |
| 169 | - AiChatModalConfigVO resVo = null; | |
| 170 | - if (AiPlatformEnum.CHAT_PLATFORM_LIST.contains(platformEnum)) { | |
| 171 | - resVo = JsonUtils.parseObject(JsonUtils.toJsonString(req.getConfig()), AiChatModalChatConfigVO.class); | |
| 172 | - } else if (AiPlatformEnum.OPEN_AI_DALL == platformEnum) { | |
| 173 | - resVo = JsonUtils.parseObject(JsonUtils.toJsonString(req.getConfig()), AiChatModalDallConfigVO.class); | |
| 174 | - } | |
| 175 | - if (resVo == null) { | |
| 176 | - throw new IllegalArgumentException("ai模型中config不能转换! json: " + req.getConfig()); | |
| 177 | - } | |
| 178 | - resVo.setType(req.getModal()); | |
| 179 | - resVo.setPlatform(req.getPlatform()); | |
| 180 | - return resVo; | |
| 181 | - } | |
| 182 | 130 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java
| ... | ... | @@ -72,10 +72,10 @@ public class AiChatServiceImpl implements AiChatService { |
| 72 | 72 | // 校验角色是否公开 |
| 73 | 73 | aiChatRoleService.validateIsPublic(aiChatRoleDO); |
| 74 | 74 | // 获取 client 类型 |
| 75 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModal()); | |
| 75 | + AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModel()); | |
| 76 | 76 | // 保存 chat message |
| 77 | 77 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), |
| 78 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | |
| 78 | + chatModal.getModel(), chatModal.getId(), req.getContent(), | |
| 79 | 79 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 80 | 80 | String content = null; |
| 81 | 81 | try { |
| ... | ... | @@ -96,7 +96,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 96 | 96 | } finally { |
| 97 | 97 | // 保存 chat message |
| 98 | 98 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), |
| 99 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | |
| 99 | + chatModal.getModel(), chatModal.getId(), req.getContent(), | |
| 100 | 100 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 101 | 101 | } |
| 102 | 102 | return new AiChatMessageRespVO().setContent(content); |
| ... | ... | @@ -150,11 +150,11 @@ public class AiChatServiceImpl implements AiChatService { |
| 150 | 150 | // 保存 chat message |
| 151 | 151 | // 保存 chat message |
| 152 | 152 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), |
| 153 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | |
| 153 | + chatModal.getModel(), chatModal.getId(), req.getContent(), | |
| 154 | 154 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 155 | 155 | |
| 156 | 156 | // 获取 client 类型 |
| 157 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModal()); | |
| 157 | + AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModel()); | |
| 158 | 158 | StreamingChatClient streamingChatClient = aiChatClientFactory.getStreamingChatClient(platformEnum); |
| 159 | 159 | Flux<ChatResponse> streamResponse = streamingChatClient.stream(prompt); |
| 160 | 160 | |
| ... | ... | @@ -183,7 +183,7 @@ public class AiChatServiceImpl implements AiChatService { |
| 183 | 183 | sseEmitter.complete(); |
| 184 | 184 | // 保存 chat message |
| 185 | 185 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), |
| 186 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | |
| 186 | + chatModal.getModel(), chatModal.getId(), req.getContent(), | |
| 187 | 187 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 188 | 188 | |
| 189 | 189 | } | ... | ... |