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,6 +109,7 @@ public class AiImageServiceImpl implements AiImageService {
109 } 109 }
110 110
111 @Async 111 @Async
  112 + @SuppressWarnings("ConstantValue")
112 public void executeDrawImage(AiImageDO image, AiImageDrawReqVO reqVO, AiModelDO model) { 113 public void executeDrawImage(AiImageDO image, AiImageDrawReqVO reqVO, AiModelDO model) {
113 try { 114 try {
114 // 1.1 构建请求 115 // 1.1 构建请求
@@ -164,8 +165,8 @@ public class AiImageServiceImpl implements AiImageService { @@ -164,8 +165,8 @@ public class AiImageServiceImpl implements AiImageService {
164 .build(); 165 .build();
165 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.TONG_YI.getPlatform())) { 166 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.TONG_YI.getPlatform())) {
166 return DashScopeImageOptions.builder() 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 .build(); 170 .build();
170 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.YI_YAN.getPlatform())) { 171 } else if (ObjUtil.equal(model.getPlatform(), AiPlatformEnum.YI_YAN.getPlatform())) {
171 return QianFanImageOptions.builder() 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,23 +12,34 @@ import org.springframework.ai.image.ImageResponse;
12 /** 12 /**
13 * {@link DashScopeImageModel} 集成测试类 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 * @author fansili 23 * @author fansili
16 */ 24 */
17 public class TongYiImagesModelTest { 25 public class TongYiImagesModelTest {
18 26
19 private final DashScopeImageModel imageModel = DashScopeImageModel.builder() 27 private final DashScopeImageModel imageModel = DashScopeImageModel.builder()
20 .dashScopeApi(DashScopeImageApi.builder() 28 .dashScopeApi(DashScopeImageApi.builder()
21 - .apiKey("sk-47aa124781be4bfb95244cc62f63f7d0") 29 + .apiKey("sk-cd9f39e99ea54840bd1888282325f55a") // https://bailian.console.aliyun.com/cn-beijing/?tab=model#/api-key 获取密钥
22 .build()) 30 .build())
23 .build(); 31 .build();
24 32
  33 + // TODO @芋艿:
25 @Test 34 @Test
26 @Disabled 35 @Disabled
27 public void imageCallTest() { 36 public void imageCallTest() {
28 // 准备参数 37 // 准备参数
29 ImageOptions options = DashScopeImageOptions.builder() 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 .build(); 43 .build();
33 ImagePrompt prompt = new ImagePrompt("中国长城!", options); 44 ImagePrompt prompt = new ImagePrompt("中国长城!", options);
34 45