【增加】MidjourneyProxy 增加 action 操作

This commit is contained in:
cherishsince 2024-06-05 10:27:08 +08:00
parent 4c20593211
commit 79a094be02
2 changed files with 62 additions and 8 deletions

View File

@ -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 - 放大缩小U1U2...
*
* @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);
}
}

View File

@ -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;
/**
* Midjourneyaction 请求
*
* @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;
}