Commit 6b7238a79d9d01987c315935b59461b2df67f7bb
1 parent
e39a6c34
【增加】百度千帆 image tests
Showing
1 changed file
with
47 additions
and
0 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/QianFanImageTests.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.ai.image; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.ai.image.ImageOptionsBuilder; | |
| 6 | +import org.springframework.ai.image.ImagePrompt; | |
| 7 | +import org.springframework.ai.image.ImageResponse; | |
| 8 | +import org.springframework.ai.qianfan.QianFanImageModel; | |
| 9 | +import org.springframework.ai.qianfan.QianFanImageOptions; | |
| 10 | +import org.springframework.ai.qianfan.api.QianFanApi; | |
| 11 | +import org.springframework.ai.qianfan.api.QianFanImageApi; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 百度千帆 image | |
| 15 | + */ | |
| 16 | +public class QianFanImageTests { | |
| 17 | + | |
| 18 | + @Test | |
| 19 | + public void callTest() { | |
| 20 | + QianFanImageApi qianFanImageApi = new QianFanImageApi( | |
| 21 | + "ghbbvbW2t7HK7WtYmEITAupm", "njJEr5AsQ5fkB3ucYYDjiQqsOZK20SGb"); | |
| 22 | + QianFanImageModel qianFanImageModel = new QianFanImageModel(qianFanImageApi); | |
| 23 | + | |
| 24 | + QianFanImageOptions imageOptions = QianFanImageOptions.builder() | |
| 25 | + .withWidth(512) | |
| 26 | + .withHeight(512) | |
| 27 | + .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); | |
| 45 | + } | |
| 46 | + | |
| 47 | +} | ... | ... |