- Issue created by @marcus_johansson
- Merge request !45Draft: Resolve #3531289 "Add gpt image 1 image" → (Open) created by marcus_johansson
- 🇰🇬Kyrgyzstan dan_metille
This is a duplicate of which issue?
Got a bit into trouble since last update from dev-1.1.x#f3c8cae
I had ImageToImage working with OpenAI, and then lost all models provided by OpenAI. - 🇩🇪Germany marcus_johansson
Sorry about that @dan - active again and I will move this to 1.2.x, since it will require AI 1.2.x.
- 🇰🇬Kyrgyzstan dan_metille
Thanks @marcus, no problem. If it helps, here is the code that I added to this patch to make the ImageToImage working:
--- a/src/Plugin/AiProvider/OpenAiProvider.php +++ b/src/Plugin/AiProvider/OpenAiProvider.php @@ -599,7 +599,21 @@ class OpenAiProvider extends AiProviderClientBase implements // Process the image response. foreach ($response['data'] as $data) { $image = new ImageFile(); - $image->setFileFromUrl($data['url']); + // Handle both URL and base64 responses + if (isset($data['url'])) { + $image->setFileFromUrl($data['url']); + } elseif (isset($data['b64_json'])) { + $mime_type = 'image/png'; + $file_ext = 'png'; + $image->setBinary(base64_decode($data['b64_json'])); + $image->setMimeType($mime_type); + $image->setFilename('generated_image_' . time() . '.' . $file_ext); + } else { + continue; + } + + // Add the image to the array (this was missing!) + $images[] = $image; } // If no images were successfully created, throw an error. if (empty($images)) {
- 🇩🇪Germany marcus_johansson
This looks good, it reviewed, but it can't be merged until the image-to-image issue is merged: ✨ Create Image-To-Image operation type Active .