-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add hosting integration section to text-to-image quickstart #49896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…amples Co-authored-by: gewarren <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new "Use hosting integration" section to the text-to-image quickstart documentation, demonstrating how to integrate image generation capabilities into ASP.NET Core applications using dependency injection and the Aspire Azure OpenAI package. The addition addresses feedback from the original article review and follows the pattern established in a reference sample repository.
- Adds comprehensive hosting integration documentation showing dependency injection setup with
AddAzureOpenAIClientandAddImageGenerator - Includes a complete working ASP.NET Core web application sample demonstrating the hosting pattern
- Documents configuration management through connection strings and the benefits of the DI approach
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/ai/quickstarts/text-to-image.md | Adds "Use hosting integration" section with setup instructions, code examples, and benefits explanation |
| docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs | Complete ASP.NET Core sample demonstrating Azure OpenAI client registration and image generator endpoint |
| docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/TextToImageHosting.csproj | Project file with required NuGet packages for hosting integration |
| docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/appsettings.json | Configuration file showing connection string structure for Azure OpenAI |
| docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/appsettings.Development.json | Development-specific logging configuration |
| docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Properties/launchSettings.json | Launch profiles for HTTP and HTTPS debugging |
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/TextToImageHosting.csproj
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting.csproj
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/appsettings.json
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/Program.cs
Outdated
Show resolved
Hide resolved
docs/ai/quickstarts/snippets/text-to-image/hosting/TextToImageHosting/TextToImageHosting.csproj
Outdated
Show resolved
Hide resolved
BillWagner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM @gewarren
You can decide how to handle the Copilot feedback. Some of it seems reasonable.
Co-authored-by: Copilot <[email protected]>
|
@ericstj This is a preview of the new section on hosting. Can you look it over? |
| // Use the image generator in an endpoint. | ||
| app.MapPost("/generate-image", async (IImageGenerator generator, string prompt) => | ||
| { | ||
| var options = new ImageGenerationOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could set these up with ConfigureOptions on the builder if we wanted to demonstrate that API.
| OpenAIClient openAiClient = services.GetRequiredService<OpenAIClient>(); | ||
| OpenAI.Images.ImageClient imageClient = openAiClient.GetImageClient("gpt-image-1"); | ||
| #pragma warning disable MEAI001 // Type is for evaluation purposes only. | ||
| return imageClient.AsIImageGenerator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to include UseLogging or ConfigureOptions
| - **Dependency injection**: The image generator is available throughout your application via DI. | ||
| - **Lifecycle management**: Services are properly initialized and disposed of by the hosting infrastructure. | ||
| - **Testability**: Mock implementations can be easily substituted for testing. | ||
| - **Integration with .NET Aspire**: When using .NET Aspire, the `AddAzureOpenAIClient` method integrates with service discovery and telemetry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could further improve this if Aspire adds support like AddChatClient and we add an OpenTelemetryImageGenerator. Not sure if that's important for folks usage though.
ericstj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general, just a couple small suggestions to demonstrate additional API.
Summary
Adds documentation showing how to use
AddAzureOpenAIClientandAddImageGeneratorwith dependency injection in hosted applications, addressing feedback from the text-to-image article review.Fixes #49391 (discussion thread)
Changes
New section: "Use hosting integration" added before "Best practices"
Aspire.Azure.AI.OpenAIpackage usage for registering Azure OpenAI clientAddImageGeneratorfor DI container registrationIImageGeneratorinjectionCode sample: Complete ASP.NET Core web app at
snippets/text-to-image/hosting/TextToImageHosting/Example Usage
Follows pattern from ericstj/imageGeneratorSample.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews