[Azure OpenAI] Image generation support from 2023-06-01-preview service API #37317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change introduces DALL-E image generation support to the .NET SDK based on the latest TypeSpec code generation updates.
The code is a bit "thick" with custom code relative to what we'd like, but that's necessary at the moment given that Azure OpenAI performs image generation as a long-running operation (LRO) while standard OpenAI performs it as a normal, synchronous POST operation.
To represent this,
Response<ImageGenerations> GetImageGenerationsAsync(ImageGenerationOptions, ...)
is introduced, parallel in structure to e.g.Response<ChatCompletions> GetChatCompletionsAsync(..., ChatCompletionsOptions, ...)
ImageGenerations
contains a collection ofImageResponseItem
elements, each of them a concrete instance of one of the two derived classes:ImageLocation
andImagePayload
IReadOnlyList<ImageResponseItem> Data
is determined by the request value ofResponseFormat
in theImageGenerationOptions
(imageGenerationsResponse.Value.Data[0] as ImageLocation).Url
Stream GetStream()
method that will generate a stream for the image data independently of the response format (using the client's pipeline to facilitate downloads in the case of URL format and simply wrapping the base64 data in the case of base64 format)Internally, the implementation of
GetImageGenerations
wraps a deferred LRO call in the case of Azure OpenAI requests and constructs a simpler, straightforward request in the case of standard OpenAI service use.These capabilities are based on the
2023-06-01-preview
service API and we update that dependency (including test collateral) as part of this.