mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +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,6 +59,25 @@ 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 = getOpenAiImageOptions(imagePrompt); | ||||||
|  |             // 创建请求 | ||||||
|  |             OpenAiImageRequest request = new OpenAiImageRequest(); | ||||||
|  |             BeanUtil.copyProperties(openAiImageOptions, request); | ||||||
|  |             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); | ||||||
|  |             return new ImageResponse(response.getData().stream().map(res -> { | ||||||
|  |                 byte[] bytes = HttpUtil.downloadBytes(res.getUrl()); | ||||||
|  |                 String base64 = Base64.encode(bytes); | ||||||
|  |                 return new ImageGeneration(new Image(res.getUrl(), base64)); | ||||||
|  |             }).toList()); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private @NotNull OpenAiImageOptions getOpenAiImageOptions(ImagePrompt imagePrompt) { | ||||||
|         // 检查是否配置了 OpenAiImageOptions |         // 检查是否配置了 OpenAiImageOptions | ||||||
|         if (defaultImageOptions == null && imagePrompt.getOptions() == null) { |         if (defaultImageOptions == null && imagePrompt.getOptions() == null) { | ||||||
|             throw new ChatException("OpenAiImageOptions 未配置参数!"); |             throw new ChatException("OpenAiImageOptions 未配置参数!"); | ||||||
| @@ -69,18 +89,7 @@ public class OpenAiImageClient implements ImageClient { | |||||||
|         } |         } | ||||||
|         // 转换 OpenAiImageOptions |         // 转换 OpenAiImageOptions | ||||||
|         OpenAiImageOptions openAiImageOptions = (OpenAiImageOptions) useImageOptions; |         OpenAiImageOptions openAiImageOptions = (OpenAiImageOptions) useImageOptions; | ||||||
|             // 创建请求 |         return openAiImageOptions; | ||||||
|             OpenAiImageRequest request = new OpenAiImageRequest(); |  | ||||||
|             BeanUtil.copyProperties(openAiImageOptions, request); |  | ||||||
|             request.setPrompt(imagePrompt.getInstructions().get(0).getText()); |  | ||||||
|             // 发送请求 |  | ||||||
|             OpenAiImageResponse response = openAiImageApi.createImage(request); |  | ||||||
|             return new ImageResponse(response.getData().stream().map(res -> { |  | ||||||
|                 byte[] bytes = HttpUtil.downloadBytes(res.getUrl()); |  | ||||||
|                 String base64 = Base64.encode(bytes); |  | ||||||
|                 return new ImageGeneration(new Image(res.getUrl(), base64)); |  | ||||||
|             }).toList()); |  | ||||||
|         }); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 cherishsince
					cherishsince