Commit 870b1bf3695cddd9abfe1f28d2f396fa5e3b0835

Authored by cherishsince
1 parent ae69b137

【增加】增加通义万象 test

yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/TongYiImagesModelTests.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.ai.image;
  2 +
  3 +import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
  4 +import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
  5 +import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
  6 +import com.alibaba.dashscope.exception.NoApiKeyException;
  7 +import com.alibaba.dashscope.utils.Constants;
  8 +import com.alibaba.fastjson.JSON;
  9 +import org.junit.jupiter.api.Test;
  10 +
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 通义万象 - 测试
  15 + */
  16 +public class TongYiImagesModelTests {
  17 +
  18 + @Test
  19 + public void imageCallTest() throws NoApiKeyException {
  20 + // 设置 api key
  21 + Constants.apiKey="sk-Zsd81gZYg7";
  22 + ImageSynthesisParam param =
  23 + ImageSynthesisParam.builder()
  24 + .model(ImageSynthesis.Models.WANX_V1)
  25 + .n(4)
  26 + .size("1024*1024")
  27 + .prompt("雄鹰自由自在的在蓝天白云下飞翔")
  28 + .build();
  29 + // 创建 ImageSynthesis
  30 + ImageSynthesis is = new ImageSynthesis();
  31 + // 调用 call 生成 image
  32 + ImageSynthesisResult call = is.call(param);
  33 + System.err.println(JSON.toJSON(call));
  34 + for (Map<String, String> result : call.getOutput().getResults()) {
  35 + System.err.println("地址: " + result.get("url"));
  36 + }
  37 + }
  38 +}