2026-06-30 24681c81c09022f584a57006f2534b5f74723414
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cn.iocoder.yudao.module.ai.framework.ai.core.model.image;
 
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.image.ImageOptions;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.OpenAiImageOptions;
 
/**
 * {@link OpenAiImageModel} 集成测试类
 *
 * @author fansili
 */
public class OpenAiImageModelTests {
 
    private final OpenAiImageModel imageModel = OpenAiImageModel.builder()
            .options(OpenAiImageOptions.builder()
                    .baseUrl("https://api.holdai.top") // apiKey
                    .apiKey("sk-xxx")
                    .build())
            .build();
 
    @Test
    @Disabled
    public void testCall() {
        // 准备参数
        ImageOptions options = OpenAiImageOptions.builder()
                .model("dall-e-2") // 这个模型比较便宜
                .height(256).width(256)
                .build();
        ImagePrompt prompt = new ImagePrompt("中国长城!", options);
 
        // 方法调用
        ImageResponse response = imageModel.call(prompt);
        // 打印结果
        System.out.println(response);
    }
 
}