mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-02 03:34:58 +08:00
【增加】MidjourneyProxy 增加 action 操作
This commit is contained in:
parent
4c20593211
commit
79a094be02
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.ai.client;
|
package cn.iocoder.yudao.module.ai.client;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
|
import cn.iocoder.yudao.module.ai.client.vo.MidjourneyActionReqVO;
|
||||||
import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO;
|
import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO;
|
||||||
import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO;
|
import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@ -23,9 +24,12 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
public class MidjourneyProxyClient {
|
public class MidjourneyProxyClient {
|
||||||
|
|
||||||
private static final String URI_IMAGINE = "/submit/imagine";
|
private static final String URI_IMAGINE = "/submit/imagine";
|
||||||
|
private static final String URI_ACTON = "/submit/action";
|
||||||
|
|
||||||
@Value("${ai.midjourney-proxy.url:http://127.0.0.1:8080/mj}")
|
@Value("${ai.midjourney-proxy.url:http://127.0.0.1:8080/mj}")
|
||||||
private String url;
|
private String url;
|
||||||
|
@Value("${ai.midjourney-proxy.key}")
|
||||||
|
private String key;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestTemplate restTemplate;
|
private RestTemplate restTemplate;
|
||||||
@ -37,15 +41,32 @@ public class MidjourneyProxyClient {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) {
|
public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) {
|
||||||
// 创建 HttpHeaders 对象
|
// 1、发送 post 请求
|
||||||
HttpHeaders headers = new HttpHeaders();
|
ResponseEntity<String> response = post(URI_IMAGINE, imagineReqVO);
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
// 2、转换 resp
|
||||||
headers.set("Authorization", "Bearer sk-c3qxUCVKsPfdQiYU8440E3Fc8dE5424d9cB124A4Ee2489E3");
|
|
||||||
// 创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它
|
|
||||||
HttpEntity<String> requestEntity = new HttpEntity<>(JsonUtils.toJsonString(imagineReqVO), headers);
|
|
||||||
// 发送 post 请求
|
|
||||||
ResponseEntity<String> response = restTemplate.exchange(url.concat(URI_IMAGINE), HttpMethod.POST, requestEntity, String.class);
|
|
||||||
return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class);
|
return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* action - 放大、缩小、U1、U2...
|
||||||
|
*
|
||||||
|
* @param actionReqVO
|
||||||
|
*/
|
||||||
|
public MidjourneySubmitRespVO action(@Validated @NotNull MidjourneyActionReqVO actionReqVO) {
|
||||||
|
// 1、发送 post 请求
|
||||||
|
ResponseEntity<String> response = post(URI_ACTON, actionReqVO);
|
||||||
|
// 2、转换 resp
|
||||||
|
return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseEntity<String> post(String uri, Object body) {
|
||||||
|
// 1、创建 HttpHeaders 对象
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("Authorization", "Bearer ".concat(key));
|
||||||
|
// 2、创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(JsonUtils.toJsonString(body), headers);
|
||||||
|
// 3、发送 post 请求
|
||||||
|
return restTemplate.exchange(url.concat(uri), HttpMethod.POST, requestEntity, String.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Midjourney:action 请求
|
||||||
|
*
|
||||||
|
* @author fansili
|
||||||
|
* @time 2024/5/30 14:02
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MidjourneyActionReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "操作按钮id", required = true)
|
||||||
|
@NotNull(message = "customId 不能为空!")
|
||||||
|
private String customId;
|
||||||
|
|
||||||
|
@Schema(description = "操作按钮id", required = true)
|
||||||
|
@NotNull(message = "customId 不能为空!")
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
@Schema(description = "通知地址", required = false)
|
||||||
|
@NotNull(message = "回调地址不能为空!")
|
||||||
|
private String notifyHook;
|
||||||
|
|
||||||
|
@Schema(description = "自定义参数", required = false)
|
||||||
|
private String state;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user