From 698b2b24aeee15dc27d7eea058cce7e968471608 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 11 Jul 2024 22:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91AI=EF=BC=9A=E6=96=87=E5=BF=83=E4=B8=80=E8=A8=80?= =?UTF-8?q?=E7=9A=84=20tests=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/ai/image/QianFanImageTests.java | 53 ++++++++----------- .../ai/image/TongYiImagesModelTest.java | 2 + 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java index 04312bcbd..22bf6614e 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java @@ -1,49 +1,42 @@ package cn.iocoder.yudao.framework.ai.image; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.springframework.ai.image.ImageOptionsBuilder; import org.springframework.ai.image.ImagePrompt; import org.springframework.ai.image.ImageResponse; import org.springframework.ai.qianfan.QianFanImageModel; import org.springframework.ai.qianfan.QianFanImageOptions; import org.springframework.ai.qianfan.api.QianFanImageApi; +import static cn.iocoder.yudao.framework.ai.image.StabilityAiImageModelTests.viewImage; + /** - * 百度千帆 image + * {@link QianFanImageModel} 集成测试类 */ public class QianFanImageTests { - @Test - public void callTest() { - // todo @芋艿 千帆sdk有个错误,暂时没找到问题 - QianFanImageApi qianFanImageApi = new QianFanImageApi( - "qS8k8dYr2nXunagK4SSU8Xjj", "pHGbx51ql2f0hOyabQvSZezahVC3hh3e"); - QianFanImageModel qianFanImageModel = new QianFanImageModel(qianFanImageApi); + private final QianFanImageApi imageApi = new QianFanImageApi( + "qS8k8dYr2nXunagK4SSU8Xjj", "pHGbx51ql2f0hOyabQvSZezahVC3hh3e"); + private final QianFanImageModel imageModel = new QianFanImageModel(imageApi); + @Test + @Disabled + public void testCall() { + // 准备参数 + // 只支持 1024x1024、768x768、768x1024、1024x768、576x1024、1024x576 QianFanImageOptions imageOptions = QianFanImageOptions.builder() - .withWidth(512) - .withHeight(512) + .withModel(QianFanImageApi.ImageModel.Stable_Diffusion_XL.getValue()) + .withWidth(1024).withHeight(1024) + .withN(1) .build(); - ImagePrompt imagePrompt = new ImagePrompt("薄涂炫酷少女头像,田野花朵盛开", imageOptions); - ImageResponse call = qianFanImageModel.call(imagePrompt); - System.err.println(JsonUtils.toJsonString(call)); + ImagePrompt prompt = new ImagePrompt("good", imageOptions); + + // 方法调用 + ImageResponse response = imageModel.call(prompt); + // 打印结果 + String b64Json = response.getResult().getOutput().getB64Json(); + System.out.println(response); + viewImage(b64Json); } - @Test - public void call2Test() { - // 官方测试 test https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-qianfan/src/test/java/org/springframework/ai/qianfan/image/QianFanImageModelIT.java - var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build(); - var instructions = "薄涂炫酷少女头像,田野花朵盛开"; - - ImagePrompt imagePrompt = new ImagePrompt(instructions, options); - - QianFanImageApi qianFanImageApi = new QianFanImageApi( - "ghbbvbW2t7HK7WtYmEITAupm", "njJEr5AsQ5fkB3ucYYDjiQqsOZK20SGb"); - QianFanImageModel imageModel = new QianFanImageModel(qianFanImageApi); - ImageResponse imageResponse = imageModel.call(imagePrompt); - } - - - } diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/TongYiImagesModelTest.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/TongYiImagesModelTest.java index 0ed736cde..41d7859c4 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/TongYiImagesModelTest.java +++ b/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; import com.alibaba.cloud.ai.tongyi.image.TongYiImagesModel; import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis; import com.alibaba.dashscope.utils.Constants; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.ai.image.ImageOptions; import org.springframework.ai.image.ImagePrompt; @@ -24,6 +25,7 @@ public class TongYiImagesModelTest { } @Test + @Disabled public void imageCallTest() { // 准备参数 ImageOptions options = OpenAiImageOptions.builder()