Commit 20addff45edc33ea44d2ca013c666cca80027603
1 parent
b9d823f0
【增加】Midjourney client,增加 imagine 方法
Showing
3 changed files
with
99 additions
and
0 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.client; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO; | |
| 4 | +import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.beans.factory.annotation.Value; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | +import org.springframework.validation.annotation.Validated; | |
| 10 | +import org.springframework.web.client.RestTemplate; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Midjourney Proxy 客户端 | |
| 14 | + * | |
| 15 | + * @author fansili | |
| 16 | + * @time 2024/5/30 13:58 | |
| 17 | + * @since 1.0 | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class MidjourneyProxyClient { | |
| 21 | + | |
| 22 | + private static final String URI_IMAGINE = "/submit/imagine"; | |
| 23 | + | |
| 24 | + @Value("${ai.midjourney-proxy.url:http://127.0.0.1:8080/mj}") | |
| 25 | + private String url; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private RestTemplate restTemplate; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * imagine - 根据提示词提交绘画任务 | |
| 32 | + * | |
| 33 | + * @param imagineReqVO | |
| 34 | + * @return | |
| 35 | + */ | |
| 36 | + public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) { | |
| 37 | + return restTemplate.postForObject(url.concat(URI_IMAGINE), imagineReqVO, MidjourneySubmitRespVO.class); | |
| 38 | + } | |
| 39 | + | |
| 40 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyImagineReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.client.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Midjourney:Imagine 请求 | |
| 11 | + * | |
| 12 | + * @author fansili | |
| 13 | + * @time 2024/5/30 14:02 | |
| 14 | + * @since 1.0 | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +public class MidjourneyImagineReqVO { | |
| 18 | + | |
| 19 | + @Schema(description = "垫图(参考图)base64数组", required = false) | |
| 20 | + private List<String> base64Array; | |
| 21 | + | |
| 22 | + @Schema(description = "通知地址", required = false) | |
| 23 | + @NotNull(message = "回调地址不能为空!") | |
| 24 | + private String notifyHook; | |
| 25 | + | |
| 26 | + @Schema(description = "提示词", required = true) | |
| 27 | + @NotNull(message = "提示词不能为空!") | |
| 28 | + private String prompt; | |
| 29 | + | |
| 30 | + @Schema(description = "自定义参数", required = false) | |
| 31 | + private String state; | |
| 32 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneySubmitRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.client.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Midjourney:Imagine 请求 | |
| 8 | + * | |
| 9 | + * @author fansili | |
| 10 | + * @time 2024/5/30 14:02 | |
| 11 | + * @since 1.0 | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +public class MidjourneySubmitRespVO { | |
| 15 | + | |
| 16 | + @Schema(description = "状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)") | |
| 17 | + private String code; | |
| 18 | + | |
| 19 | + @Schema(description = "描述") | |
| 20 | + private String description; | |
| 21 | + | |
| 22 | + @Schema(description = "扩展字段") | |
| 23 | + private String properties; | |
| 24 | + | |
| 25 | + @Schema(description = "任务ID") | |
| 26 | + private String result; | |
| 27 | +} | ... | ... |