Merge remote-tracking branch 'origin/master-jdk21-ai' into master-jdk21-ai

This commit is contained in:
cherishsince 2024-05-30 14:21:23 +08:00
commit 782f108516
4 changed files with 14 additions and 4 deletions

View File

@ -151,7 +151,6 @@ public class YudaoAiAutoConfiguration {
@Bean
@ConditionalOnProperty(value = "yudao.ai.suno.enable", havingValue = "true")
public SunoApi sunoApi(YudaoAiProperties yudaoAiProperties) {
// 创建 sunoApi
return new SunoApi(new SunoConfig(yudaoAiProperties.getSuno().getToken()));
}

View File

@ -137,12 +137,15 @@ public class YudaoAiProperties {
}
@Data
@Accessors(chain = true)
@Accessors(chain = true) // TODO @xiaoxin可以去掉这个默认全局已经开启
public static class SunoProperties {
private boolean enable = false;
/**
* token
*/
private String token;
}
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.framework.ai.core.model.suno.api;
import cn.iocoder.yudao.framework.ai.core.model.suno.SunoConfig;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -14,6 +13,7 @@ import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
// TODO @xiaoxin类注释
/**
* @Author xiaoxin
* @Date 2024/5/27
@ -21,13 +21,17 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public class SunoApi {
// TODO @xiaoxinAPPLICATION_JSONTOKEN_PREFIX 看看 spring 有没自带的这 2 个枚举哈变量越少越好
public static final String APPLICATION_JSON = "application/json";
public static final String TOKEN_PREFIX = "Bearer ";
public static final String API_URL = "https://api.acedata.cloud/suno/audios";
private static final int READ_TIMEOUT = 160; // 连接超时时间音乐生成时间较长设置为 160s后续可做callback
// TODO @xiaoxin建议使用 webClient 对接参考 https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java
private final OkHttpClient client;
// TODO @xiaoxinsunoConfig => config简洁一点
public SunoApi(SunoConfig sunoConfig) {
this.client = new OkHttpClient().newBuilder().readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.addInterceptor(chain -> {
@ -40,6 +44,7 @@ public class SunoApi {
.build();
}
// TODO @芋艿方法名要考虑下
public SunoResponse musicGen(SunoRequest sunoRequest) {
Request request = new Request.Builder()
.url(API_URL)
@ -57,6 +62,7 @@ public class SunoApi {
}
}
// TODO @xiaoxin看看是不是使用 record 特性简化下
/**
* 请求数据对象用于生成音乐音频
@ -96,6 +102,7 @@ public class SunoApi {
private String callbackUrl;
}
// TODO @xiaoxin看看是不是使用 record 特性简化下
/**
* SunoAPI 响应的数据

View File

@ -28,4 +28,5 @@ public class SunoTests {
SunoApi.SunoResponse sunoResponse = sunoApi.musicGen(sunoRequest);
System.out.println(sunoResponse);
}
}