Commit 79a094be02072c0a0f650d5162f2bcb55593ac31
1 parent
4c205932
【增加】MidjourneyProxy 增加 action 操作
Showing
2 changed files
with
62 additions
and
8 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.client; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | +import cn.iocoder.yudao.module.ai.client.vo.MidjourneyActionReqVO; | |
| 4 | 5 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO; |
| 6 | 7 | import jakarta.validation.constraints.NotNull; |
| ... | ... | @@ -23,9 +24,12 @@ import org.springframework.web.client.RestTemplate; |
| 23 | 24 | public class MidjourneyProxyClient { |
| 24 | 25 | |
| 25 | 26 | private static final String URI_IMAGINE = "/submit/imagine"; |
| 27 | + private static final String URI_ACTON = "/submit/action"; | |
| 26 | 28 | |
| 27 | 29 | @Value("${ai.midjourney-proxy.url:http://127.0.0.1:8080/mj}") |
| 28 | 30 | private String url; |
| 31 | + @Value("${ai.midjourney-proxy.key}") | |
| 32 | + private String key; | |
| 29 | 33 | |
| 30 | 34 | @Autowired |
| 31 | 35 | private RestTemplate restTemplate; |
| ... | ... | @@ -37,15 +41,32 @@ public class MidjourneyProxyClient { |
| 37 | 41 | * @return |
| 38 | 42 | */ |
| 39 | 43 | public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) { |
| 40 | - // 创建 HttpHeaders 对象 | |
| 41 | - HttpHeaders headers = new HttpHeaders(); | |
| 42 | - headers.setContentType(MediaType.APPLICATION_JSON); | |
| 43 | - headers.set("Authorization", "Bearer sk-c3qxUCVKsPfdQiYU8440E3Fc8dE5424d9cB124A4Ee2489E3"); | |
| 44 | - // 创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它 | |
| 45 | - HttpEntity<String> requestEntity = new HttpEntity<>(JsonUtils.toJsonString(imagineReqVO), headers); | |
| 46 | - // 发送 post 请求 | |
| 47 | - ResponseEntity<String> response = restTemplate.exchange(url.concat(URI_IMAGINE), HttpMethod.POST, requestEntity, String.class); | |
| 44 | + // 1、发送 post 请求 | |
| 45 | + ResponseEntity<String> response = post(URI_IMAGINE, imagineReqVO); | |
| 46 | + // 2、转换 resp | |
| 48 | 47 | return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class); |
| 49 | 48 | } |
| 50 | 49 | |
| 50 | + /** | |
| 51 | + * action - 放大、缩小、U1、U2... | |
| 52 | + * | |
| 53 | + * @param actionReqVO | |
| 54 | + */ | |
| 55 | + public MidjourneySubmitRespVO action(@Validated @NotNull MidjourneyActionReqVO actionReqVO) { | |
| 56 | + // 1、发送 post 请求 | |
| 57 | + ResponseEntity<String> response = post(URI_ACTON, actionReqVO); | |
| 58 | + // 2、转换 resp | |
| 59 | + return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class); | |
| 60 | + } | |
| 61 | + | |
| 62 | + private ResponseEntity<String> post(String uri, Object body) { | |
| 63 | + // 1、创建 HttpHeaders 对象 | |
| 64 | + HttpHeaders headers = new HttpHeaders(); | |
| 65 | + headers.setContentType(MediaType.APPLICATION_JSON); | |
| 66 | + headers.set("Authorization", "Bearer ".concat(key)); | |
| 67 | + // 2、创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它 | |
| 68 | + HttpEntity<String> requestEntity = new HttpEntity<>(JsonUtils.toJsonString(body), headers); | |
| 69 | + // 3、发送 post 请求 | |
| 70 | + return restTemplate.exchange(url.concat(uri), HttpMethod.POST, requestEntity, String.class); | |
| 71 | + } | |
| 51 | 72 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyActionReqVO.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:action 请求 | |
| 11 | + * | |
| 12 | + * @author fansili | |
| 13 | + * @time 2024/5/30 14:02 | |
| 14 | + * @since 1.0 | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +public class MidjourneyActionReqVO { | |
| 18 | + | |
| 19 | + @Schema(description = "操作按钮id", required = true) | |
| 20 | + @NotNull(message = "customId 不能为空!") | |
| 21 | + private String customId; | |
| 22 | + | |
| 23 | + @Schema(description = "操作按钮id", required = true) | |
| 24 | + @NotNull(message = "customId 不能为空!") | |
| 25 | + private String taskId; | |
| 26 | + | |
| 27 | + @Schema(description = "通知地址", required = false) | |
| 28 | + @NotNull(message = "回调地址不能为空!") | |
| 29 | + private String notifyHook; | |
| 30 | + | |
| 31 | + @Schema(description = "自定义参数", required = false) | |
| 32 | + private String state; | |
| 33 | +} | ... | ... |