Commit f78d13a83ce1fa4481b3fb0140b84ea4f5151bc6

Authored by YunaiV
1 parent 3e164121

【代码优化】AI:完善各种注释

Showing 17 changed files with 52 additions and 96 deletions
yudao-dependencies/pom.xml
... ... @@ -75,7 +75,6 @@
75 75 <jimureport.version>1.6.6-beta2</jimureport.version>
76 76 <xercesImpl.version>2.12.2</xercesImpl.version>
77 77 <weixin-java.version>4.6.0</weixin-java.version>
78   - <ureport2.version>2.2.9</ureport2.version>
79 78 <spring-ai-bom.version>0.8.0</spring-ai-bom.version>
80 79 </properties>
81 80  
... ...
yudao-module-ai/pom.xml
... ... @@ -2,28 +2,26 @@
2 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <modelVersion>4.0.0</modelVersion>
6 5 <parent>
7 6 <groupId>cn.iocoder.boot</groupId>
8 7 <artifactId>yudao</artifactId>
9 8 <version>${revision}</version>
10 9 </parent>
11   - <packaging>pom</packaging>
12   - <artifactId>yudao-module-ai</artifactId>
13   -
  10 + <modelVersion>4.0.0</modelVersion>
14 11 <modules>
15 12 <module>yudao-module-ai-api</module>
16 13 <module>yudao-module-ai-biz</module>
17 14 <module>yudao-spring-boot-starter-ai</module>
18 15 </modules>
  16 + <packaging>pom</packaging>
  17 + <artifactId>yudao-module-ai</artifactId>
19 18  
20   - <properties>
21   - <maven.compiler.source>17</maven.compiler.source>
22   - <maven.compiler.target>17</maven.compiler.target>
23   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24   - </properties>
25   -
26   - <dependencies>
27   - </dependencies>
  19 + <name>${project.artifactId}</name>
  20 + <description>
  21 + ai 模块下,接入 LLM 大模型,支持聊天、绘图、音乐、写作、思维脑图等功能。
  22 + 目前已接入各种模型,不限于:
  23 + 国内:通义千问、文心一言、讯飞星火
  24 + 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno
  25 + </description>
28 26  
29 27 </project>
30 28 \ No newline at end of file
... ...
yudao-module-ai/yudao-module-ai-api/pom.xml
... ... @@ -2,32 +2,26 @@
2 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <modelVersion>4.0.0</modelVersion>
6 5 <parent>
7 6 <groupId>cn.iocoder.boot</groupId>
8 7 <artifactId>yudao-module-ai</artifactId>
9 8 <version>${revision}</version>
10 9 </parent>
11   -
  10 + <modelVersion>4.0.0</modelVersion>
12 11 <artifactId>yudao-module-ai-api</artifactId>
  12 + <packaging>jar</packaging>
13 13  
14   - <properties>
15   - <maven.compiler.source>17</maven.compiler.source>
16   - <maven.compiler.target>17</maven.compiler.target>
17   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18   - </properties>
  14 + <name>${project.artifactId}</name>
  15 + <description>
  16 + ai 模块 API,暴露给其它模块调用
  17 + </description>
19 18  
20 19 <dependencies>
21   - <!-- yudao-common -->
22 20 <dependency>
23 21 <groupId>cn.iocoder.boot</groupId>
24 22 <artifactId>yudao-common</artifactId>
25 23 </dependency>
26   - <!-- lombok -->
27   - <dependency>
28   - <groupId>org.projectlombok</groupId>
29   - <artifactId>lombok</artifactId>
30   - </dependency>
  24 +
31 25 <!-- 参数校验 -->
32 26 <dependency>
33 27 <groupId>org.springframework.boot</groupId>
... ...
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java
... ... @@ -12,6 +12,9 @@ public interface ErrorCodeConstants {
12 12 // ========== API 密钥 1-040-000-000 ==========
13 13 ErrorCode API_KEY_NOT_EXISTS = new ErrorCode(1_040_000_000, "API 密钥不存在");
14 14 ErrorCode API_KEY_DISABLE = new ErrorCode(1_040_000_001, "API 密钥已禁用!");
  15 + ErrorCode API_KEY_MIDJOURNEY_NOT_FOUND = new ErrorCode(1_040_000_900, "Midjourney 模型不存在");
  16 + ErrorCode API_KEY_SUNO_NOT_FOUND = new ErrorCode(1_040_000_901, "Suno 模型不存在");
  17 + ErrorCode API_KEY_IMAGE_NODE_FOUND = new ErrorCode(1_040_000_902, "平台({}) 图片模型未配置");
15 18  
16 19 // ========== API 聊天模型 1-040-001-000 ==========
17 20 ErrorCode CHAT_MODEL_NOT_EXISTS = new ErrorCode(1_040_001_000, "模型不存在!");
... ...
yudao-module-ai/yudao-module-ai-biz/pom.xml
... ... @@ -2,21 +2,21 @@
2 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5   - <modelVersion>4.0.0</modelVersion>
6 5 <parent>
7 6 <groupId>cn.iocoder.boot</groupId>
8 7 <artifactId>yudao-module-ai</artifactId>
9 8 <version>${revision}</version>
10 9 </parent>
11   -
  10 + <modelVersion>4.0.0</modelVersion>
12 11 <artifactId>yudao-module-ai-biz</artifactId>
13 12  
14   - <properties>
15   - <maven.compiler.source>8</maven.compiler.source>
16   - <maven.compiler.target>8</maven.compiler.target>
17   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18   - </properties>
19   -
  13 + <name>${project.artifactId}</name>
  14 + <description>
  15 + ai 模块下,接入 LLM 大模型,支持聊天、绘图、音乐、写作、思维脑图等功能。
  16 + 目前已接入各种模型,不限于:
  17 + 国内:通义千问、文心一言、讯飞星火
  18 + 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno
  19 + </description>
20 20  
21 21 <dependencies>
22 22 <dependency>
... ... @@ -24,44 +24,36 @@
24 24 <artifactId>yudao-module-ai-api</artifactId>
25 25 <version>${revision}</version>
26 26 </dependency>
  27 +
  28 + <!-- 业务组件 -->
27 29 <dependency>
28 30 <groupId>cn.iocoder.boot</groupId>
29 31 <artifactId>yudao-spring-boot-starter-ai</artifactId>
30 32 <version>${revision}</version>
31 33 </dependency>
32   - <!-- yudao framwork -->
33   - <dependency>
34   - <groupId>cn.iocoder.boot</groupId>
35   - <artifactId>yudao-common</artifactId>
36   - </dependency>
  34 +
  35 + <!-- Web 相关 -->
37 36 <dependency>
38 37 <groupId>cn.iocoder.boot</groupId>
39 38 <artifactId>yudao-spring-boot-starter-security</artifactId>
40 39 </dependency>
  40 +
  41 + <!-- DB 相关 -->
41 42 <dependency>
42 43 <groupId>cn.iocoder.boot</groupId>
43 44 <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
44 45 </dependency>
45   - <!-- 测试 -->
  46 +
  47 + <!-- Job 相关 -->
46 48 <dependency>
47 49 <groupId>cn.iocoder.boot</groupId>
48   - <artifactId>yudao-spring-boot-starter-test</artifactId>
  50 + <artifactId>yudao-spring-boot-starter-job</artifactId>
49 51 </dependency>
  52 +
  53 + <!-- Test 测试相关 -->
50 54 <dependency>
51 55 <groupId>cn.iocoder.boot</groupId>
52   - <artifactId>yudao-spring-boot-starter-job</artifactId>
  56 + <artifactId>yudao-spring-boot-starter-test</artifactId>
53 57 </dependency>
54 58 </dependencies>
55   - <build>
56   - <plugins>
57   - <plugin>
58   - <groupId>org.apache.maven.plugins</groupId>
59   - <artifactId>maven-compiler-plugin</artifactId>
60   - <configuration>
61   - <source>17</source>
62   - <target>17</target>
63   - </configuration>
64   - </plugin>
65   - </plugins>
66   - </build>
67 59 </project>
68 60 \ No newline at end of file
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImagePageReqVO.java
... ... @@ -13,8 +13,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
13 13  
14 14 @Schema(description = "管理后台 - AI 绘画分页 Request VO")
15 15 @Data
16   -@EqualsAndHashCode(callSuper = true)
17   -@ToString(callSuper = true)
18 16 public class AiImagePageReqVO extends PageParam {
19 17  
20 18 @Schema(description = "用户编号", example = "28987")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java
... ... @@ -5,8 +5,6 @@ import jakarta.validation.constraints.NotEmpty;
5 5 import jakarta.validation.constraints.NotNull;
6 6 import lombok.Data;
7 7  
8   -import java.util.List;
9   -
10 8 @Schema(description = "管理后台 - AI 绘画生成(Midjourney) Request VO")
11 9 @Data
12 10 public class AiMidjourneyImagineReqVO {
... ... @@ -31,7 +29,7 @@ public class AiMidjourneyImagineReqVO {
31 29 @NotEmpty(message = "版本号不能为空")
32 30 private String version;
33 31  
34   - @Schema(description = "参考图")
  32 + @Schema(description = "参考图", example = "https://www.iocoder.cn/x.png")
35 33 private String referImageUrl;
36 34  
37 35 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/apikey/AiApiKeyPageReqVO.java
... ... @@ -11,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
11 11  
12 12 @Schema(description = "管理后台 - AI API 密钥分页 Request VO")
13 13 @Data
14   -@EqualsAndHashCode(callSuper = true)
15   -@ToString(callSuper = true)
16 14 public class AiApiKeyPageReqVO extends PageParam {
17 15  
18 16 @Schema(description = "名称", example = "文心一言")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/chatModel/AiChatModelPageReqVO.java
... ... @@ -6,8 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
6 6  
7 7 @Schema(description = "管理后台 - API 聊天模型分页 Request VO")
8 8 @Data
9   -@EqualsAndHashCode(callSuper = true)
10   -@ToString(callSuper = true)
11 9 public class AiChatModelPageReqVO extends PageParam {
12 10  
13 11 @Schema(description = "模型名字", example = "张三")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/chatRole/AiChatRolePageReqVO.java
... ... @@ -6,8 +6,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
6 6  
7 7 @Schema(description = "管理后台 - AI 聊天角色分页 Request VO")
8 8 @Data
9   -@EqualsAndHashCode(callSuper = true)
10   -@ToString(callSuper = true)
11 9 public class AiChatRolePageReqVO extends PageParam {
12 10  
13 11 @Schema(description = "角色名称", example = "李四")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/music/vo/AiMusicPageReqVO.java
... ... @@ -16,8 +16,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
16 16  
17 17 @Schema(description = "管理后台 - AI 音乐分页 Request VO")
18 18 @Data
19   -@EqualsAndHashCode(callSuper = true)
20   -@ToString(callSuper = true)
21 19 public class AiMusicPageReqVO extends PageParam {
22 20  
23 21 @Schema(description = "用户编号", example = "12212")
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
... ... @@ -35,7 +35,6 @@ import org.springframework.scheduling.annotation.Async;
35 35 import org.springframework.stereotype.Service;
36 36 import org.springframework.transaction.annotation.Transactional;
37 37  
38   -import java.util.ArrayList;
39 38 import java.util.Collections;
40 39 import java.util.List;
41 40 import java.util.Map;
... ... @@ -192,10 +191,8 @@ public class AiImageServiceImpl implements AiImageService {
192 191 imageMapper.insert(image);
193 192  
194 193 // 2. 调用 Midjourney Proxy 提交任务
195   - List<String> base64Array = new ArrayList<>(8);
196   - if (StrUtil.isNotBlank(reqVO.getReferImageUrl())) {
197   - base64Array.add("data:image/jpeg;base64,".concat(Base64.encode(HttpUtil.downloadBytes(reqVO.getReferImageUrl()))));
198   - }
  194 + List<String> base64Array = StrUtil.isBlank(reqVO.getReferImageUrl()) ? null :
  195 + Collections.singletonList("data:image/jpeg;base64,".concat(Base64.encode(HttpUtil.downloadBytes(reqVO.getReferImageUrl()))));
199 196 MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest(
200 197 base64Array, reqVO.getPrompt(),null,
201 198 MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(),
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiApiKeyServiceImpl.java
... ... @@ -108,7 +108,7 @@ public class AiApiKeyServiceImpl implements AiApiKeyService {
108 108 public ImageModel getImageClient(AiPlatformEnum platform) {
109 109 AiApiKeyDO apiKey = apiKeyMapper.selectFirstByPlatformAndStatus(platform.getName(), CommonStatusEnum.ENABLE.getStatus());
110 110 if (apiKey == null) {
111   - return null;
  111 + throw exception(API_KEY_IMAGE_NODE_FOUND, platform.getName());
112 112 }
113 113 return clientFactory.getOrCreateImageClient(platform, apiKey.getApiKey(), apiKey.getUrl());
114 114 }
... ... @@ -117,9 +117,8 @@ public class AiApiKeyServiceImpl implements AiApiKeyService {
117 117 public MidjourneyApi getMidjourneyApi() {
118 118 AiApiKeyDO apiKey = apiKeyMapper.selectFirstByPlatformAndStatus(
119 119 AiPlatformEnum.MIDJOURNEY.getPlatform(), CommonStatusEnum.ENABLE.getStatus());
120   - // todo @芋艿 这些地方直接抛异常会好点,不然调用到的地方都需要做判断
121 120 if (apiKey == null) {
122   - return null;
  121 + throw exception(API_KEY_MIDJOURNEY_NOT_FOUND);
123 122 }
124 123 return clientFactory.getOrCreateMidjourneyApi(apiKey.getApiKey(), apiKey.getUrl());
125 124 }
... ... @@ -129,7 +128,7 @@ public class AiApiKeyServiceImpl implements AiApiKeyService {
129 128 AiApiKeyDO apiKey = apiKeyMapper.selectFirstByPlatformAndStatus(
130 129 AiPlatformEnum.SUNO.getPlatform(), CommonStatusEnum.ENABLE.getStatus());
131 130 if (apiKey == null) {
132   - return null;
  131 + throw exception(API_KEY_SUNO_NOT_FOUND);
133 132 }
134 133 return clientFactory.getOrCreateSunoApi(apiKey.getApiKey(), apiKey.getUrl());
135 134 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/pom.xml
... ... @@ -8,8 +8,9 @@
8 8 <version>${revision}</version>
9 9 </parent>
10 10 <modelVersion>4.0.0</modelVersion>
11   -
12 11 <artifactId>yudao-spring-boot-starter-ai</artifactId>
  12 + <packaging>jar</packaging>
  13 +
13 14 <name>${project.artifactId}</name>
14 15 <description>AI 大模型拓展,接入国内外大模型</description>
15 16 <properties>
... ... @@ -58,6 +59,7 @@
58 59 <version>2.14.0</version>
59 60 </dependency>
60 61  
  62 + <!-- Test 测试相关 -->
61 63 <dependency>
62 64 <groupId>junit</groupId>
63 65 <artifactId>junit</artifactId>
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/package-info.java deleted
1   -/**
2   - * model 包,接入各种大模型,对标 https://github.com/spring-projects/spring-ai/tree/main/models
3   - *
4   - * 1. yiyan 包:【百度】文心一言
5   - * 2. tongyi 包:【阿里】通义千问,对标 spring-cloud-alibaba 提供的 ai 包 TODO 芋艿:未来直接使用它
6   - * 3. xinghuo 包:【讯飞】星火,自己实现
7   - * 4. midjourney 包:Midjourney,接入 https://github.com/novicezk/midjourney-proxy 实现
8   - * 5. suno 包:TODO 芋艿:
9   - */
10   -package cn.iocoder.yudao.framework.ai.core.model;
11 0 \ No newline at end of file
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/package-info.java deleted
1   -/**
2   - * 芋道 AI Starter,整体参考 spring-ai 拓展
3   - */
4   -package cn.iocoder.yudao.framework.ai.core;
5 0 \ No newline at end of file
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/package-info.java
... ... @@ -6,10 +6,8 @@
6 6 * 包路径:
7 7 * 1. chat、parser、model、parser 包:https://github.com/spring-projects/spring-ai/tree/main/spring-ai-core 拷贝
8 8 * 2. models 包:对标 https://github.com/spring-projects/spring-ai/tree/main/models 拷贝
9   - * 2.1 tongyi 包:【阿里】通义千问,对标 spring-cloud-alibaba 提供的 ai 包
10   - * 2.2 yiyan 包:【百度】文心一言,自己实现
11   - * 2.3 xinghuo 包:【讯飞】星火,自己实现
12   - * 2.4 openai 包:【OpenAI】ChatGPT,拷贝 spring-ai 提供的 models/openai 包
13   - * 2.5 midjourney 包:Midjourney,参考 https://github.com/novicezk/midjourney-proxy 实现
  9 + * 2.1 xinghuo 包:【讯飞】星火,自己实现
  10 + * 2.2 midjourney 包:Midjourney API,对接 https://github.com/novicezk/midjourney-proxy 实现
  11 + * 2.3 suno 包:Suno API,对接 https://github.com/gcui-art/suno-api 实现
14 12 */
15 13 package cn.iocoder.yudao.framework.ai;
16 14 \ No newline at end of file
... ...