Fix generateImage edit mode for Azure OpenAI provider#1806
Conversation
Co-authored-by: sinedied <593151+sinedied@users.noreply.github.com>
| if (isEditMode) { | ||
| body.image = image | ||
| if (mask) body.mask = mask | ||
| // Model parameter is typically not used in edit mode for OpenAI |
There was a problem hiding this comment.
is it really the case?
I think we should always set the model
There was a problem hiding this comment.
You're absolutely right! I've fixed this - the model parameter is now always set in the request body for both edit and generation modes. Commit: b8eb307
| `/images/generations?api-version=${version}` | ||
| delete body.model | ||
| if (isEditMode) { | ||
| // Azure doesn't use model in the URL for edit mode |
There was a problem hiding this comment.
YES, model is needed in edits just like for generations!
There was a problem hiding this comment.
Fixed! The model is now included in the Azure URL construction for edit mode, just like it is for generations. Commit: b8eb307
|
Review the comments and update the code |
|
Wrong branch |
|
Use GitHub.com/copilot/agents to start a task on dev |
sinedied
left a comment
There was a problem hiding this comment.
Review previous comment and make changes
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The
generateImagefunction was returningundefinedwhen used in edit mode with the Azure OpenAI provider. This was caused by edit mode parameters (imageandmask) not being properly passed to the Azure API endpoint.Problem
When calling
generateImagewith edit parameters like this:The function would fail silently because:
/images/generationsinstead of/images/edits)Solution
This PR fixes the issue by:
Adding edit mode parameter support: Extended
CreateImageRequestandImageGenerationOptionstype definitions to includeimageandmaskparameters for image editingFixing parameter passing: Modified the
generateImagefunction inrunpromptcontext.tsto include edit parameters (...rest) in the request object that gets sent to the API, rather than only passing them to function optionsImplementing edit mode detection: Updated
OpenAIImageGenerationto detect whenimageparameter is present and automatically switch to the/images/editsendpointCorrecting Azure URL construction: Fixed Azure-specific URL building to properly handle both generation (
/images/generations) and edit (/images/edits) endpoints, including the model parameter in both casesConsistent model parameter handling: Ensured the
modelparameter is always included in requests for both edit and generation modes, as required by the OpenAI APIChanges
imageandmaskparameters to support edit mode/images/editswhenimageparameter is providedThe fix ensures that image editing works correctly with all supported providers, including Azure OpenAI, while maintaining backward compatibility for regular image generation.
Fixes #1805.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.