Skip to content

Fix generateImage edit mode for Azure OpenAI provider#1806

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-1805
Closed

Fix generateImage edit mode for Azure OpenAI provider#1806
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-1805

Conversation

Copy link
Copy Markdown

Copilot AI commented Jul 29, 2025

The generateImage function was returning undefined when used in edit mode with the Azure OpenAI provider. This was caused by edit mode parameters (image and mask) not being properly passed to the Azure API endpoint.

Problem

When calling generateImage with edit parameters like this:

const result = await generateImage("Replace the cat with a dog", {
    image: baseImageData,
    mask: maskData,
    model: "dall-e-2"
});
// result was undefined for Azure provider

The function would fail silently because:

  1. Edit mode parameters were passed to the function options instead of the HTTP request body
  2. The wrong API endpoint was used (/images/generations instead of /images/edits)
  3. Azure-specific URL construction didn't handle edit mode properly

Solution

This PR fixes the issue by:

  1. Adding edit mode parameter support: Extended CreateImageRequest and ImageGenerationOptions type definitions to include image and mask parameters for image editing

  2. Fixing parameter passing: Modified the generateImage function in runpromptcontext.ts to include edit parameters (...rest) in the request object that gets sent to the API, rather than only passing them to function options

  3. Implementing edit mode detection: Updated OpenAIImageGeneration to detect when image parameter is present and automatically switch to the /images/edits endpoint

  4. Correcting 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 cases

  5. Consistent model parameter handling: Ensured the model parameter is always included in requests for both edit and generation modes, as required by the OpenAI API

Changes

  • Type definitions: Added image and mask parameters to support edit mode
  • Request building: Edit parameters are now properly included in the HTTP request body
  • Endpoint selection: Automatically uses /images/edits when image parameter is provided
  • Azure compatibility: Handles Azure OpenAI URL format for both generation and edit modes with proper model parameter inclusion

The 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.

Co-authored-by: sinedied <593151+sinedied@users.noreply.github.com>
Copilot AI changed the title [WIP] generateImage edit mode does not work with Azure Fix generateImage edit mode for Azure OpenAI provider Jul 29, 2025
Copilot AI requested a review from sinedied July 29, 2025 14:02
if (isEditMode) {
body.image = image
if (mask) body.mask = mask
// Model parameter is typically not used in edit mode for OpenAI
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really the case?
I think we should always set the model

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, model is needed in edits just like for generations!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! The model is now included in the Azure URL construction for edit mode, just like it is for generations. Commit: b8eb307

@sinedied
Copy link
Copy Markdown
Collaborator

sinedied commented Jul 29, 2025

Review the comments and update the code

@copilot

@pelikhan
Copy link
Copy Markdown
Member

Wrong branch

@pelikhan
Copy link
Copy Markdown
Member

Use GitHub.com/copilot/agents to start a task on dev

Copy link
Copy Markdown
Collaborator

@sinedied sinedied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review previous comment and make changes

Copy link
Copy Markdown
Author

Copilot AI commented Jul 30, 2025

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 addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from sinedied July 30, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateImage edit mode does not work with Azure

3 participants