Commit dbe23cfe8ea14090daabf4edd3fd0d4d8faecf61
1 parent
3ab218ef
【优化】调试 mj proxy 通知回调
Showing
5 changed files
with
23 additions
and
6 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java
| 1 | package cn.iocoder.yudao.module.ai.client; | 1 | package cn.iocoder.yudao.module.ai.client; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 3 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO; | 4 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO; |
| 4 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO; | 5 | import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO; |
| 5 | import jakarta.validation.constraints.NotNull; | 6 | import jakarta.validation.constraints.NotNull; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.beans.factory.annotation.Value; | 8 | import org.springframework.beans.factory.annotation.Value; |
| 9 | +import org.springframework.http.*; | ||
| 8 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 9 | import org.springframework.validation.annotation.Validated; | 11 | import org.springframework.validation.annotation.Validated; |
| 10 | import org.springframework.web.client.RestTemplate; | 12 | import org.springframework.web.client.RestTemplate; |
| @@ -35,7 +37,15 @@ public class MidjourneyProxyClient { | @@ -35,7 +37,15 @@ public class MidjourneyProxyClient { | ||
| 35 | * @return | 37 | * @return |
| 36 | */ | 38 | */ |
| 37 | public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) { | 39 | public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) { |
| 38 | - return restTemplate.postForObject(url.concat(URI_IMAGINE), imagineReqVO, MidjourneySubmitRespVO.class); | 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); | ||
| 48 | + return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class); | ||
| 39 | } | 49 | } |
| 40 | 50 | ||
| 41 | } | 51 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java
| @@ -19,7 +19,7 @@ public class MidjourneyNotifyReqVO { | @@ -19,7 +19,7 @@ public class MidjourneyNotifyReqVO { | ||
| 19 | @Schema(description = "任务类型") | 19 | @Schema(description = "任务类型") |
| 20 | private MidjourneyTaskActionEnum action; | 20 | private MidjourneyTaskActionEnum action; |
| 21 | @Schema(description = "任务状态") | 21 | @Schema(description = "任务状态") |
| 22 | - private MidjourneyTaskStatusEnum status = MidjourneyTaskStatusEnum.NOT_START; | 22 | + private MidjourneyTaskStatusEnum status; |
| 23 | 23 | ||
| 24 | @Schema(description = "提示词") | 24 | @Schema(description = "提示词") |
| 25 | private String prompt; | 25 | private String prompt; |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| @@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation; | @@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation; | ||
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | import jakarta.annotation.Resource; | 17 | import jakarta.annotation.Resource; |
| 18 | +import jakarta.annotation.security.PermitAll; | ||
| 18 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 19 | import org.springframework.validation.annotation.Validated; | 20 | import org.springframework.validation.annotation.Validated; |
| 20 | import org.springframework.web.bind.annotation.*; | 21 | import org.springframework.web.bind.annotation.*; |
| @@ -70,10 +71,10 @@ public class AiImageController { | @@ -70,10 +71,10 @@ public class AiImageController { | ||
| 70 | return success(imageService.midjourneyImagine(getLoginUserId(), req)); | 71 | return success(imageService.midjourneyImagine(getLoginUserId(), req)); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | - // TODO @芋艿:不拦截 | ||
| 74 | @Operation(summary = "midjourney proxy - 回调通知") | 74 | @Operation(summary = "midjourney proxy - 回调通知") |
| 75 | - @RequestMapping("/midjourney-notify") | ||
| 76 | - public CommonResult<Boolean> midjourneyNotify(MidjourneyNotifyReqVO notifyReqVO) { | 75 | + @PostMapping("/midjourney-notify") |
| 76 | + @PermitAll | ||
| 77 | + public CommonResult<Boolean> midjourneyNotify( @RequestBody MidjourneyNotifyReqVO notifyReqVO) { | ||
| 77 | return success(imageService.midjourneyNotify(getLoginUserId(), notifyReqVO)); | 78 | return success(imageService.midjourneyNotify(getLoginUserId(), notifyReqVO)); |
| 78 | } | 79 | } |
| 79 | 80 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| @@ -212,7 +212,6 @@ public class AiImageServiceImpl implements AiImageService { | @@ -212,7 +212,6 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 212 | .setId(image.getId()) | 212 | .setId(image.getId()) |
| 213 | .setStatus(imageStatus) | 213 | .setStatus(imageStatus) |
| 214 | .setPicUrl(filePath) | 214 | .setPicUrl(filePath) |
| 215 | -// .setOriginalPicUrl(notifyReqVO.getImageUrl()) TODO @fan:就不存原始的图片地址啦 | ||
| 216 | ); | 215 | ); |
| 217 | return true; | 216 | return true; |
| 218 | } | 217 | } |
yudao-server/src/main/resources/application-local.yaml
| @@ -76,6 +76,13 @@ server: | @@ -76,6 +76,13 @@ server: | ||
| 76 | enabled: true | 76 | enabled: true |
| 77 | charset: UTF-8 | 77 | charset: UTF-8 |
| 78 | force: true | 78 | force: true |
| 79 | +# ai | ||
| 80 | +ai: | ||
| 81 | + midjourney-proxy: | ||
| 82 | + url: https://api.holdai.top/mj | ||
| 83 | + notifyUrl: http://7b1aada4.r26.cpolar.top/admin-api/ai/image/midjourney-notify | ||
| 84 | + | ||
| 85 | + | ||
| 79 | --- #################### 定时任务相关配置 #################### | 86 | --- #################### 定时任务相关配置 #################### |
| 80 | 87 | ||
| 81 | # Quartz 配置项,对应 QuartzProperties 配置类 | 88 | # Quartz 配置项,对应 QuartzProperties 配置类 |