Commit 698b2b24aeee15dc27d7eea058cce7e968471608

Authored by YunaiV
1 parent abc51c67

【代码优化】AI:文心一言的 tests 类

yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java
1 1 package cn.iocoder.yudao.framework.ai.image;
2 2  
3   -import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  3 +import org.junit.jupiter.api.Disabled;
4 4 import org.junit.jupiter.api.Test;
5   -import org.springframework.ai.image.ImageOptionsBuilder;
6 5 import org.springframework.ai.image.ImagePrompt;
7 6 import org.springframework.ai.image.ImageResponse;
8 7 import org.springframework.ai.qianfan.QianFanImageModel;
9 8 import org.springframework.ai.qianfan.QianFanImageOptions;
10 9 import org.springframework.ai.qianfan.api.QianFanImageApi;
11 10  
  11 +import static cn.iocoder.yudao.framework.ai.image.StabilityAiImageModelTests.viewImage;
  12 +
12 13 /**
13   - * 百度千帆 image
  14 + * {@link QianFanImageModel} 集成测试类
14 15 */
15 16 public class QianFanImageTests {
16 17  
17   - @Test
18   - public void callTest() {
19   - // todo @芋艿 千帆sdk有个错误,暂时没找到问题
20   - QianFanImageApi qianFanImageApi = new QianFanImageApi(
21   - "qS8k8dYr2nXunagK4SSU8Xjj", "pHGbx51ql2f0hOyabQvSZezahVC3hh3e");
22   - QianFanImageModel qianFanImageModel = new QianFanImageModel(qianFanImageApi);
  18 + private final QianFanImageApi imageApi = new QianFanImageApi(
  19 + "qS8k8dYr2nXunagK4SSU8Xjj", "pHGbx51ql2f0hOyabQvSZezahVC3hh3e");
  20 + private final QianFanImageModel imageModel = new QianFanImageModel(imageApi);
23 21  
  22 + @Test
  23 + @Disabled
  24 + public void testCall() {
  25 + // 准备参数
  26 + // 只支持 1024x1024、768x768、768x1024、1024x768、576x1024、1024x576
24 27 QianFanImageOptions imageOptions = QianFanImageOptions.builder()
25   - .withWidth(512)
26   - .withHeight(512)
  28 + .withModel(QianFanImageApi.ImageModel.Stable_Diffusion_XL.getValue())
  29 + .withWidth(1024).withHeight(1024)
  30 + .withN(1)
27 31 .build();
28   - ImagePrompt imagePrompt = new ImagePrompt("薄涂炫酷少女头像,田野花朵盛开", imageOptions);
29   - ImageResponse call = qianFanImageModel.call(imagePrompt);
30   - System.err.println(JsonUtils.toJsonString(call));
31   - }
32   -
33   - @Test
34   - public void call2Test() {
35   - // 官方测试 test https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-qianfan/src/test/java/org/springframework/ai/qianfan/image/QianFanImageModelIT.java
36   - var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build();
37   - var instructions = "薄涂炫酷少女头像,田野花朵盛开";
38   -
39   - ImagePrompt imagePrompt = new ImagePrompt(instructions, options);
40   -
41   - QianFanImageApi qianFanImageApi = new QianFanImageApi(
42   - "ghbbvbW2t7HK7WtYmEITAupm", "njJEr5AsQ5fkB3ucYYDjiQqsOZK20SGb");
43   - QianFanImageModel imageModel = new QianFanImageModel(qianFanImageApi);
44   - ImageResponse imageResponse = imageModel.call(imagePrompt);
  32 + ImagePrompt prompt = new ImagePrompt("good", imageOptions);
  33 +
  34 + // 方法调用
  35 + ImageResponse response = imageModel.call(prompt);
  36 + // 打印结果
  37 + String b64Json = response.getResult().getOutput().getB64Json();
  38 + System.out.println(response);
  39 + viewImage(b64Json);
45 40 }
46 41  
47   -
48   -
49 42 }
... ...
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/TongYiImagesModelTest.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.image;
3 3 import com.alibaba.cloud.ai.tongyi.image.TongYiImagesModel;
4 4 import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
5 5 import com.alibaba.dashscope.utils.Constants;
  6 +import org.junit.jupiter.api.Disabled;
6 7 import org.junit.jupiter.api.Test;
7 8 import org.springframework.ai.image.ImageOptions;
8 9 import org.springframework.ai.image.ImagePrompt;
... ... @@ -24,6 +25,7 @@ public class TongYiImagesModelTest {
24 25 }
25 26  
26 27 @Test
  28 + @Disabled
27 29 public void imageCallTest() {
28 30 // 准备参数
29 31 ImageOptions options = OpenAiImageOptions.builder()
... ...