mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
【增加】MidjourneyProxy 增加 action 操作
This commit is contained in:
parent
4c20593211
commit
79a094be02
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.ai.client;
|
||||
|
||||
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.MidjourneySubmitRespVO;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@ -23,9 +24,12 @@ import org.springframework.web.client.RestTemplate;
|
||||
public class MidjourneyProxyClient {
|
||||
|
||||
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}")
|
||||
private String url;
|
||||
@Value("${ai.midjourney-proxy.key}")
|
||||
private String key;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@ -37,15 +41,32 @@ public class MidjourneyProxyClient {
|
||||
* @return
|
||||
*/
|
||||
public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) {
|
||||
// 创建 HttpHeaders 对象
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
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);
|
||||
// 1、发送 post 请求
|
||||
ResponseEntity<String> response = post(URI_IMAGINE, imagineReqVO);
|
||||
// 2、转换 resp
|
||||
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