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,19 +2,19 @@ package cn.iocoder.yudao.module.ai.controller.admin.model; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 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 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; | 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 8 | +import cn.iocoder.yudao.module.ai.service.AiChatModalService; | ||
| 9 | import io.swagger.v3.oas.annotations.Operation; | 9 | import io.swagger.v3.oas.annotations.Operation; |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 11 | import lombok.AllArgsConstructor; | 11 | import lombok.AllArgsConstructor; |
| 12 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| 13 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | import org.springframework.web.bind.annotation.*; | 14 | import org.springframework.web.bind.annotation.*; |
| 15 | -import org.springframework.web.multipart.MultipartFile; | ||
| 16 | 15 | ||
| 17 | // TODO @fan:调整下接口;相关 vo 的命名等等;modal => model | 16 | // TODO @fan:调整下接口;相关 vo 的命名等等;modal => model |
| 17 | + | ||
| 18 | /** | 18 | /** |
| 19 | * ai 模型 | 19 | * ai 模型 |
| 20 | * | 20 | * |
| @@ -24,7 +24,7 @@ import org.springframework.web.multipart.MultipartFile; | @@ -24,7 +24,7 @@ import org.springframework.web.multipart.MultipartFile; | ||
| 24 | */ | 24 | */ |
| 25 | @Tag(name = "A6-AI模型") | 25 | @Tag(name = "A6-AI模型") |
| 26 | @RestController | 26 | @RestController |
| 27 | -@RequestMapping("/ai/chat") | 27 | +@RequestMapping("/ai/chat/modal") |
| 28 | @Slf4j | 28 | @Slf4j |
| 29 | @AllArgsConstructor | 29 | @AllArgsConstructor |
| 30 | public class AiChatModalController { | 30 | public class AiChatModalController { |
| @@ -32,37 +32,29 @@ public class AiChatModalController { | @@ -32,37 +32,29 @@ public class AiChatModalController { | ||
| 32 | private final AiChatModalService aiChatModalService; | 32 | private final AiChatModalService aiChatModalService; |
| 33 | 33 | ||
| 34 | @Operation(summary = "ai模型 - 模型列表") | 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 | return aiChatModalService.list(req); | 37 | return aiChatModalService.list(req); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | @Operation(summary = "ai模型 - 添加") | 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 | aiChatModalService.add(req); | 43 | aiChatModalService.add(req); |
| 44 | return CommonResult.success(null); | 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 | @Operation(summary = "ai模型 - 修改") | 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 | aiChatModalService.update(id, req); | 51 | aiChatModalService.update(id, req); |
| 60 | return CommonResult.success(null); | 52 | return CommonResult.success(null); |
| 61 | } | 53 | } |
| 62 | 54 | ||
| 63 | @Operation(summary = "ai模型 - 删除") | 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 | aiChatModalService.delete(id); | 58 | aiChatModalService.delete(id); |
| 67 | return CommonResult.success(null); | 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,8 +6,6 @@ import jakarta.validation.constraints.Size; | ||
| 6 | import lombok.Data; | 6 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 8 | 8 | ||
| 9 | -import java.util.Map; | ||
| 10 | - | ||
| 11 | /** | 9 | /** |
| 12 | * ai chat modal | 10 | * ai chat modal |
| 13 | * | 11 | * |
| @@ -17,32 +15,40 @@ import java.util.Map; | @@ -17,32 +15,40 @@ import java.util.Map; | ||
| 17 | */ | 15 | */ |
| 18 | @Data | 16 | @Data |
| 19 | @Accessors(chain = true) | 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 | @Schema(description = "模型名字") | 25 | @Schema(description = "模型名字") |
| 23 | @Size(max = 60, message = "模型名字最大60个字符") | 26 | @Size(max = 60, message = "模型名字最大60个字符") |
| 24 | @NotNull(message = "模型名字不能为空!") | 27 | @NotNull(message = "模型名字不能为空!") |
| 25 | private String name; | 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 | @Size(max = 32, message = "模型平台最大32个字符") | 35 | @Size(max = 32, message = "模型平台最大32个字符") |
| 28 | @Schema(description = "模型平台 参考 AiPlatformEnum") | 36 | @Schema(description = "模型平台 参考 AiPlatformEnum") |
| 29 | @NotNull(message = "平台不能为空!") | 37 | @NotNull(message = "平台不能为空!") |
| 30 | private String platform; | 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 | @Schema(description = "排序") | 40 | @Schema(description = "排序") |
| 42 | @NotNull(message = "sort排序不能为空!") | 41 | @NotNull(message = "sort排序不能为空!") |
| 43 | private Integer sort; | 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,7 +14,7 @@ import lombok.experimental.Accessors; | ||
| 14 | */ | 14 | */ |
| 15 | @Data | 15 | @Data |
| 16 | @Accessors(chain = true) | 16 | @Accessors(chain = true) |
| 17 | -public class AiChatModalListReq extends PageParam { | 17 | +public class AiChatModalListReqVO extends PageParam { |
| 18 | 18 | ||
| 19 | @Schema(description = "名字搜搜") | 19 | @Schema(description = "名字搜搜") |
| 20 | private String search; | 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 | package cn.iocoder.yudao.module.ai.controller.admin.model.vo.model; | 1 | package cn.iocoder.yudao.module.ai.controller.admin.model.vo.model; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | +import jakarta.validation.constraints.Size; | ||
| 4 | import lombok.Data; | 5 | import lombok.Data; |
| 5 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
| 6 | 7 | ||
| @@ -15,27 +16,35 @@ import lombok.experimental.Accessors; | @@ -15,27 +16,35 @@ import lombok.experimental.Accessors; | ||
| 15 | @Accessors(chain = true) | 16 | @Accessors(chain = true) |
| 16 | public class AiChatModalRes { | 17 | public class AiChatModalRes { |
| 17 | 18 | ||
| 18 | - @Schema(description = "id") | 19 | + @Schema(description = "编号") |
| 19 | private Long id; | 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 | @Schema(description = "模型名字") | 25 | @Schema(description = "模型名字") |
| 28 | private String name; | 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 | private Integer sort; | 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 | 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.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 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; | 4 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; | 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 | import org.mapstruct.Mapper; | 7 | import org.mapstruct.Mapper; |
| 8 | -import org.mapstruct.Mapping; | ||
| 9 | -import org.mapstruct.Mappings; | ||
| 10 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 11 | 9 | ||
| 12 | import java.util.List; | 10 | import java.util.List; |
| @@ -37,10 +35,7 @@ public interface AiChatModalConvert { | @@ -37,10 +35,7 @@ public interface AiChatModalConvert { | ||
| 37 | * @param req | 35 | * @param req |
| 38 | * @return | 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 | 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.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 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalListRes; |
| 7 | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; | 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 | * ai modal | 11 | * ai modal |
| @@ -21,14 +22,14 @@ public interface AiChatModalService { | @@ -21,14 +22,14 @@ public interface AiChatModalService { | ||
| 21 | * @param req | 22 | * @param req |
| 22 | * @return | 23 | * @return |
| 23 | */ | 24 | */ |
| 24 | - PageResult<AiChatModalListRes> list(AiChatModalListReq req); | 25 | + PageResult<AiChatModalListRes> list(AiChatModalListReqVO req); |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * ai modal - 添加 | 28 | * ai modal - 添加 |
| 28 | * | 29 | * |
| 29 | * @param req | 30 | * @param req |
| 30 | */ | 31 | */ |
| 31 | - void add(AiChatModalAddReq req); | 32 | + void add(AiChatModalAddReqVO req); |
| 32 | 33 | ||
| 33 | /** | 34 | /** |
| 34 | * ai modal - 更新 | 35 | * ai modal - 更新 |
| @@ -36,7 +37,7 @@ public interface AiChatModalService { | @@ -36,7 +37,7 @@ public interface AiChatModalService { | ||
| 36 | * @param id | 37 | * @param id |
| 37 | * @param req | 38 | * @param req |
| 38 | */ | 39 | */ |
| 39 | - void update(Long id, AiChatModalAddReq req); | 40 | + void update(Long id, AiChatModalAddReqVO req); |
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * ai modal - 删除 | 43 | * ai modal - 删除 |
| @@ -54,6 +55,14 @@ public interface AiChatModalService { | @@ -54,6 +55,14 @@ public interface AiChatModalService { | ||
| 54 | AiChatModalRes getChatModalOfValidate(Long modalId); | 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 | * @param chatModal | 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,26 +3,20 @@ package cn.iocoder.yudao.module.ai.service.impl; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.hutool.extra.validation.ValidationUtil; | 4 | import cn.hutool.extra.validation.ValidationUtil; |
| 5 | import cn.iocoder.yudao.framework.ai.AiPlatformEnum; | 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 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 7 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 10 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 11 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 12 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 9 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 13 | import cn.iocoder.yudao.module.ai.ErrorCodeConstants; | 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 | import cn.iocoder.yudao.module.ai.convert.AiChatModalConvert; | 15 | import cn.iocoder.yudao.module.ai.convert.AiChatModalConvert; |
| 15 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModalDO; | 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 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatModalMapper; | 17 | import cn.iocoder.yudao.module.ai.dal.mysql.AiChatModalMapper; |
| 18 | +import cn.iocoder.yudao.module.ai.dal.vo.AiChatModalConfigVO; | ||
| 21 | import cn.iocoder.yudao.module.ai.service.AiChatModalService; | 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 | import jakarta.validation.ConstraintViolation; | 20 | import jakarta.validation.ConstraintViolation; |
| 27 | import lombok.AllArgsConstructor; | 21 | import lombok.AllArgsConstructor; |
| 28 | import lombok.extern.slf4j.Slf4j; | 22 | import lombok.extern.slf4j.Slf4j; |
| @@ -46,10 +40,10 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -46,10 +40,10 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 46 | private final AiChatModalMapper aiChatModalMapper; | 40 | private final AiChatModalMapper aiChatModalMapper; |
| 47 | 41 | ||
| 48 | @Override | 42 | @Override |
| 49 | - public PageResult<AiChatModalListRes> list(AiChatModalListReq req) { | 43 | + public PageResult<AiChatModalListRes> list(AiChatModalListReqVO req) { |
| 50 | LambdaQueryWrapperX<AiChatModalDO> queryWrapperX = new LambdaQueryWrapperX<>(); | 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 | // search | 47 | // search |
| 54 | if (!StrUtil.isBlank(req.getSearch())) { | 48 | if (!StrUtil.isBlank(req.getSearch())) { |
| 55 | queryWrapperX.like(AiChatModalDO::getName, req.getSearch().trim()); | 49 | queryWrapperX.like(AiChatModalDO::getName, req.getSearch().trim()); |
| @@ -64,39 +58,26 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -64,39 +58,26 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 64 | } | 58 | } |
| 65 | 59 | ||
| 66 | @Override | 60 | @Override |
| 67 | - public void add(AiChatModalAddReq req) { | 61 | + public void add(AiChatModalAddReqVO req) { |
| 68 | // 校验 platform、type | 62 | // 校验 platform、type |
| 69 | validatePlatform(req.getPlatform()); | 63 | validatePlatform(req.getPlatform()); |
| 70 | - validateModal(req.getPlatform(), req.getModal()); | ||
| 71 | - // 转换config | ||
| 72 | - AiChatModalConfigVO aiChatModalConfigVO = convertConfig(req); | ||
| 73 | - // 校验 modal config | ||
| 74 | - validateModalConfig(aiChatModalConfigVO); | ||
| 75 | // 转换 do | 64 | // 转换 do |
| 76 | AiChatModalDO insertChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req); | 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 | aiChatModalMapper.insert(insertChatModalDO); | 69 | aiChatModalMapper.insert(insertChatModalDO); |
| 82 | } | 70 | } |
| 83 | 71 | ||
| 84 | @Override | 72 | @Override |
| 85 | - public void update(Long id, AiChatModalAddReq req) { | ||
| 86 | - // 校验 platform、type | 73 | + public void update(Long id, AiChatModalAddReqVO req) { |
| 74 | + // 校验 platform | ||
| 87 | validatePlatform(req.getPlatform()); | 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 | // 转换 updateChatModalDO | 78 | // 转换 updateChatModalDO |
| 97 | AiChatModalDO updateChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req); | 79 | AiChatModalDO updateChatModalDO = AiChatModalConvert.INSTANCE.convertAiChatModalDO(req); |
| 98 | updateChatModalDO.setId(id); | 80 | updateChatModalDO.setId(id); |
| 99 | - updateChatModalDO.setConfig(JsonUtils.toJsonString(aiChatModalConfigVO)); | ||
| 100 | // 更新数据库 | 81 | // 更新数据库 |
| 101 | aiChatModalMapper.updateById(updateChatModalDO); | 82 | aiChatModalMapper.updateById(updateChatModalDO); |
| 102 | } | 83 | } |
| @@ -104,7 +85,7 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -104,7 +85,7 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 104 | @Override | 85 | @Override |
| 105 | public void delete(Long id) { | 86 | public void delete(Long id) { |
| 106 | // 检查 modal 是否存在 | 87 | // 检查 modal 是否存在 |
| 107 | - validateChatModalExists(id); | 88 | + validateExists(id); |
| 108 | // 删除 delete | 89 | // 删除 delete |
| 109 | aiChatModalMapper.deleteById(id); | 90 | aiChatModalMapper.deleteById(id); |
| 110 | } | 91 | } |
| @@ -112,19 +93,19 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -112,19 +93,19 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 112 | @Override | 93 | @Override |
| 113 | public AiChatModalRes getChatModalOfValidate(Long modalId) { | 94 | public AiChatModalRes getChatModalOfValidate(Long modalId) { |
| 114 | // 检查 modal 是否存在 | 95 | // 检查 modal 是否存在 |
| 115 | - AiChatModalDO aiChatModalDO = validateChatModalExists(modalId); | 96 | + AiChatModalDO aiChatModalDO = validateExists(modalId); |
| 116 | return AiChatModalConvert.INSTANCE.convertAiChatModalRes(aiChatModalDO); | 97 | return AiChatModalConvert.INSTANCE.convertAiChatModalRes(aiChatModalDO); |
| 117 | } | 98 | } |
| 118 | 99 | ||
| 119 | @Override | 100 | @Override |
| 120 | public void validateAvailable(AiChatModalRes chatModal) { | 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 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_DISABLE_NOT_USED); | 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 | AiChatModalDO aiChatModalDO = aiChatModalMapper.selectById(id); | 109 | AiChatModalDO aiChatModalDO = aiChatModalMapper.selectById(id); |
| 129 | if (aiChatModalDO == null) { | 110 | if (aiChatModalDO == null) { |
| 130 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_EXIST); | 111 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_EXIST); |
| @@ -132,23 +113,6 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -132,23 +113,6 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 132 | return aiChatModalDO; | 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 | private void validatePlatform(String platform) { | 116 | private void validatePlatform(String platform) { |
| 153 | try { | 117 | try { |
| 154 | AiPlatformEnum.valueOfPlatform(platform); | 118 | AiPlatformEnum.valueOfPlatform(platform); |
| @@ -163,20 +127,4 @@ public class AiChatModalServiceImpl implements AiChatModalService { | @@ -163,20 +127,4 @@ public class AiChatModalServiceImpl implements AiChatModalService { | ||
| 163 | throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_CONFIG_PARAMS_INCORRECT, constraintViolation.getMessage()); | 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,10 +72,10 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 72 | // 校验角色是否公开 | 72 | // 校验角色是否公开 |
| 73 | aiChatRoleService.validateIsPublic(aiChatRoleDO); | 73 | aiChatRoleService.validateIsPublic(aiChatRoleDO); |
| 74 | // 获取 client 类型 | 74 | // 获取 client 类型 |
| 75 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModal()); | 75 | + AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModel()); |
| 76 | // 保存 chat message | 76 | // 保存 chat message |
| 77 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), | 77 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), |
| 78 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | 78 | + chatModal.getModel(), chatModal.getId(), req.getContent(), |
| 79 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); | 79 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 80 | String content = null; | 80 | String content = null; |
| 81 | try { | 81 | try { |
| @@ -96,7 +96,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -96,7 +96,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 96 | } finally { | 96 | } finally { |
| 97 | // 保存 chat message | 97 | // 保存 chat message |
| 98 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), | 98 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), |
| 99 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | 99 | + chatModal.getModel(), chatModal.getId(), req.getContent(), |
| 100 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); | 100 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 101 | } | 101 | } |
| 102 | return new AiChatMessageRespVO().setContent(content); | 102 | return new AiChatMessageRespVO().setContent(content); |
| @@ -150,11 +150,11 @@ public class AiChatServiceImpl implements AiChatService { | @@ -150,11 +150,11 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 150 | // 保存 chat message | 150 | // 保存 chat message |
| 151 | // 保存 chat message | 151 | // 保存 chat message |
| 152 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), | 152 | insertChatMessage(conversation.getId(), MessageType.USER, loginUserId, conversation.getRoleId(), |
| 153 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | 153 | + chatModal.getModel(), chatModal.getId(), req.getContent(), |
| 154 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); | 154 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 155 | 155 | ||
| 156 | // 获取 client 类型 | 156 | // 获取 client 类型 |
| 157 | - AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModal()); | 157 | + AiPlatformEnum platformEnum = AiPlatformEnum.valueOfPlatform(chatModal.getModel()); |
| 158 | StreamingChatClient streamingChatClient = aiChatClientFactory.getStreamingChatClient(platformEnum); | 158 | StreamingChatClient streamingChatClient = aiChatClientFactory.getStreamingChatClient(platformEnum); |
| 159 | Flux<ChatResponse> streamResponse = streamingChatClient.stream(prompt); | 159 | Flux<ChatResponse> streamResponse = streamingChatClient.stream(prompt); |
| 160 | 160 | ||
| @@ -183,7 +183,7 @@ public class AiChatServiceImpl implements AiChatService { | @@ -183,7 +183,7 @@ public class AiChatServiceImpl implements AiChatService { | ||
| 183 | sseEmitter.complete(); | 183 | sseEmitter.complete(); |
| 184 | // 保存 chat message | 184 | // 保存 chat message |
| 185 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), | 185 | insertChatMessage(conversation.getId(), MessageType.SYSTEM, loginUserId, conversation.getRoleId(), |
| 186 | - chatModal.getModal(), chatModal.getId(), req.getContent(), | 186 | + chatModal.getModel(), chatModal.getId(), req.getContent(), |
| 187 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); | 187 | null, conversation.getTemperature(), conversation.getMaxTokens(), conversation.getMaxContexts()); |
| 188 | 188 | ||
| 189 | } | 189 | } |