Commit 072b3d6fa4574eb1ec60e0f2de9d191b8bff8b8b

Authored by YunaiV
1 parent 814a9633

feat(ai):补充说明下,wan2.7-image 要注意,等 alibaba ai 兼容!!!

yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
... ... @@ -109,6 +109,7 @@ public class AiImageServiceImpl implements AiImageService {
109 109 }
110 110  
111 111 @Async
  112 + @SuppressWarnings("ConstantValue")
112 113 public void executeDrawImage(AiImageDO image, AiImageDrawReqVO reqVO, AiModelDO model) {
113 114 try {
114 115 // 1.1 构建请求
... ... @@ -164,8 +165,8 @@ public class AiImageServiceImpl implements AiImageService {
164 165 .build();
165 166 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.TONG_YI.getPlatform())) {
166 167 return DashScopeImageOptions.builder()
167   - .withModel(model.getModel()).withN(1)
168   - .withHeight(draw.getHeight()).withWidth(draw.getWidth())
  168 + .model(model.getModel()).n(1)
  169 + .height(draw.getHeight()).width(draw.getWidth())
169 170 .build();
170 171 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.YI_YAN.getPlatform())) {
171 172 return QianFanImageOptions.builder()
... ...
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/image/TongYiImagesModelTest.java
... ... @@ -12,23 +12,34 @@ import org.springframework.ai.image.ImageResponse;
12 12 /**
13 13 * {@link DashScopeImageModel} 集成测试类
14 14 *
  15 + * TODO @芋艿:注:spring-ai-alibaba-dashscope(1.1.2.2)的 {@code DashScopeImageApi#resolveImagePath} 未给 {@code wan2.7-image} 加路由分支,
  16 + * 会落到默认的 {@code text2image/image-synthesis} 异步端点 + 旧版 {@code prompt} 入参,
  17 + * 而该模型实际要求 {@code multimodal-generation/generation} 同步端点 + {@code messages} 入参,
  18 + * 端点、异步头、入参结构全部对不上,所以走 SDK 直接调用必失败。
  19 + *
  20 + * 临时方案:改用 SDK 已支持的 {@code wan2.6-image}(异步)或 {@code qwen-image}(同步);
  21 + * 或在项目内同包同名覆盖 {@code DashScopeImageApi},把 {@code wan2.7*} 也路由到 {@code wan2.6-image} 那条 {@code image-generation/generation} 异步分支。
  22 + *
15 23 * @author fansili
16 24 */
17 25 public class TongYiImagesModelTest {
18 26  
19 27 private final DashScopeImageModel imageModel = DashScopeImageModel.builder()
20 28 .dashScopeApi(DashScopeImageApi.builder()
21   - .apiKey("sk-47aa124781be4bfb95244cc62f63f7d0")
  29 + .apiKey("sk-cd9f39e99ea54840bd1888282325f55a") // https://bailian.console.aliyun.com/cn-beijing/?tab=model#/api-key 获取密钥
22 30 .build())
23 31 .build();
24 32  
  33 + // TODO @芋艿:
25 34 @Test
26 35 @Disabled
27 36 public void imageCallTest() {
28 37 // 准备参数
29 38 ImageOptions options = DashScopeImageOptions.builder()
30   - .withModel("wanx-v1")
31   - .withHeight(256).withWidth(256)
  39 + .model("wan2.7-image")
  40 +// .withSize("2k")
  41 + .height(768).width(768)
  42 + .n(1)
32 43 .build();
33 44 ImagePrompt prompt = new ImagePrompt("中国长城!", options);
34 45  
... ...