From fa230cea8e4ca46c7c4842563ee11cd029bc42c9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Jul 2024 23:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91AI=EF=BC=9A=E5=AE=8C=E5=96=84=20SunoApiTests=20?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=A4=A7=E5=AE=B6?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/core/model/suno/api/SunoApi.java | 13 +-- .../framework/ai/music/SunoApiTests.java | 83 +++++++++++++++++++ .../yudao/framework/ai/music/SunoTests.java | 50 ----------- 3 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java delete mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoTests.java diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/suno/api/SunoApi.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/suno/api/SunoApi.java index de33635f7..81cc654fb 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/suno/api/SunoApi.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/suno/api/SunoApi.java @@ -68,17 +68,6 @@ public class SunoApi { .block(); } - public List chatCompletion(String prompt) { - return this.webClient.post() - .uri("/v1/chat/completions") - .body(Mono.just(new MusicGenerateRequest(prompt)), MusicGenerateRequest.class) - .retrieve() - .onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION.apply(prompt)) - .bodyToMono(new ParameterizedTypeReference>() { - }) - .block(); - } - public LyricsData generateLyrics(String prompt) { return this.webClient.post() .uri("/api/generate_lyrics") @@ -198,7 +187,7 @@ public class SunoApi { } /** - * Suno API 响应的限额数据,目前每日免费50 + * Suno API 响应的限额数据,目前每日免费 50 */ public record LimitUsageData( @JsonProperty("credits_left") Long creditsLeft, diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java new file mode 100644 index 000000000..ed8ecc6c6 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoApiTests.java @@ -0,0 +1,83 @@ +package cn.iocoder.yudao.framework.ai.music; + +import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * {@link SunoApi} 集成测试 + * + * @author xiaoxin + */ +public class SunoApiTests { + + private final SunoApi sunoApi = new SunoApi("https://suno-3tah0ycyt-status2xxs-projects.vercel.app"); +// private final SunoApi sunoApi = new SunoApi("http://127.0.0.1:3001"); + + @Test // 描述模式 + @Disabled + public void testGenerate() { + // 准备参数 + SunoApi.MusicGenerateRequest generateRequest = new SunoApi.MusicGenerateRequest( + "happy music", + "chirp-v3-5", + false); + + // 调用方法 + List musicList = sunoApi.generate(generateRequest); + // 打印结果 + System.out.println(musicList); + } + + @Test // 歌词模式 + @Disabled + public void testCustomGenerate() { + // 准备参数 + SunoApi.MusicGenerateRequest generateRequest = new SunoApi.MusicGenerateRequest( + "创作一首带有轻松吉他旋律的流行歌曲,[verse] 描述夏日海滩的宁静,[chorus] 节奏加快,表达对自由的向往。", + "Happy", + "Happy Song", + "chirp-v3.5", + false, + false); + + // 调用方法 + List musicList = sunoApi.customGenerate(generateRequest); + // 打印结果 + System.out.println(musicList); + } + + @Test + @Disabled + public void testGenerateLyrics() { + // 调用方法 + SunoApi.LyricsData lyricsData = sunoApi.generateLyrics("A soothing lullaby"); + // 打印结果 + System.out.println(lyricsData); + } + + @Test + @Disabled + public void testGetMusicList() { + // 准备参数 +// String id = "d460ddda-7c87-4f34-b751-419b08a590ca"; + String id = "584729e5-0fe9-4157-86da-1b4803ff42bf"; + + // 调用方法 + List musicList = sunoApi.getMusicList(List.of(id)); + // 打印结果 + System.out.println(musicList); + } + + @Test + @Disabled + public void testGetLimitUsage() { + // 调用方法 + SunoApi.LimitUsageData limitUsageData = sunoApi.getLimitUsage(); + // 打印结果 + System.out.println(limitUsageData); + } + +} diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoTests.java deleted file mode 100644 index f6df134ba..000000000 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/music/SunoTests.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.yudao.framework.ai.music; - -import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi; -import org.junit.jupiter.api.Test; - -import java.util.List; - -// TODO 芋艿:整理单测 -/** - * @Author xiaoxin - * @Date 2024/5/27 - */ -public class SunoTests { - - private final SunoApi sunoApi = new SunoApi("https://suno-55ishh05u-status2xxs-projects.vercel.app"); -// private final SunoApi sunoApi = new SunoApi("http://127.0.0.1:3001"); - - @Test - public void selectById() { - System.out.println(sunoApi.getMusicList(List.of("d460ddda-7c87-4f34-b751-419b08a590ca,ff90ea66-49cd-4fd2-b44c-44267dfd5551"))); - } - - @Test - public void generate() { - List generate = sunoApi.generate(new SunoApi.MusicGenerateRequest("创作一首带有轻松吉他旋律的流行歌曲,[verse] 描述夏日海滩的宁静,[chorus] 节奏加快,表达对自由的向往。")); - System.out.println(generate); - } - - - @Test - public void doChatCompletion() { - List generate = sunoApi.chatCompletion("创作一首带有轻松吉他旋律的流行歌曲,[verse] 描述夏日海滩的宁静,[chorus] 节奏加快,表达对自由的向往。"); - System.out.println(generate); - } - - - @Test - public void generateLyrics() { - SunoApi.LyricsData lyricsData = sunoApi.generateLyrics("A soothing lullaby"); - System.out.println(lyricsData); - } - - - @Test - public void selectLimit() { - SunoApi.LimitUsageData limitUsageData = sunoApi.getLimitUsage(); - System.out.println(limitUsageData); - } - -}