Commit 32bc632947783ac18dd8618d57e216ac6174892c

Authored by cherishsince
1 parent 337ae045

处理todo

Showing 24 changed files with 165 additions and 268 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiModelEnum.java deleted
1   -package cn.iocoder.yudao.module.ai.enums;
2   -
3   -import lombok.Getter;
4   -
5   -// TODO @fansili:1)类注释要加下;2)author 和 time 用 javadoc,@author 和 @since;3)@AllArgsConstructor 使用这个注解,去掉构造方法;4)value 改成 model 字段,然后注释都写下哈;5)message 改成 name,然后注释都写下哈
6   -/**
7   - * author: fansili
8   - * time: 2024/3/4 12:36
9   - */
10   -@Getter
11   -public enum AiModelEnum {
12   -
13   - OPEN_AI_GPT_3_5("gpt-3.5-turbo", "GPT3.5"),
14   - OPEN_AI_GPT_4("gpt-4-turbo", "GPT4")
15   -
16   - ;
17   -
18   - AiModelEnum(String value, String message) {
19   - this.value = value;
20   - this.message = message;
21   - }
22   -
23   - // TODO @fan
24   - private String value;
25   -
26   - private String message;
27   -
28   -}
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/OpenAiModelEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.ai.enums;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Getter;
  5 +
  6 +// TODO done @fansili:1)类注释要加下;2)author 和 time 用 javadoc,@author 和 @since;3)@AllArgsConstructor 使用这个注解,去掉构造方法;4)value 改成 model 字段,然后注释都写下哈;5)message 改成 name,然后注释都写下哈
  7 +/**
  8 + * @author: fansili
  9 + * @time: 2024/3/4 12:36
  10 + */
  11 +@Getter
  12 +@AllArgsConstructor
  13 +public enum OpenAiModelEnum {
  14 +
  15 + /**
  16 + * open ai 3.5模型
  17 + */
  18 + OPEN_AI_GPT_3_5("gpt-3.5-turbo", "GPT3.5"),
  19 + /**
  20 + * open ai 4.0 收费模型
  21 + */
  22 + OPEN_AI_GPT_4("gpt-4-turbo", "GPT4")
  23 +
  24 + ;
  25 +
  26 + /**
  27 + * 模型 - 用于参数传递
  28 + */
  29 + private String model;
  30 + /**
  31 + * 模型名字 - 用于展示
  32 + */
  33 + private String name;
  34 +
  35 +}
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/ChatController.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
6 6 import cn.iocoder.yudao.module.ai.controller.admin.vo.AiChatReqVO;
7   -import cn.iocoder.yudao.module.ai.enums.AiModelEnum;
  7 +import cn.iocoder.yudao.module.ai.enums.OpenAiModelEnum;
8 8 import io.swagger.v3.oas.annotations.Operation;
9 9 import io.swagger.v3.oas.annotations.tags.Tag;
10 10 import jakarta.servlet.http.HttpServletResponse;
... ... @@ -13,7 +13,6 @@ import org.springframework.ai.chat.ChatClient;
13 13 import org.springframework.ai.chat.ChatResponse;
14 14 import org.springframework.ai.chat.prompt.Prompt;
15 15 import org.springframework.ai.openai.OpenAiChatClient;
16   -import org.springframework.ai.openai.api.OpenAiApi;
17 16 import org.springframework.beans.factory.annotation.Autowired;
18 17 import org.springframework.context.ApplicationContext;
19 18 import org.springframework.validation.annotation.Validated;
... ... @@ -23,16 +22,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
23 22 import org.springframework.web.bind.annotation.RestController;
24 23 import reactor.core.publisher.Flux;
25 24  
26   -import java.util.Scanner;
27 25 import java.util.function.Consumer;
28 26  
29   -// TODO @fansili:有了 swagger 注释,就不用类注释了
30   -/**
31   - * AI模块
32   - *
33   - * author: fansili
34   - * time: 2024/3/3 20:28
35   - */
  27 +// TODO done @fansili:有了 swagger 注释,就不用类注释了
36 28 @Tag(name = "AI模块")
37 29 @RestController
38 30 @RequestMapping("/ai-api")
... ... @@ -48,7 +40,7 @@ public class ChatController {
48 40 ChatClient chatClient = getChatClient(reqVO.getAiModel());
49 41 String res;
50 42 try {
51   - res = chatClient.call(reqVO.getInputText());
  43 + res = chatClient.call(reqVO.getPrompt());
52 44 } catch (Exception e) {
53 45 res = e.getMessage();
54 46 }
... ... @@ -59,33 +51,14 @@ public class ChatController {
59 51 @Operation(summary = "对话聊天chatStream", description = "简单的ai聊天")
60 52 public CommonResult chatStream(HttpServletResponse response, @RequestBody @Validated AiChatReqVO reqVO) throws InterruptedException {
61 53 OpenAiChatClient chatClient = applicationContext.getBean(OpenAiChatClient.class);
62   - Flux<ChatResponse> chatResponse = chatClient.stream(new Prompt(reqVO.getInputText()));
  54 + Flux<ChatResponse> chatResponse = chatClient.stream(new Prompt(reqVO.getPrompt()));
63 55 chatResponse.subscribe(new Consumer<ChatResponse>() {
64 56 @Override
65 57 public void accept(ChatResponse chatResponse) {
66 58 System.err.println(chatResponse.getResults().get(0).getOutput().getContent());
67 59 }
68 60 });
69   - return CommonResult.success("1");
70   - }
71   -
72   - public static void main(String[] args) {
73   - OpenAiChatClient openAiChatClient = new OpenAiChatClient(new OpenAiApi("openkey"));
74   - Flux<ChatResponse> responseFlux = openAiChatClient.stream(new Prompt("最好的编程语言!"));
75   - long now = System.currentTimeMillis();
76   - responseFlux.subscribe(new Consumer<ChatResponse>() {
77   - @Override
78   - public void accept(ChatResponse chatResponse) {
79   - if (chatResponse.getResults().get(0).getOutput() == null) {
80   - return;
81   - }
82   - System.err.println(chatResponse.getResults().get(0).getOutput().getContent());
83   - }
84   - });
85   -
86   - // 阻止退出
87   - Scanner scanner = new Scanner(System.in);
88   - scanner.nextLine();
  61 + return CommonResult.success(null);
89 62 }
90 63  
91 64 /**
... ... @@ -94,8 +67,8 @@ public class ChatController {
94 67 * @param aiModelEnum
95 68 * @return
96 69 */
97   - private ChatClient getChatClient(AiModelEnum aiModelEnum) {
98   - if (AiModelEnum.OPEN_AI_GPT_3_5 == aiModelEnum) {
  70 + private ChatClient getChatClient(OpenAiModelEnum aiModelEnum) {
  71 + if (OpenAiModelEnum.OPEN_AI_GPT_3_5 == aiModelEnum) {
99 72 return applicationContext.getBean(OpenAiChatClient.class);
100 73 }
101 74 // AI模型暂不支持
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/vo/AiChatReqVO.java
1 1 package cn.iocoder.yudao.module.ai.controller.admin.vo;
2 2  
3   -import cn.iocoder.yudao.module.ai.enums.AiModelEnum;
  3 +import cn.iocoder.yudao.module.ai.enums.OpenAiModelEnum;
4 4 import io.swagger.v3.oas.annotations.media.Schema;
5 5 import jakarta.validation.constraints.NotNull;
6 6 import lombok.Data;
7 7  
8   -// TODO @fansili 1)swagger 注释不太对;2)有了 swagger 注释,就不用类注释了
9   -/**
10   - * ai 聊天 req
11   - *
12   - * author: fansili
13   - * time: 2024/3/4 12:33
14   - */
15   -@Schema(description = "用户 App - 上传文件 Request VO")
  8 +// TODO done @fansili 1)swagger 注释不太对;2)有了 swagger 注释,就不用类注释了
16 9 @Data
  10 +@Schema(description = "用户 App - 上传文件 Request VO")
17 11 public class AiChatReqVO {
18 12  
19   - @Schema(description = "输入内容", requiredMode = Schema.RequiredMode.REQUIRED)
20   - @NotNull(message = "输入内容不能为空")
21   - private String inputText;
  13 + @Schema(description = "提示词", requiredMode = Schema.RequiredMode.REQUIRED)
  14 + @NotNull(message = "提示词不能为空!")
  15 + private String prompt;
22 16  
23 17 @Schema(description = "AI模型", requiredMode = Schema.RequiredMode.REQUIRED)
24 18 @NotNull(message = "AI模型不能为空")
25   - private AiModelEnum aiModel;
  19 + private OpenAiModelEnum aiModel;
26 20  
27 21 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/pom.xml
... ... @@ -149,6 +149,10 @@
149 149 <!-- </exclusion>-->
150 150 <!-- </exclusions>-->
151 151 </dependency>
  152 + <dependency>
  153 + <groupId>cn.iocoder.boot</groupId>
  154 + <artifactId>yudao-common</artifactId>
  155 + </dependency>
152 156 </dependencies>
153 157  
154 158 </project>
155 159 \ No newline at end of file
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatqianwen/QianWenChatClient.java
... ... @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.ai.chat.*;
6 6 import cn.iocoder.yudao.framework.ai.chat.messages.MessageType;
7 7 import cn.iocoder.yudao.framework.ai.chat.prompt.ChatOptions;
8 8 import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt;
  9 +import cn.iocoder.yudao.framework.ai.chatqianwen.api.QianWenApi;
9 10 import cn.iocoder.yudao.framework.ai.chatyiyan.exception.YiYanApiException;
10 11 import com.aliyun.broadscope.bailian.sdk.models.*;
11 12 import lombok.extern.slf4j.Slf4j;
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatqianwen/QianWenApi.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/chatqianwen/api/QianWenApi.java
1   -package cn.iocoder.yudao.framework.ai.chatqianwen;
  1 +package cn.iocoder.yudao.framework.ai.chatqianwen.api;
2 2  
3 3 import com.aliyun.broadscope.bailian.sdk.AccessTokenClient;
4 4 import com.aliyun.broadscope.bailian.sdk.ApplicationClient;
... ... @@ -9,7 +9,7 @@ import org.springframework.http.HttpStatusCode;
9 9 import org.springframework.http.ResponseEntity;
10 10 import reactor.core.publisher.Flux;
11 11  
12   -// TODO @fansili:是不是挪到 api 包里?按照 spring ai 的结构;根目录只放 client 和 options
  12 +// TODO done @fansili:是不是挪到 api 包里?按照 spring ai 的结构;根目录只放 client 和 options
13 13 /**
14 14 * 阿里 通义千问
15 15 *
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/OpenAiImageApi.java
... ... @@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
4 4 import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageRequest;
5 5 import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageResponse;
6 6 import cn.iocoder.yudao.framework.ai.util.JacksonUtil;
  7 +import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
7 8 import io.netty.channel.ChannelOption;
8 9 import lombok.extern.slf4j.Slf4j;
9 10 import org.apache.http.HttpEntity;
... ... @@ -55,7 +56,7 @@ public class OpenAiImageApi {
55 56 httpPost.setURI(URI.create(DEFAULT_BASE_URL.concat("/v1/images/generations")));
56 57 httpPost.setHeader("Content-Type", "application/json");
57 58 httpPost.setHeader("Authorization", "Bearer " + apiKey);
58   - httpPost.setEntity(new StringEntity(JacksonUtil.toJson(request), "UTF-8"));
  59 + httpPost.setEntity(new StringEntity(JsonUtils.toJsonString(request), "UTF-8"));
59 60  
60 61 CloseableHttpResponse response= null;
61 62 try {
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/MjMessage.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyMessage.java
1 1 package cn.iocoder.yudao.framework.ai.midjourney;
2 2  
  3 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyGennerateStatusEnum;
3 4 import lombok.Data;
4 5 import lombok.experimental.Accessors;
5 6  
... ... @@ -7,7 +8,7 @@ import java.util.List;
7 8  
8 9 @Data
9 10 @Accessors(chain = true)
10   -public class MjMessage {
  11 +public class MidjourneyMessage {
11 12  
12 13 /**
13 14 * id是一个重要的字段,在同时生成多个的时候,可以区分生成信息
... ... @@ -41,7 +42,7 @@ public class MjMessage {
41 42 * 1、等待
42 43 * 2、进行中
43 44 * 3、完成
44   - * {@link cn.iocoder.yudao.framework.ai.midjourney.constants.MjGennerateStatusEnum}
  45 + * {@link MidjourneyGennerateStatusEnum}
45 46 */
46 47 private String generateStatus;
47 48  
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MjConstants.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MidjourneyConstants.java
1 1 package cn.iocoder.yudao.framework.ai.midjourney.constants;
2 2  
3   -public final class MjConstants {
  3 +public final class MidjourneyConstants {
4 4  
5 5 /**
6 6 * 消息 - 编号
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MjGennerateStatusEnum.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MidjourneyGennerateStatusEnum.java
1 1 package cn.iocoder.yudao.framework.ai.midjourney.constants;
2 2  
  3 +import lombok.AllArgsConstructor;
3 4 import lombok.Getter;
4 5  
5   -// TODO @fansili:1)Mj 缩写,还是搞成全称。。虽然长一点,但是感觉会相对清晰一些哈;2)lombok 相关的注解,可以用用哈;3)value 改 status;
  6 +// TODO done @fansili:1)Mj 缩写,还是搞成全称。。虽然长一点,但是感觉会相对清晰一些哈;2)lombok 相关的注解,可以用用哈;3)value 改 status;
6 7 /**
7 8 * mj 生成状态
8 9 *
... ... @@ -10,8 +11,8 @@ import lombok.Getter;
10 11 * time: 2024/4/6 21:07
11 12 */
12 13 @Getter
13   -public enum MjGennerateStatusEnum {
14   -
  14 +@AllArgsConstructor
  15 +public enum MidjourneyGennerateStatusEnum {
15 16  
16 17 WAITING("waiting", "等待..."),
17 18 IN_PROGRESS("in_progress", "进行中"),
... ... @@ -19,12 +20,12 @@ public enum MjGennerateStatusEnum {
19 20  
20 21 ;
21 22  
22   - MjGennerateStatusEnum(String value, String message) {
23   - this.value = value;
24   - this.message = message;
25   - }
26   -
27   - private String value;
28   -
  23 + /**
  24 + * 状态
  25 + */
  26 + private String status;
  27 + /**
  28 + * 状态信息
  29 + */
29 30 private String message;
30 31 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MjInteractionsEnum.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MidjourneyInteractionsEnum.java
... ... @@ -6,7 +6,7 @@ import lombok.Getter;
6 6 * MJ 命令
7 7 */
8 8 @Getter
9   -public enum MjInteractionsEnum {
  9 +public enum MidjourneyInteractionsEnum {
10 10  
11 11 IMAGINE("imagine", "生成图片"),
12 12 DESCRIBE("describe", "生成描述"),
... ... @@ -17,7 +17,7 @@ public enum MjInteractionsEnum {
17 17  
18 18 ;
19 19  
20   - MjInteractionsEnum(String value, String message) {
  20 + MidjourneyInteractionsEnum(String value, String message) {
21 21 this.value =value;
22 22 this.message =message;
23 23 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MjMessageTypeEnum.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MidjourneyMessageTypeEnum.java
1 1 package cn.iocoder.yudao.framework.ai.midjourney.constants;
2 2  
3 3  
4   -public enum MjMessageTypeEnum {
  4 +public enum MidjourneyMessageTypeEnum {
5 5 /**
6 6 * 创建.
7 7 */
... ... @@ -15,7 +15,7 @@ public enum MjMessageTypeEnum {
15 15 */
16 16 DELETE;
17 17  
18   - public static MjMessageTypeEnum of(String type) {
  18 + public static MidjourneyMessageTypeEnum of(String type) {
19 19 return switch (type) {
20 20 case "MESSAGE_CREATE" -> CREATE;
21 21 case "MESSAGE_UPDATE" -> UPDATE;
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MjNotifyCode.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/constants/MidjourneyNotifyCode.java
... ... @@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.ai.midjourney.constants;
3 3 import lombok.experimental.UtilityClass;
4 4  
5 5 @UtilityClass
6   -public final class MjNotifyCode {
  6 +public final class MidjourneyNotifyCode {
7 7 /**
8 8 * 成功.
9 9 */
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjInteractions.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MidjourneyInteractions.java
... ... @@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.ai.midjourney.interactions;
3 3 import cn.hutool.core.util.IdUtil;
4 4 import cn.hutool.core.util.StrUtil;
5 5 import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
6   -import cn.iocoder.yudao.framework.ai.midjourney.constants.MjConstants;
7   -import cn.iocoder.yudao.framework.ai.midjourney.util.MjUtil;
  6 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyConstants;
  7 +import cn.iocoder.yudao.framework.ai.midjourney.util.MidjourneyUtil;
8 8 import cn.iocoder.yudao.framework.ai.midjourney.vo.Attachments;
9 9 import cn.iocoder.yudao.framework.ai.midjourney.vo.Describe;
10 10 import cn.iocoder.yudao.framework.ai.midjourney.vo.ReRoll;
... ... @@ -32,15 +32,17 @@ import java.util.HashMap;
32 32 * time: 2024/4/3 17:36
33 33 */
34 34 @Slf4j
35   -public class MjInteractions {
  35 +public class MidjourneyInteractions {
  36 +
  37 + // TODO done @fansili:静态变量,放在最前面哈;
  38 + private static final String HEADER_REFERER = "https://discord.com/channels/%s/%s";
36 39  
37 40 private final String url;
38 41 private final MidjourneyConfig midjourneyConfig;
39 42 private final RestTemplate restTemplate = new RestTemplate(); // TODO @fansili:优先级低:后续搞到统一的管理
40   - // TODO @fansili:静态变量,放在最前面哈;
41   - private static final String HEADER_REFERER = "https://discord.com/channels/%s/%s";
42 43  
43   - public MjInteractions(MidjourneyConfig midjourneyConfig) {
  44 +
  45 + public MidjourneyInteractions(MidjourneyConfig midjourneyConfig) {
44 46 this.midjourneyConfig = midjourneyConfig;
45 47 this.url = midjourneyConfig.getServerUrl().concat(midjourneyConfig.getApiInteractions());
46 48 }
... ... @@ -57,7 +59,7 @@ public class MjInteractions {
57 59 requestParams.put("nonce", String.valueOf(IdUtil.getSnowflakeNextId())); // TODO @fansili:建议用 uuid 之类的;nextId 跨进程未必合适哈;
58 60 requestParams.put("prompt", prompt);
59 61 // 解析 template 参数占位符
60   - String requestBody = MjUtil.parseTemplate(requestTemplate, requestParams);
  62 + String requestBody = MidjourneyUtil.parseTemplate(requestTemplate, requestParams);
61 63 // 获取 header
62 64 HttpHeaders httpHeaders = getHttpHeaders();
63 65 // 发送请求
... ... @@ -65,14 +67,14 @@ public class MjInteractions {
65 67 String res = restTemplate.postForObject(url, requestEntity, String.class);
66 68 // 这个 res 只要不返回值,就是成功!
67 69 // TODO @fansili:可以直接 if (StrUtil.isBlank(res))
68   - boolean isSuccess = StrUtil.isBlank(res);
69   - if (isSuccess) {
  70 + if (StrUtil.isBlank(res)) {
70 71 return true;
  72 + } else {
  73 + log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
  74 + return false;
71 75 }
72   - log.error("请求失败! 请求参数:{} 返回结果! {}", requestBody, res);
73   - return isSuccess;
74 76 }
75   - // TODO @fansili:方法和方法之间,空一行哈;
  77 + // TODO done @fansili:方法和方法之间,空一行哈;
76 78  
77 79  
78 80 public Boolean reRoll(ReRoll reRoll) {
... ... @@ -89,7 +91,7 @@ public class MjInteractions {
89 91 // 获取 header
90 92 HttpHeaders httpHeaders = getHttpHeaders();
91 93 // 设置参数
92   - String requestBody = MjUtil.parseTemplate(requestTemplate, requestParams);
  94 + String requestBody = MidjourneyUtil.parseTemplate(requestTemplate, requestParams);
93 95 // 发送请求
94 96 HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, httpHeaders);
95 97 String res = restTemplate.postForObject(url, requestEntity, String.class);
... ... @@ -123,7 +125,7 @@ public class MjInteractions {
123 125 httpHeaders.setContentType(MediaType.APPLICATION_JSON);
124 126 httpHeaders.set("Authorization", midjourneyConfig.getToken());
125 127 httpHeaders.set("User-Agent", midjourneyConfig.getUserAage());
126   - httpHeaders.set("Cookie", MjConstants.HTTP_COOKIE);
  128 + httpHeaders.set("Cookie", MidjourneyConstants.HTTP_COOKIE);
127 129 httpHeaders.set("Referer", String.format(HEADER_REFERER, midjourneyConfig.getGuildId(), midjourneyConfig.getChannelId()));
128 130 // 创建HttpEntity对象,包含表单数据和头部信息
129 131 HttpEntity<MultiValueMap<String, Object>> multiValueMapHttpEntity = new HttpEntity<>(multipartRequest, httpHeaders);
... ... @@ -132,16 +134,13 @@ public class MjInteractions {
132 134 String response = restTemplate.postForObject(midjourneyConfig.getServerUrl().concat(uri), multiValueMapHttpEntity, String.class);
133 135 UploadAttachmentsRes uploadAttachmentsRes = JSON.parseObject(response, UploadAttachmentsRes.class);
134 136  
135   -
136 137 //
137 138 // 上传文件
138 139 String uploadUrl = uploadAttachmentsRes.getAttachments().getFirst().getUploadUrl();
139   - String uploadAttachmentsUrl = midjourneyConfig.getApiAttachmentsUpload().concat(uploadUrl);
140 140 httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
141 141 HttpEntity<FileSystemResource> fileSystemResourceHttpEntity = new HttpEntity<>(attachments.getFileSystemResource(), httpHeaders);
142 142 ResponseEntity<String> exchange = restTemplate.exchange(uploadUrl, HttpMethod.PUT, fileSystemResourceHttpEntity, String.class);
143 143 String uploadRes = exchange.getBody();
144   -
145 144 return uploadAttachmentsRes;
146 145 }
147 146  
... ... @@ -161,9 +160,9 @@ public class MjInteractions {
161 160 httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); // 设置内容类型为JSON
162 161 httpHeaders.set("Authorization", midjourneyConfig.getToken());
163 162 httpHeaders.set("User-Agent", midjourneyConfig.getUserAage());
164   - httpHeaders.set("Cookie", MjConstants.HTTP_COOKIE);
  163 + httpHeaders.set("Cookie", MidjourneyConstants.HTTP_COOKIE);
165 164 httpHeaders.set("Referer", String.format(HEADER_REFERER, midjourneyConfig.getGuildId(), midjourneyConfig.getChannelId()));
166   - String requestBody = MjUtil.parseTemplate(requestTemplate, requestParams);
  165 + String requestBody = MidjourneyUtil.parseTemplate(requestTemplate, requestParams);
167 166 // 创建表单数据
168 167 MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
169 168 formData.add("payload_json", requestBody);
... ... @@ -185,7 +184,7 @@ public class MjInteractions {
185 184 httpHeaders.setContentType(MediaType.APPLICATION_JSON); // 设置内容类型为JSON
186 185 httpHeaders.set("Authorization", midjourneyConfig.getToken());
187 186 httpHeaders.set("User-Agent", midjourneyConfig.getUserAage());
188   - httpHeaders.set("Cookie", MjConstants.HTTP_COOKIE);
  187 + httpHeaders.set("Cookie", MidjourneyConstants.HTTP_COOKIE);
189 188 httpHeaders.set("Referer", String.format(HEADER_REFERER, midjourneyConfig.getGuildId(), midjourneyConfig.getChannelId()));
190 189 return httpHeaders;
191 190 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/util/MjUtil.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/util/MidjourneyUtil.java
1 1 package cn.iocoder.yudao.framework.ai.midjourney.util;
2 2  
3 3 import cn.hutool.core.text.CharSequenceUtil;
4   -import cn.iocoder.yudao.framework.ai.midjourney.MjMessage;
  4 +import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyMessage;
5 5  
6 6 import java.util.Map;
7 7 import java.util.regex.Matcher;
... ... @@ -13,7 +13,7 @@ import java.util.regex.Pattern;
13 13 * author: fansili
14 14 * time: 2024/4/6 19:00
15 15 */
16   -public class MjUtil {
  16 +public class MidjourneyUtil {
17 17 /**
18 18 * content正则匹配prompt和进度.
19 19 */
... ... @@ -26,12 +26,12 @@ public class MjUtil {
26 26 * @param content
27 27 * @return
28 28 */
29   - public static MjMessage.Content parseContent(String content) {
  29 + public static MidjourneyMessage.Content parseContent(String content) {
30 30 // 有三种格式。
31 31 // 南极应该是什么样子?
32 32 // "**南极应该是什么样子? --v 6.0 --style raw** - <@972721304891453450> (32%) (fast, stealth)",
33 33 // "**南极应该是什么样子? --v 6.0 --style raw** - <@972721304891453450> (fast, stealth)"
34   - MjMessage.Content mjContent = new MjMessage.Content();
  34 + MidjourneyMessage.Content mjContent = new MidjourneyMessage.Content();
35 35 if (CharSequenceUtil.isBlank(content)) {
36 36 return null;
37 37 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/MjWebSocketStarter.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/MidjourneyWebSocketStarter.java
... ... @@ -4,9 +4,9 @@ package cn.iocoder.yudao.framework.ai.midjourney.webSocket;
4 4 import cn.hutool.core.text.CharSequenceUtil;
5 5 import cn.hutool.core.thread.ThreadUtil;
6 6 import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
7   -import cn.iocoder.yudao.framework.ai.midjourney.constants.MjNotifyCode;
8   -import cn.iocoder.yudao.framework.ai.midjourney.webSocket.handler.MjWebSocketHandler;
9   -import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MjMessageListener;
  7 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyNotifyCode;
  8 +import cn.iocoder.yudao.framework.ai.midjourney.webSocket.handler.MidjourneyWebSocketHandler;
  9 +import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MidjourneyMessageListener;
10 10 import lombok.Getter;
11 11 import lombok.extern.slf4j.Slf4j;
12 12 import org.apache.tomcat.websocket.Constants;
... ... @@ -20,11 +20,10 @@ import org.springframework.web.socket.client.standard.StandardWebSocketClient;
20 20  
21 21 import java.io.IOException;
22 22 import java.net.URI;
23   -import java.util.concurrent.TimeoutException;
24 23  
25 24 // TODO @fansili:mj 这块 websocket 有点小复杂,虽然代码量 400 多行;感觉可以考虑,有没第三方 sdk,通过它透明接入 mj
26 25 @Slf4j
27   -public class MjWebSocketStarter implements WebSocketStarter {
  26 +public class MidjourneyWebSocketStarter implements WebSocketStarter {
28 27 /**
29 28 * 链接重试次数
30 29 */
... ... @@ -36,7 +35,7 @@ public class MjWebSocketStarter implements WebSocketStarter {
36 35 /**
37 36 * mj 监听(所有message 都会 callback到这里)
38 37 */
39   - private final MjMessageListener userMessageListener;
  38 + private final MidjourneyMessageListener userMessageListener;
40 39 /**
41 40 * wss 服务器
42 41 */
... ... @@ -58,10 +57,10 @@ public class MjWebSocketStarter implements WebSocketStarter {
58 57 */
59 58 private WebSocketSession webSocketSession = null;
60 59  
61   - public MjWebSocketStarter(String wssServer,
62   - String resumeWss,
63   - MidjourneyConfig midjourneyConfig,
64   - MjMessageListener userMessageListener) {
  60 + public MidjourneyWebSocketStarter(String wssServer,
  61 + String resumeWss,
  62 + MidjourneyConfig midjourneyConfig,
  63 + MidjourneyMessageListener userMessageListener) {
65 64 this.wssServer = wssServer;
66 65 this.resumeWss = resumeWss;
67 66 this.midjourneyConfig = midjourneyConfig;
... ... @@ -83,7 +82,7 @@ public class MjWebSocketStarter implements WebSocketStarter {
83 82 headers.add("Sec-Websocket-Extensions", "permessage-deflate; client_max_window_bits");
84 83 headers.add("User-Agent", this.midjourneyConfig.getUserAage());
85 84 // 创建 mjHeader
86   - MjWebSocketHandler mjWebSocketHandler = new MjWebSocketHandler(
  85 + MidjourneyWebSocketHandler mjWebSocketHandler = new MidjourneyWebSocketHandler(
87 86 this.midjourneyConfig, this.userMessageListener, this::onSocketSuccess, this::onSocketFailure);
88 87 //
89 88 String gatewayUrl;
... ... @@ -105,12 +104,12 @@ public class MjWebSocketStarter implements WebSocketStarter {
105 104 socketSessionFuture.addCallback(new ListenableFutureCallback<>() {
106 105 @Override
107 106 public void onFailure(@NotNull Throwable e) {
108   - onSocketFailure(MjWebSocketHandler.CLOSE_CODE_EXCEPTION, e.getMessage());
  107 + onSocketFailure(MidjourneyWebSocketHandler.CLOSE_CODE_EXCEPTION, e.getMessage());
109 108 }
110 109  
111 110 @Override
112 111 public void onSuccess(WebSocketSession session) {
113   - MjWebSocketStarter.this.webSocketSession = session;
  112 + MidjourneyWebSocketStarter.this.webSocketSession = session;
114 113 }
115 114 });
116 115 }
... ... @@ -118,7 +117,7 @@ public class MjWebSocketStarter implements WebSocketStarter {
118 117 private void onSocketSuccess(String sessionId, Object sequence, String resumeGatewayUrl) {
119 118 this.resumeData = new ResumeData(sessionId, sequence, resumeGatewayUrl);
120 119 this.running = true;
121   - notifyWssLock(MjNotifyCode.SUCCESS, "");
  120 + notifyWssLock(MidjourneyNotifyCode.SUCCESS, "");
122 121 }
123 122  
124 123 private void onSocketFailure(int code, String reason) {
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/handler/MjWebSocketHandler.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/handler/MidjourneyWebSocketHandler.java
... ... @@ -8,7 +8,7 @@ import cn.hutool.http.useragent.UserAgentUtil;
8 8 import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
9 9 import cn.iocoder.yudao.framework.ai.midjourney.webSocket.FailureCallback;
10 10 import cn.iocoder.yudao.framework.ai.midjourney.webSocket.SuccessCallback;
11   -import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MjMessageListener;
  11 +import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MidjourneyMessageListener;
12 12 import lombok.Setter;
13 13 import lombok.extern.slf4j.Slf4j;
14 14 import net.dv8tion.jda.api.utils.data.DataArray;
... ... @@ -29,7 +29,7 @@ import java.util.concurrent.ScheduledExecutorService;
29 29 import java.util.concurrent.TimeUnit;
30 30  
31 31 @Slf4j
32   -public class MjWebSocketHandler implements WebSocketHandler {
  32 +public class MidjourneyWebSocketHandler implements WebSocketHandler {
33 33 /**
34 34 * close 错误码:重连
35 35 */
... ... @@ -49,7 +49,7 @@ public class MjWebSocketHandler implements WebSocketHandler {
49 49 /**
50 50 * mj 消息监听
51 51 */
52   - private final MjMessageListener userMessageListener;
  52 + private final MidjourneyMessageListener userMessageListener;
53 53 /**
54 54 * 成功回调
55 55 */
... ... @@ -85,10 +85,10 @@ public class MjWebSocketHandler implements WebSocketHandler {
85 85 */
86 86 private final Decompressor decompressor = new ZlibDecompressor(2048);
87 87  
88   - public MjWebSocketHandler(MidjourneyConfig account,
89   - MjMessageListener userMessageListener,
90   - SuccessCallback successCallback,
91   - FailureCallback failureCallback) {
  88 + public MidjourneyWebSocketHandler(MidjourneyConfig account,
  89 + MidjourneyMessageListener userMessageListener,
  90 + SuccessCallback successCallback,
  91 + FailureCallback failureCallback) {
92 92 this.midjourneyConfig = account;
93 93 this.userMessageListener = userMessageListener;
94 94 this.successCallback = successCallback;
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/listener/MjMessageListener.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/webSocket/listener/MidjourneyMessageListener.java
... ... @@ -6,11 +6,11 @@ import cn.hutool.core.text.CharSequenceUtil;
6 6 import cn.hutool.core.util.StrUtil;
7 7 import cn.hutool.json.JSONUtil;
8 8 import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
9   -import cn.iocoder.yudao.framework.ai.midjourney.MjMessage;
10   -import cn.iocoder.yudao.framework.ai.midjourney.constants.MjConstants;
11   -import cn.iocoder.yudao.framework.ai.midjourney.constants.MjGennerateStatusEnum;
12   -import cn.iocoder.yudao.framework.ai.midjourney.constants.MjMessageTypeEnum;
13   -import cn.iocoder.yudao.framework.ai.midjourney.util.MjUtil;
  9 +import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyMessage;
  10 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyConstants;
  11 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyGennerateStatusEnum;
  12 +import cn.iocoder.yudao.framework.ai.midjourney.constants.MidjourneyMessageTypeEnum;
  13 +import cn.iocoder.yudao.framework.ai.midjourney.util.MidjourneyUtil;
14 14 import com.alibaba.fastjson.JSON;
15 15 import lombok.extern.slf4j.Slf4j;
16 16 import net.dv8tion.jda.api.utils.data.DataObject;
... ... @@ -18,17 +18,17 @@ import net.dv8tion.jda.api.utils.data.DataObject;
18 18 import java.util.List;
19 19  
20 20 @Slf4j
21   -public class MjMessageListener {
  21 +public class MidjourneyMessageListener {
22 22  
23 23 private MidjourneyConfig midjourneyConfig;
24 24  
25   - public MjMessageListener(MidjourneyConfig midjourneyConfig) {
  25 + public MidjourneyMessageListener(MidjourneyConfig midjourneyConfig) {
26 26 this.midjourneyConfig = midjourneyConfig;
27 27 }
28 28  
29 29 public void onMessage(DataObject raw) {
30   - MjMessageTypeEnum messageType = MjMessageTypeEnum.of(raw.getString("t"));
31   - if (messageType == null || MjMessageTypeEnum.DELETE == messageType) {
  30 + MidjourneyMessageTypeEnum messageType = MidjourneyMessageTypeEnum.of(raw.getString("t"));
  31 + if (messageType == null || MidjourneyMessageTypeEnum.DELETE == messageType) {
32 32 return;
33 33 }
34 34 DataObject data = raw.getObject("d");
... ... @@ -37,21 +37,21 @@ public class MjMessageListener {
37 37 }
38 38  
39 39 // 转换几个重要的信息
40   - MjMessage mjMessage = new MjMessage();
41   - mjMessage.setId(data.getString(MjConstants.MSG_ID));
42   - mjMessage.setType(data.getInt(MjConstants.MSG_TYPE));
  40 + MidjourneyMessage mjMessage = new MidjourneyMessage();
  41 + mjMessage.setId(data.getString(MidjourneyConstants.MSG_ID));
  42 + mjMessage.setType(data.getInt(MidjourneyConstants.MSG_TYPE));
43 43 mjMessage.setRawData(StrUtil.str(raw.toJson(), "UTF-8"));
44   - mjMessage.setContent(MjUtil.parseContent(data.getString(MjConstants.MSG_CONTENT)));
  44 + mjMessage.setContent(MidjourneyUtil.parseContent(data.getString(MidjourneyConstants.MSG_CONTENT)));
45 45 // 转换 components
46   - if (!data.getArray(MjConstants.MSG_COMPONENTS).isEmpty()) {
47   - String componentsJson = StrUtil.str(data.getArray(MjConstants.MSG_COMPONENTS).toJson(), "UTF-8");
48   - List<MjMessage.ComponentType> components = JSON.parseArray(componentsJson, MjMessage.ComponentType.class);
  46 + if (!data.getArray(MidjourneyConstants.MSG_COMPONENTS).isEmpty()) {
  47 + String componentsJson = StrUtil.str(data.getArray(MidjourneyConstants.MSG_COMPONENTS).toJson(), "UTF-8");
  48 + List<MidjourneyMessage.ComponentType> components = JSON.parseArray(componentsJson, MidjourneyMessage.ComponentType.class);
49 49 mjMessage.setComponents(components);
50 50 }
51 51 // 转换附件
52   - if (!data.getArray(MjConstants.MSG_ATTACHMENTS).isEmpty()) {
53   - String attachmentsJson = StrUtil.str(data.getArray(MjConstants.MSG_ATTACHMENTS).toJson(), "UTF-8");
54   - List<MjMessage.Attachment> attachments = JSON.parseArray(attachmentsJson, MjMessage.Attachment.class);
  52 + if (!data.getArray(MidjourneyConstants.MSG_ATTACHMENTS).isEmpty()) {
  53 + String attachmentsJson = StrUtil.str(data.getArray(MidjourneyConstants.MSG_ATTACHMENTS).toJson(), "UTF-8");
  54 + List<MidjourneyMessage.Attachment> attachments = JSON.parseArray(attachmentsJson, MidjourneyMessage.Attachment.class);
55 55 mjMessage.setAttachments(attachments);
56 56 }
57 57 // 转换状态
... ... @@ -61,18 +61,18 @@ public class MjMessageListener {
61 61 System.err.println(JSONUtil.toJsonPrettyStr(mjMessage));
62 62 }
63 63  
64   - private void convertGenerateStatus(MjMessage mjMessage) {
  64 + private void convertGenerateStatus(MidjourneyMessage mjMessage) {
65 65 if (mjMessage.getType() == 20 && mjMessage.getContent().getStatus().contains("Waiting")) {
66   - mjMessage.setGenerateStatus(MjGennerateStatusEnum.WAITING.getValue());
  66 + mjMessage.setGenerateStatus(MidjourneyGennerateStatusEnum.WAITING.getValue());
67 67 } else if (mjMessage.getType() == 20 && !StrUtil.isBlank(mjMessage.getContent().getProgress())) {
68   - mjMessage.setGenerateStatus(MjGennerateStatusEnum.IN_PROGRESS.getValue());
  68 + mjMessage.setGenerateStatus(MidjourneyGennerateStatusEnum.IN_PROGRESS.getValue());
69 69 } else if (mjMessage.getType() == 0 && !CollUtil.isEmpty(mjMessage.getComponents())) {
70   - mjMessage.setGenerateStatus(MjGennerateStatusEnum.COMPLETED.getValue());
  70 + mjMessage.setGenerateStatus(MidjourneyGennerateStatusEnum.COMPLETED.getValue());
71 71 }
72 72 }
73 73  
74   - private boolean ignoreAndLogMessage(DataObject data, MjMessageTypeEnum messageType) {
75   - String channelId = data.getString(MjConstants.MSG_CHANNEL_ID);
  74 + private boolean ignoreAndLogMessage(DataObject data, MidjourneyMessageTypeEnum messageType) {
  75 + String channelId = data.getString(MidjourneyConstants.MSG_CHANNEL_ID);
76 76 if (!CharSequenceUtil.equals(channelId, midjourneyConfig.getChannelId())) {
77 77 return true;
78 78 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/util/JacksonUtil.java deleted
1   -package cn.iocoder.yudao.framework.ai.util;
2   -
3   -import com.fasterxml.jackson.annotation.JsonInclude;
4   -import com.fasterxml.jackson.core.JsonProcessingException;
5   -import com.fasterxml.jackson.databind.ObjectMapper;
6   -import com.fasterxml.jackson.databind.SerializationFeature;
7   -import com.fasterxml.jackson.databind.module.SimpleModule;
8   -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
9   -
10   -import java.io.IOException;
11   -
12   -// TODO @fansili:看看能不能用 JsonUtils
13   -/**
14   - * Jackson工具类
15   - *
16   - * author: fansili
17   - * time: 2024/3/17 10:13
18   - */
19   -public class JacksonUtil {
20   -
21   - private static final ObjectMapper objectMapper = new ObjectMapper();
22   -
23   - /**
24   - * 初始化 ObjectMapper 以美化输出(即格式化JSON内容)
25   - */
26   - static {
27   - // 美化输出(缩进)
28   - objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
29   - // 忽略值为 null 的属性
30   - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
31   - // 配置一个模块来将 Long 类型转换为 String 类型
32   - SimpleModule module = new SimpleModule();
33   - module.addSerializer(Long.class, ToStringSerializer.instance);
34   - objectMapper.registerModule(module);
35   - }
36   -
37   - /**
38   - * 将对象转换为 JSON 字符串
39   - *
40   - * @param obj 需要序列化的Java对象
41   - * @return 序列化后的 JSON 字符串
42   - * @throws JsonProcessingException 当 JSON 序列化过程中出现错误时抛出异常
43   - */
44   - public static String toJson(Object obj) {
45   - try {
46   - return objectMapper.writeValueAsString(obj);
47   - } catch (JsonProcessingException e) {
48   - throw new RuntimeException(e);
49   - }
50   - }
51   -
52   - /**
53   - * 将 JSON 字符串反序列化为指定类型的对象
54   - *
55   - * @param json JSON 字符串
56   - * @param clazz 目标类型 Class 对象
57   - * @param <T> 泛型类型参数
58   - * @return 反序列化后的 Java 对象
59   - * @throws IOException 当 JSON 解析过程中出现错误时抛出异常
60   - */
61   - public static <T> T fromJson(String json, Class<T> clazz) {
62   - try {
63   - return objectMapper.readValue(json, clazz);
64   - } catch (JsonProcessingException e) {
65   - throw new RuntimeException(e);
66   - }
67   - }
68   -
69   - /**
70   - * 将对象转换为格式化的 JSON 字符串(已启用 INDENT_OUTPUT 功能,所以所有方法都会返回格式化后的 JSON)
71   - *
72   - * @param obj 需要序列化的Java对象
73   - * @return 格式化后的 JSON 字符串
74   - * @throws JsonProcessingException 当 JSON 序列化过程中出现错误时抛出异常
75   - */
76   - public static String toFormattedJson(Object obj) {
77   - // 已在类初始化时设置了 SerializationFeature.INDENT_OUTPUT,此处无需额外操作
78   - return toJson(obj);
79   - }
80   -}
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/QianWenChatClientTests.java
1 1 package cn.iocoder.yudao.framework.ai.chat;
2 2  
3 3 import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt;
4   -import cn.iocoder.yudao.framework.ai.chatqianwen.QianWenApi;
  4 +import cn.iocoder.yudao.framework.ai.chatqianwen.api.QianWenApi;
5 5 import cn.iocoder.yudao.framework.ai.chatqianwen.QianWenChatClient;
6 6 import cn.iocoder.yudao.framework.ai.chatqianwen.QianWenOptions;
7   -import com.aliyun.broadscope.bailian.sdk.models.CompletionsRequest;
8 7 import org.junit.Before;
9 8 import org.junit.Test;
10 9 import reactor.core.publisher.Flux;
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/mj/MjInteractionsTests.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyInteractionsTests.java
1   -package cn.iocoder.yudao.framework.ai.mj;
  1 +package cn.iocoder.yudao.framework.ai.midjourney;
2 2  
3 3 import cn.hutool.core.io.FileUtil;
4   -import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
5   -import cn.iocoder.yudao.framework.ai.midjourney.interactions.MjInteractions;
  4 +import cn.iocoder.yudao.framework.ai.midjourney.interactions.MidjourneyInteractions;
6 5 import cn.iocoder.yudao.framework.ai.midjourney.vo.Attachments;
7 6 import cn.iocoder.yudao.framework.ai.midjourney.vo.Describe;
8 7 import cn.iocoder.yudao.framework.ai.midjourney.vo.ReRoll;
... ... @@ -23,7 +22,7 @@ import java.util.Map;
23 22 * author: fansili
24 23 * time: 2024/4/4 18:59
25 24 */
26   -public class MjInteractionsTests {
  25 +public class MidjourneyInteractionsTests {
27 26  
28 27 private MidjourneyConfig midjourneyConfig;
29 28 @Before
... ... @@ -39,14 +38,14 @@ public class MjInteractionsTests {
39 38  
40 39 @Test
41 40 public void mjImageTest() {
42   - MjInteractions mjImagineInteractions = new MjInteractions(midjourneyConfig);
  41 + MidjourneyInteractions mjImagineInteractions = new MidjourneyInteractions(midjourneyConfig);
43 42 mjImagineInteractions.imagine("童话里应该是什么样子?");
44 43 }
45 44  
46 45  
47 46 @Test
48 47 public void reRollTest() {
49   - MjInteractions mjImagineInteractions = new MjInteractions(midjourneyConfig);
  48 + MidjourneyInteractions mjImagineInteractions = new MidjourneyInteractions(midjourneyConfig);
50 49 mjImagineInteractions.reRoll(new ReRoll()
51 50 .setMessageId("1226165117448753243")
52 51 .setCustomId("MJ::JOB::upsample::3::2aeefbef-43e2-4057-bcf1-43b5f39ab6f7"));
... ... @@ -54,7 +53,7 @@ public class MjInteractionsTests {
54 53  
55 54 @Test
56 55 public void uploadAttachmentsTest() {
57   - MjInteractions mjImagineInteractions = new MjInteractions(midjourneyConfig);
  56 + MidjourneyInteractions mjImagineInteractions = new MidjourneyInteractions(midjourneyConfig);
58 57 UploadAttachmentsRes res = mjImagineInteractions.uploadAttachments(
59 58 new Attachments().setFileSystemResource(
60 59 new FileSystemResource(new File("/Users/fansili/Downloads/DSC01402.JPG")))
... ... @@ -64,7 +63,7 @@ public class MjInteractionsTests {
64 63  
65 64 @Test
66 65 public void describeTest() {
67   - MjInteractions mjImagineInteractions = new MjInteractions(midjourneyConfig);
  66 + MidjourneyInteractions mjImagineInteractions = new MidjourneyInteractions(midjourneyConfig);
68 67 mjImagineInteractions.describe(new Describe()
69 68 .setFileName("DSC01402.JPG")
70 69 .setFinalFileName("16826931-2873-45ec-8cfb-0ad81f1a075f/DSC01402.JPG")
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/mj/MjUtilTests.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyUtilTests.java
1   -package cn.iocoder.yudao.framework.ai.mj;
  1 +package cn.iocoder.yudao.framework.ai.midjourney;
2 2  
3   -import cn.iocoder.yudao.framework.ai.midjourney.util.MjUtil;
  3 +import cn.iocoder.yudao.framework.ai.midjourney.util.MidjourneyUtil;
4 4 import org.junit.Test;
5 5  
6 6 /**
... ... @@ -9,14 +9,14 @@ import org.junit.Test;
9 9 * author: fansili
10 10 * time: 2024/4/6 21:57
11 11 */
12   -public class MjUtilTests {
  12 +public class MidjourneyUtilTests {
13 13  
14 14 @Test
15 15 public void parseContentTest() {
16 16 String content1 = "**南极应该是什么样子? --v 6.0 --style raw** - <@972721304891453450> (32%) (fast, stealth)";
17 17 String content2 = "**南极应该是什么样子? --v 6.0 --style raw** - <@972721304891453450> (fast, stealth)";
18 18  
19   - System.err.println(MjUtil.parseContent(content1));
20   - System.err.println(MjUtil.parseContent(content2));
  19 + System.err.println(MidjourneyUtil.parseContent(content1));
  20 + System.err.println(MidjourneyUtil.parseContent(content2));
21 21 }
22 22 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/mj/MjWebSocketTests.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyWebSocketTests.java
1   -package cn.iocoder.yudao.framework.ai.mj;
  1 +package cn.iocoder.yudao.framework.ai.midjourney;
2 2  
3 3 import cn.hutool.core.io.FileUtil;
4   -import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig;
5   -import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MjMessageListener;
6   -import cn.iocoder.yudao.framework.ai.midjourney.webSocket.MjWebSocketStarter;
  4 +import cn.iocoder.yudao.framework.ai.midjourney.webSocket.listener.MidjourneyMessageListener;
  5 +import cn.iocoder.yudao.framework.ai.midjourney.webSocket.MidjourneyWebSocketStarter;
7 6 import org.junit.Before;
8 7 import org.junit.Test;
9 8  
... ... @@ -17,7 +16,7 @@ import java.util.Scanner;
17 16 * author: fansili
18 17 * time: 2024/4/3 16:40
19 18 */
20   -public class MjWebSocketTests {
  19 +public class MidjourneyWebSocketTests {
21 20  
22 21 private MidjourneyConfig midjourneyConfig;
23 22  
... ... @@ -35,8 +34,8 @@ public class MjWebSocketTests {
35 34 @Test
36 35 public void startSocketTest() {
37 36 String wssUrl = "wss://gateway.discord.gg";
38   - var messageListener = new MjMessageListener(midjourneyConfig);
39   - var webSocketStarter = new MjWebSocketStarter(wssUrl, null, midjourneyConfig, messageListener);
  37 + var messageListener = new MidjourneyMessageListener(midjourneyConfig);
  38 + var webSocketStarter = new MidjourneyWebSocketStarter(wssUrl, null, midjourneyConfig, messageListener);
40 39  
41 40 try {
42 41 webSocketStarter.start();
... ...