Commit 3e1641216a31290e3c5734a321d3740eb103f5f7
1 parent
8f68d64c
【解决todo】mj 增加 base64 参考图
Showing
2 changed files
with
10 additions
and
5 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java
| @@ -31,8 +31,7 @@ public class AiMidjourneyImagineReqVO { | @@ -31,8 +31,7 @@ public class AiMidjourneyImagineReqVO { | ||
| 31 | @NotEmpty(message = "版本号不能为空") | 31 | @NotEmpty(message = "版本号不能为空") |
| 32 | private String version; | 32 | private String version; |
| 33 | 33 | ||
| 34 | - // TODO @fan:参考图,建议用 referImageUrl。 | ||
| 35 | - @Schema(description = "垫图(参考图)base64数组") | ||
| 36 | - private List<String> base64Array; | 34 | + @Schema(description = "参考图") |
| 35 | + private String referImageUrl; | ||
| 37 | 36 | ||
| 38 | } | 37 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| @@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async; | @@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async; | ||
| 35 | import org.springframework.stereotype.Service; | 35 | import org.springframework.stereotype.Service; |
| 36 | import org.springframework.transaction.annotation.Transactional; | 36 | import org.springframework.transaction.annotation.Transactional; |
| 37 | 37 | ||
| 38 | +import java.util.ArrayList; | ||
| 38 | import java.util.Collections; | 39 | import java.util.Collections; |
| 39 | import java.util.List; | 40 | import java.util.List; |
| 40 | import java.util.Map; | 41 | import java.util.Map; |
| @@ -191,9 +192,14 @@ public class AiImageServiceImpl implements AiImageService { | @@ -191,9 +192,14 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 191 | imageMapper.insert(image); | 192 | imageMapper.insert(image); |
| 192 | 193 | ||
| 193 | // 2. 调用 Midjourney Proxy 提交任务 | 194 | // 2. 调用 Midjourney Proxy 提交任务 |
| 195 | + List<String> base64Array = new ArrayList<>(8); | ||
| 196 | + if (StrUtil.isNotBlank(reqVO.getReferImageUrl())) { | ||
| 197 | + base64Array.add("data:image/jpeg;base64,".concat(Base64.encode(HttpUtil.downloadBytes(reqVO.getReferImageUrl())))); | ||
| 198 | + } | ||
| 194 | MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest( | 199 | MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest( |
| 195 | - null, reqVO.getPrompt(),null, | ||
| 196 | - MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(), reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel())); | 200 | + base64Array, reqVO.getPrompt(),null, |
| 201 | + MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(), | ||
| 202 | + reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel())); | ||
| 197 | MidjourneyApi.SubmitResponse imagineResponse = midjourneyApi.imagine(imagineRequest); | 203 | MidjourneyApi.SubmitResponse imagineResponse = midjourneyApi.imagine(imagineRequest); |
| 198 | 204 | ||
| 199 | // 3. 情况一【失败】:抛出业务异常 | 205 | // 3. 情况一【失败】:抛出业务异常 |