mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	【优化】修复imageSize不生效问题,增加modal、style、size 适配
This commit is contained in:
		| @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.ai.image.*; | |||||||
| import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageRequest; | import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageRequest; | ||||||
| import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageResponse; | import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageResponse; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.jetbrains.annotations.NotNull; | ||||||
| import org.springframework.retry.RetryCallback; | import org.springframework.retry.RetryCallback; | ||||||
| import org.springframework.retry.RetryContext; | import org.springframework.retry.RetryContext; | ||||||
| import org.springframework.retry.RetryListener; | import org.springframework.retry.RetryListener; | ||||||
| @@ -58,21 +59,14 @@ public class OpenAiImageClient implements ImageClient { | |||||||
|     @Override |     @Override | ||||||
|     public ImageResponse call(ImagePrompt imagePrompt) { |     public ImageResponse call(ImagePrompt imagePrompt) { | ||||||
|         return this.retryTemplate.execute(ctx -> { |         return this.retryTemplate.execute(ctx -> { | ||||||
|             // 检查是否配置了 OpenAiImageOptions |             OpenAiImageOptions openAiImageOptions = getOpenAiImageOptions(imagePrompt); | ||||||
|             if (defaultImageOptions == null && imagePrompt.getOptions() == null) { |  | ||||||
|                 throw new ChatException("OpenAiImageOptions 未配置参数!"); |  | ||||||
|             } |  | ||||||
|             // 优先使用 request 中的 ImageOptions |  | ||||||
|             ImageOptions useImageOptions = imagePrompt.getOptions() == null ? defaultImageOptions : imagePrompt.getOptions(); |  | ||||||
|             if (!(useImageOptions instanceof OpenAiImageOptions)) { |  | ||||||
|                 throw new ChatException("配置信息不正确,传入的必须是 OpenAiImageOptions!"); |  | ||||||
|             } |  | ||||||
|             // 转换 OpenAiImageOptions |  | ||||||
|             OpenAiImageOptions openAiImageOptions = (OpenAiImageOptions) useImageOptions; |  | ||||||
|             // 创建请求 |             // 创建请求 | ||||||
|             OpenAiImageRequest request = new OpenAiImageRequest(); |             OpenAiImageRequest request = new OpenAiImageRequest(); | ||||||
|             BeanUtil.copyProperties(openAiImageOptions, request); |             BeanUtil.copyProperties(openAiImageOptions, request); | ||||||
|             request.setPrompt(imagePrompt.getInstructions().get(0).getText()); |             request.setPrompt(imagePrompt.getInstructions().get(0).getText()); | ||||||
|  |             request.setModel(openAiImageOptions.getModel()); | ||||||
|  |             request.setStyle(openAiImageOptions.getStyle().getStyle()); | ||||||
|  |             request.setSize(openAiImageOptions.getSize()); | ||||||
|             // 发送请求 |             // 发送请求 | ||||||
|             OpenAiImageResponse response = openAiImageApi.createImage(request); |             OpenAiImageResponse response = openAiImageApi.createImage(request); | ||||||
|             return new ImageResponse(response.getData().stream().map(res -> { |             return new ImageResponse(response.getData().stream().map(res -> { | ||||||
| @@ -83,4 +77,19 @@ public class OpenAiImageClient implements ImageClient { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private @NotNull OpenAiImageOptions getOpenAiImageOptions(ImagePrompt imagePrompt) { | ||||||
|  |         // 检查是否配置了 OpenAiImageOptions | ||||||
|  |         if (defaultImageOptions == null && imagePrompt.getOptions() == null) { | ||||||
|  |             throw new ChatException("OpenAiImageOptions 未配置参数!"); | ||||||
|  |         } | ||||||
|  |         // 优先使用 request 中的 ImageOptions | ||||||
|  |         ImageOptions useImageOptions = imagePrompt.getOptions() == null ? defaultImageOptions : imagePrompt.getOptions(); | ||||||
|  |         if (!(useImageOptions instanceof OpenAiImageOptions)) { | ||||||
|  |             throw new ChatException("配置信息不正确,传入的必须是 OpenAiImageOptions!"); | ||||||
|  |         } | ||||||
|  |         // 转换 OpenAiImageOptions | ||||||
|  |         OpenAiImageOptions openAiImageOptions = (OpenAiImageOptions) useImageOptions; | ||||||
|  |         return openAiImageOptions; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 cherishsince
					cherishsince