【增加】Midjourney client,增加 imagine 方法

This commit is contained in:
cherishsince 2024-05-30 14:21:13 +08:00
parent b9d823f0ed
commit 20addff45e
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.ai.client;
import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO;
import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.client.RestTemplate;
/**
* Midjourney Proxy 客户端
*
* @author fansili
* @time 2024/5/30 13:58
* @since 1.0
*/
@Component
public class MidjourneyProxyClient {
private static final String URI_IMAGINE = "/submit/imagine";
@Value("${ai.midjourney-proxy.url:http://127.0.0.1:8080/mj}")
private String url;
@Autowired
private RestTemplate restTemplate;
/**
* imagine - 根据提示词提交绘画任务
*
* @param imagineReqVO
* @return
*/
public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) {
return restTemplate.postForObject(url.concat(URI_IMAGINE), imagineReqVO, MidjourneySubmitRespVO.class);
}
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.ai.client.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
/**
* MidjourneyImagine 请求
*
* @author fansili
* @time 2024/5/30 14:02
* @since 1.0
*/
@Data
public class MidjourneyImagineReqVO {
@Schema(description = "垫图(参考图)base64数组", required = false)
private List<String> base64Array;
@Schema(description = "通知地址", required = false)
@NotNull(message = "回调地址不能为空!")
private String notifyHook;
@Schema(description = "提示词", required = true)
@NotNull(message = "提示词不能为空!")
private String prompt;
@Schema(description = "自定义参数", required = false)
private String state;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.ai.client.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* MidjourneyImagine 请求
*
* @author fansili
* @time 2024/5/30 14:02
* @since 1.0
*/
@Data
public class MidjourneySubmitRespVO {
@Schema(description = "状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)")
private String code;
@Schema(description = "描述")
private String description;
@Schema(description = "扩展字段")
private String properties;
@Schema(description = "任务ID")
private String result;
}