From c5ed07a091e15d72fb61bcec656c2bd3e59a5046 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Jul 2024 22:34:59 +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=20StabilityAiImageModelT?= =?UTF-8?q?ests=20=E5=8D=95=E6=B5=8B=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=A4=A7?= =?UTF-8?q?=E5=AE=B6=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 --- yudao-module-ai/pom.xml | 2 +- yudao-module-ai/yudao-module-ai-biz/pom.xml | 2 +- .../yudao/framework/ai/package-info.java | 15 ++--- .../ai/image/OpenAiImageModelTests.java | 1 + .../ai/image/StabilityAiImageModelTests.java | 65 +++++++++++++++++++ 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/StabilityAiImageModelTests.java diff --git a/yudao-module-ai/pom.xml b/yudao-module-ai/pom.xml index f2ce4fe30..7135100d7 100644 --- a/yudao-module-ai/pom.xml +++ b/yudao-module-ai/pom.xml @@ -20,7 +20,7 @@ ai 模块下,接入 LLM 大模型,支持聊天、绘图、音乐、写作、思维脑图等功能。 目前已接入各种模型,不限于: - 国内:通义千问、文心一言、讯飞星火 + 国内:通义千问、文心一言、讯飞星火、智谱 GLM、DeepSeek 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno diff --git a/yudao-module-ai/yudao-module-ai-biz/pom.xml b/yudao-module-ai/yudao-module-ai-biz/pom.xml index 0be1e4df6..7c529f118 100644 --- a/yudao-module-ai/yudao-module-ai-biz/pom.xml +++ b/yudao-module-ai/yudao-module-ai-biz/pom.xml @@ -14,7 +14,7 @@ ai 模块下,接入 LLM 大模型,支持聊天、绘图、音乐、写作、思维脑图等功能。 目前已接入各种模型,不限于: - 国内:通义千问、文心一言、讯飞星火 + 国内:通义千问、文心一言、讯飞星火、智谱 GLM、DeepSeek 国外:OpenAI、Ollama、Midjourney、StableDiffusion、Suno diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/package-info.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/package-info.java index 60e492ed7..b02d1b3ce 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/package-info.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/package-info.java @@ -1,13 +1,10 @@ /** - * 从 https://github.com/spring-projects/spring-ai 拷贝。 + * AI 大模型组件,基于 Spring AI 拓展 * - * 最大目的:适配 JDK8 兼容性 - * - * 包路径: - * 1. chat、parser、model、parser 包:https://github.com/spring-projects/spring-ai/tree/main/spring-ai-core 拷贝 - * 2. models 包:对标 https://github.com/spring-projects/spring-ai/tree/main/models 拷贝 - * 2.1 xinghuo 包:【讯飞】星火,自己实现 - * 2.2 midjourney 包:Midjourney API,对接 https://github.com/novicezk/midjourney-proxy 实现 - * 2.3 suno 包:Suno API,对接 https://github.com/gcui-art/suno-api 实现 + * models 包路径: + * 1. xinghuo 包:【讯飞】星火,自己实现 + * 2. deepseek 包:【深度求索】DeepSeek,自己实现 + * 3. midjourney 包:Midjourney API,对接 https://github.com/novicezk/midjourney-proxy 实现 + * 4. suno 包:Suno API,对接 https://github.com/gcui-art/suno-api 实现 */ package cn.iocoder.yudao.framework.ai; \ No newline at end of file diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/OpenAiImageModelTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/OpenAiImageModelTests.java index 7b2919d1e..740978e60 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/OpenAiImageModelTests.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/OpenAiImageModelTests.java @@ -35,6 +35,7 @@ public class OpenAiImageModelTests { // 方法调用 ImageResponse response = imageClient.call(prompt); + // 打印结果 System.out.println(response); } diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/StabilityAiImageModelTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/StabilityAiImageModelTests.java new file mode 100644 index 000000000..cb7412821 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/image/StabilityAiImageModelTests.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.framework.ai.image; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.thread.ThreadUtil; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.ai.image.ImageOptions; +import org.springframework.ai.image.ImagePrompt; +import org.springframework.ai.image.ImageResponse; +import org.springframework.ai.openai.OpenAiImageOptions; +import org.springframework.ai.stabilityai.StabilityAiImageModel; +import org.springframework.ai.stabilityai.api.StabilityAiApi; + +import javax.swing.*; +import java.awt.*; +import java.util.concurrent.TimeUnit; + +/** + * {@link StabilityAiImageModel} 集成测试类 + * + * @author fansili + */ +public class StabilityAiImageModelTests { + + private final StabilityAiApi imageApi = new StabilityAiApi( + "sk-e53UqbboF8QJCscYvzJscJxJXoFcFg4iJjl1oqgE7baJETmx"); + private final StabilityAiImageModel imageClient = new StabilityAiImageModel(imageApi); + + @Test + @Disabled + public void testCall() { + // 准备参数 + ImageOptions options = OpenAiImageOptions.builder() + .withModel("stable-diffusion-v1-6") + .withHeight(256).withWidth(256) + .build(); + ImagePrompt prompt = new ImagePrompt("great wall", options); + + // 方法调用 + ImageResponse response = imageClient.call(prompt); + // 打印结果 + String b64Json = response.getResult().getOutput().getB64Json(); + System.out.println(response); + viewImage(b64Json); + } + + public static void viewImage(String b64Json) { + // 创建一个 JFrame + JFrame frame = new JFrame("Byte Image Display"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(800, 600); + + // 创建一个 JLabel 来显示图片 + byte[] imageBytes = Base64.decode(b64Json); + JLabel label = new JLabel(new ImageIcon(imageBytes)); + + // 将 JLabel 添加到 JFrame + frame.getContentPane().add(label, BorderLayout.CENTER); + + // 显示 JFrame + frame.setVisible(true); + ThreadUtil.sleep(1, TimeUnit.HOURS); + } + +}