【解决todo】mj 增加 base64 参考图

This commit is contained in:
cherishsince 2024-07-02 23:02:24 +08:00
parent 8f68d64cd7
commit 3e1641216a
2 changed files with 10 additions and 5 deletions

View File

@ -31,8 +31,7 @@ public class AiMidjourneyImagineReqVO {
@NotEmpty(message = "版本号不能为空") @NotEmpty(message = "版本号不能为空")
private String version; private String version;
// TODO @fan参考图建议用 referImageUrl @Schema(description = "参考图")
@Schema(description = "垫图(参考图)base64数组") private String referImageUrl;
private List<String> base64Array;
} }

View File

@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -191,9 +192,14 @@ public class AiImageServiceImpl implements AiImageService {
imageMapper.insert(image); imageMapper.insert(image);
// 2. 调用 Midjourney Proxy 提交任务 // 2. 调用 Midjourney Proxy 提交任务
List<String> base64Array = new ArrayList<>(8);
if (StrUtil.isNotBlank(reqVO.getReferImageUrl())) {
base64Array.add("data:image/jpeg;base64,".concat(Base64.encode(HttpUtil.downloadBytes(reqVO.getReferImageUrl()))));
}
MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest( MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest(
null, reqVO.getPrompt(),null, base64Array, reqVO.getPrompt(),null,
MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(), reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel())); MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(),
reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel()));
MidjourneyApi.SubmitResponse imagineResponse = midjourneyApi.imagine(imagineRequest); MidjourneyApi.SubmitResponse imagineResponse = midjourneyApi.imagine(imagineRequest);
// 3. 情况一失败抛出业务异常 // 3. 情况一失败抛出业务异常