Commit 4ee638db87e7e7344be2dba888f06cb65d72a579
1 parent
430dc99d
【代码优化】AI:适配 Spring AI 1.0.6 对 sd、mj 的兼容
Showing
4 changed files
with
12 additions
and
20 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java
| @@ -8,7 +8,6 @@ import lombok.AllArgsConstructor; | @@ -8,7 +8,6 @@ import lombok.AllArgsConstructor; | ||
| 8 | import lombok.Data; | 8 | import lombok.Data; |
| 9 | import lombok.Getter; | 9 | import lombok.Getter; |
| 10 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
| 11 | -import org.springframework.http.HttpHeaders; | ||
| 12 | import org.springframework.http.HttpRequest; | 11 | import org.springframework.http.HttpRequest; |
| 13 | import org.springframework.http.HttpStatusCode; | 12 | import org.springframework.http.HttpStatusCode; |
| 14 | import org.springframework.http.MediaType; | 13 | import org.springframework.http.MediaType; |
| @@ -19,7 +18,6 @@ import reactor.core.publisher.Mono; | @@ -19,7 +18,6 @@ import reactor.core.publisher.Mono; | ||
| 19 | import java.util.Collection; | 18 | import java.util.Collection; |
| 20 | import java.util.List; | 19 | import java.util.List; |
| 21 | import java.util.Map; | 20 | import java.util.Map; |
| 22 | -import java.util.function.Consumer; | ||
| 23 | import java.util.function.Function; | 21 | import java.util.function.Function; |
| 24 | import java.util.function.Predicate; | 22 | import java.util.function.Predicate; |
| 25 | 23 | ||
| @@ -52,19 +50,14 @@ public class MidjourneyApi { | @@ -52,19 +50,14 @@ public class MidjourneyApi { | ||
| 52 | public MidjourneyApi(String baseUrl, String apiKey, String notifyUrl) { | 50 | public MidjourneyApi(String baseUrl, String apiKey, String notifyUrl) { |
| 53 | this.webClient = WebClient.builder() | 51 | this.webClient = WebClient.builder() |
| 54 | .baseUrl(baseUrl) | 52 | .baseUrl(baseUrl) |
| 55 | - .defaultHeaders(getJsonContentHeaders(apiKey)) | 53 | + .defaultHeaders(httpHeaders -> { |
| 54 | + httpHeaders.setContentType(MediaType.APPLICATION_JSON); | ||
| 55 | + httpHeaders.setBearerAuth(apiKey); | ||
| 56 | + }) | ||
| 56 | .build(); | 57 | .build(); |
| 57 | this.notifyUrl = notifyUrl; | 58 | this.notifyUrl = notifyUrl; |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | - // TODO @芋艿:这里,看看怎么调整下???https://github.com/spring-projects/spring-ai/issues/741 | ||
| 61 | - public static Consumer<HttpHeaders> getJsonContentHeaders(String apiKey) { | ||
| 62 | - return (headers) -> { | ||
| 63 | - headers.setBearerAuth(apiKey); | ||
| 64 | - headers.setContentType(MediaType.APPLICATION_JSON); | ||
| 65 | - }; | ||
| 66 | - }; | ||
| 67 | - | ||
| 68 | /** | 61 | /** |
| 69 | * imagine - 根据提示词提交绘画任务 | 62 | * imagine - 根据提示词提交绘画任务 |
| 70 | * | 63 | * |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/MidjourneyApiTests.java
| @@ -15,8 +15,8 @@ import java.util.List; | @@ -15,8 +15,8 @@ import java.util.List; | ||
| 15 | public class MidjourneyApiTests { | 15 | public class MidjourneyApiTests { |
| 16 | 16 | ||
| 17 | private final MidjourneyApi midjourneyApi = new MidjourneyApi( | 17 | private final MidjourneyApi midjourneyApi = new MidjourneyApi( |
| 18 | - "https://api.holdai.top/mj", | ||
| 19 | - "sk-dZEPiVaNcT3FHhef51996bAa0bC74806BeAb620dA5Da10Bf", | 18 | + "https://api.holdai.top/mj", // 链接 |
| 19 | + "sk-aN6nWn3fILjrgLFT0fC4Aa60B72e4253826c77B29dC94f17", // 密钥 | ||
| 20 | null); | 20 | null); |
| 21 | 21 | ||
| 22 | @Test | 22 | @Test |
yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/StabilityAiImageModelTests.java
| @@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit; | @@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit; | ||
| 22 | */ | 22 | */ |
| 23 | public class StabilityAiImageModelTests { | 23 | public class StabilityAiImageModelTests { |
| 24 | 24 | ||
| 25 | - private final StabilityAiApi imageApi = new StabilityAiApi( | ||
| 26 | - "sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx"); | ||
| 27 | - private final StabilityAiImageModel imageModel = new StabilityAiImageModel(imageApi); | 25 | + private final StabilityAiImageModel imageModel = new StabilityAiImageModel( |
| 26 | + new StabilityAiApi("sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx") // 密钥 | ||
| 27 | + ); | ||
| 28 | 28 | ||
| 29 | @Test | 29 | @Test |
| 30 | @Disabled | 30 | @Disabled |
| @@ -32,7 +32,7 @@ public class StabilityAiImageModelTests { | @@ -32,7 +32,7 @@ public class StabilityAiImageModelTests { | ||
| 32 | // 准备参数 | 32 | // 准备参数 |
| 33 | ImageOptions options = OpenAiImageOptions.builder() | 33 | ImageOptions options = OpenAiImageOptions.builder() |
| 34 | .withModel("stable-diffusion-v1-6") | 34 | .withModel("stable-diffusion-v1-6") |
| 35 | - .withHeight(256).withWidth(256) | 35 | + .withHeight(320).withWidth(320) |
| 36 | .build(); | 36 | .build(); |
| 37 | ImagePrompt prompt = new ImagePrompt("great wall", options); | 37 | ImagePrompt prompt = new ImagePrompt("great wall", options); |
| 38 | 38 |
yudao-server/src/main/resources/application.yaml
| @@ -186,9 +186,8 @@ yudao: | @@ -186,9 +186,8 @@ yudao: | ||
| 186 | model: deepseek-chat | 186 | model: deepseek-chat |
| 187 | xinghuo: # 讯飞星火 | 187 | xinghuo: # 讯飞星火 |
| 188 | enable: true | 188 | enable: true |
| 189 | - appId: 13c8cca6 | ||
| 190 | - appKey: cb6415c19d6162cda07b47316fcb0416 | ||
| 191 | - secretKey: Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh | 189 | + appKey: 75b161ed2aef4719b275d6e7f2a4d4cd |
| 190 | + secretKey: YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz | ||
| 192 | model: generalv3.5 | 191 | model: generalv3.5 |
| 193 | midjourney: | 192 | midjourney: |
| 194 | enable: true | 193 | enable: true |