【代码优化】AI:适配 Spring AI 1.0.6 对 sd、mj 的兼容
This commit is contained in:
parent
430dc99d12
commit
4ee638db87
|
@ -8,7 +8,6 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.http.HttpStatusCode;
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -19,7 +18,6 @@ import reactor.core.publisher.Mono;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
@ -52,19 +50,14 @@ public class MidjourneyApi {
|
||||||
public MidjourneyApi(String baseUrl, String apiKey, String notifyUrl) {
|
public MidjourneyApi(String baseUrl, String apiKey, String notifyUrl) {
|
||||||
this.webClient = WebClient.builder()
|
this.webClient = WebClient.builder()
|
||||||
.baseUrl(baseUrl)
|
.baseUrl(baseUrl)
|
||||||
.defaultHeaders(getJsonContentHeaders(apiKey))
|
.defaultHeaders(httpHeaders -> {
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
httpHeaders.setBearerAuth(apiKey);
|
||||||
|
})
|
||||||
.build();
|
.build();
|
||||||
this.notifyUrl = notifyUrl;
|
this.notifyUrl = notifyUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @芋艿:这里,看看怎么调整下???https://github.com/spring-projects/spring-ai/issues/741
|
|
||||||
public static Consumer<HttpHeaders> getJsonContentHeaders(String apiKey) {
|
|
||||||
return (headers) -> {
|
|
||||||
headers.setBearerAuth(apiKey);
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* imagine - 根据提示词提交绘画任务
|
* imagine - 根据提示词提交绘画任务
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,8 +15,8 @@ import java.util.List;
|
||||||
public class MidjourneyApiTests {
|
public class MidjourneyApiTests {
|
||||||
|
|
||||||
private final MidjourneyApi midjourneyApi = new MidjourneyApi(
|
private final MidjourneyApi midjourneyApi = new MidjourneyApi(
|
||||||
"https://api.holdai.top/mj",
|
"https://api.holdai.top/mj", // 链接
|
||||||
"sk-dZEPiVaNcT3FHhef51996bAa0bC74806BeAb620dA5Da10Bf",
|
"sk-aN6nWn3fILjrgLFT0fC4Aa60B72e4253826c77B29dC94f17", // 密钥
|
||||||
null);
|
null);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
public class StabilityAiImageModelTests {
|
public class StabilityAiImageModelTests {
|
||||||
|
|
||||||
private final StabilityAiApi imageApi = new StabilityAiApi(
|
private final StabilityAiImageModel imageModel = new StabilityAiImageModel(
|
||||||
"sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx");
|
new StabilityAiApi("sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx") // 密钥
|
||||||
private final StabilityAiImageModel imageModel = new StabilityAiImageModel(imageApi);
|
);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
|
@ -32,7 +32,7 @@ public class StabilityAiImageModelTests {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
ImageOptions options = OpenAiImageOptions.builder()
|
ImageOptions options = OpenAiImageOptions.builder()
|
||||||
.withModel("stable-diffusion-v1-6")
|
.withModel("stable-diffusion-v1-6")
|
||||||
.withHeight(256).withWidth(256)
|
.withHeight(320).withWidth(320)
|
||||||
.build();
|
.build();
|
||||||
ImagePrompt prompt = new ImagePrompt("great wall", options);
|
ImagePrompt prompt = new ImagePrompt("great wall", options);
|
||||||
|
|
||||||
|
|
|
@ -186,9 +186,8 @@ yudao:
|
||||||
model: deepseek-chat
|
model: deepseek-chat
|
||||||
xinghuo: # 讯飞星火
|
xinghuo: # 讯飞星火
|
||||||
enable: true
|
enable: true
|
||||||
appId: 13c8cca6
|
appKey: 75b161ed2aef4719b275d6e7f2a4d4cd
|
||||||
appKey: cb6415c19d6162cda07b47316fcb0416
|
secretKey: YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz
|
||||||
secretKey: Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh
|
|
||||||
model: generalv3.5
|
model: generalv3.5
|
||||||
midjourney:
|
midjourney:
|
||||||
enable: true
|
enable: true
|
||||||
|
|
Loading…
Reference in New Issue