# Image 图片生成 在 Agents-Flex 中,内置了通过 AI 生成图片的能力。 ## 大模型支持 Agents-Flex 图片生成模型支持如下: | 大语言模型名称 | 支持情况 | 描述 | |---------------------------------------------|--------|-------| | Openai | ✅ 已支持 | - | | Stability | ✅ 已支持 | - | | GiteeAI - stable-diffusion-3-medium | ✅ 已支持 | - | | GiteeAI - FLUX.1-schnell | ✅ 已支持 | - | | GiteeAI - stable-diffusion-xl-base-1.0 | ✅ 已支持 | - | | GiteeAI - Kolors | ✅ 已支持 | - | | SiliconFlow - Flux.1-schnell | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion 3 | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion XL | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion 2.1 | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion Turbo | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion XL Turbo | ✅ 已支持 | - | | SiliconFlow - Stable Diffusion XL Lighting | ✅ 已支持 | - | | 更多 |计划中... | 期待 PR | ## 示例代码 ```java public static void main(String[] args) { GiteeImageModelConfig config = new GiteeImageModelConfig(); config.setApiKey("****"); // 第一步:创建一个 ImageModel ImageModel imageModel = new GiteeImageModel(config); // 第二步:创建图片生成提示词和参数 GenerateImageRequest request = new GenerateImageRequest(); request.setPrompt("A cute little tiger standing in the high-speed train"); request.setSize(1024, 1024); // 第三步:通过大模型生成图片 ImageResponse generate = imageModel.generate(request); System.out.println(generate); int index = 0; for (Image image : generate.getImages()) { // 第四步:将图片保存到本地 image.writeToFile(new File("/image-path/"+(index++)+".jpg")); } } ``` 或者使用 OpenAI ImageModel ```java 5-7 public static void main(String[] args) { // 或者使用 OpenAI ImageModel OpenAIImageModelConfig config = new OpenAIImageModelConfig(); config.setApiKey("sk-5gqOclb****"); ImageModel imageModel = new OpenAIImageModel(config); GenerateImageRequest request = new GenerateImageRequest(); request.setPrompt("A cute little tiger standing in the high-speed train"); request.setSize(1024, 1024); ImageResponse generate = imageModel.generate(request); System.out.println(generate); int index = 0; for (Image image : generate.getImages()) { image.writeToFile(new File("/image-path/"+(index++)+".jpg")); } } ``` 或者使用 SiliconFlowImageModel ```java 5-8 public static void main(String[] args) { // 或者使用 SiliconFlowImageModel SiliconflowImageModelConfig config = new SiliconflowImageModelConfig(); config.setModel(SiliconflowImageModels.Stable_Diffusion_XL); config.setApiKey("sk-****"); ImageModel imageModel = new OpenAIImageModel(config); GenerateImageRequest request = new GenerateImageRequest(); request.setPrompt("A cute little tiger standing in the high-speed train"); request.setSize(1024, 1024); ImageResponse generate = imageModel.generate(request); System.out.println(generate); int index = 0; for (Image image : generate.getImages()) { image.writeToFile(new File("/image-path/"+(index++)+".jpg")); } } ```