Skip to content

Bug "Optional[ ]" String incorrectly added when casting "model" to string in Azure Image Service #492

@waltervvb

Description

@waltervvb

When using the Azure OpenAI implementation, the code was incorrectly converting the model parameter to a string, resulting in an unwanted "Optional" prefix being added to the deployment model value

Example:
... ImageGenerateParams.builder().model(ImageModel.GPT_IMAGE_1) ...

Will generate:
"/openai/deployments/Optional[gpt-image-1]/images/generations"

Instead of:
"/openai/deployments/gpt-image-1/images/generations"

Solution
On openai.java.core ImageServiceImpl.kt modified the code to properly handle the optional model parameter using map/orElse pattern specifically for Azure deployments, as the edit and createVariation methods handle this.

.prepare(
    clientOptions,
    params,
    deploymentModel = params.model().map { it.toString() }.orElse(null)
)

ImageServiceImplDiff.txt

The fix ensures the correct model identifier is passed to the Azure API without the "Optional" prefix.

As an additional comment the model should be required on the Azure implementation since it refers to the model deployment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions