Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

This PR adds a comprehensive tutorial that demonstrates how to use the Microsoft.Extensions.AI library to generate images from text prompts using the IImageGenerator interface.

Overview

The tutorial covers the complete workflow for integrating text-to-image capabilities into .NET applications, with support for both OpenAI and Azure OpenAI providers.

What's included

Documentation

  • New tutorial article (docs/ai/tutorials/text-to-image.md) that covers:
    • Introduction to the IImageGenerator interface and its capabilities
    • Step-by-step instructions for creating a console application
    • Configuration options for customizing image generation (size, count, format)
    • Pipeline composition with middleware for telemetry and logging
    • Error handling and best practices
    • Saving generated images locally
    • Production-ready recommendations

Code Examples

  • OpenAI implementation with complete, compilable C# code
  • Azure OpenAI implementation with authentication using DefaultAzureCredential
  • Both examples demonstrate:
    • Basic image generation from text prompts
    • Configuration with ImageGenerationOptions
    • Building pipelines with ImageGeneratorBuilder
    • Adding OpenTelemetry for observability
    • Error handling for common scenarios
    • Downloading and saving generated images

Features

  • Uses zone pivots to seamlessly switch between OpenAI and Azure OpenAI examples
  • All code examples compile successfully using .NET 9.0
  • Follows Microsoft documentation standards with proper frontmatter
  • Includes proper experimental API warning (MEAI001)
  • Code snippets organized with region markers for easy reference
  • Added to the AI tutorials section in the table of contents

Technical Details

The tutorial demonstrates the experimental IImageGenerator interface from the Microsoft.Extensions.AI library, showing how to:

  • Convert OpenAI's ImageClient to IImageGenerator using the AsIImageGenerator() extension method
  • Configure image generation with System.Drawing.Size for dimensions
  • Use ImageGenerationResponseFormat for controlling output format
  • Access generated images through ImageGenerationResponse.Contents collection
  • Cast content items to UriContent to retrieve image URLs

Fixes #486214

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

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

  • https://api.github.com/repos/jeremylikness/text2imagesample/contents
    • Triggering command: curl -s REDACTED (http block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>[New article]: AI text-to-image feature</issue_title>
<issue_description>Create a tutorial that shows how to use the text to image features of Microsoft.Extensions.AI, including code examples in C#.

Proposed topic or title

AI text-to-image feature

Location in table of contents.

docs/ai/toc.yml

Sources:


Associated WorkItem - 486214</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #48169


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/ai/index.yml [linkListType: architecture
docs/ai/overview.md Develop .NET apps with AI features
docs/ai/quickstarts/build-chat-app.md CustomerIntent: As a .NET developer new to AI, I want deploy and use sample code to interact to learn from the sample code.
docs/ai/quickstarts/build-vector-search-app.md Build a .NET AI vector search app
docs/ai/quickstarts/generate-images.md docs/ai/quickstarts/generate-images
docs/ai/quickstarts/text-to-image.md Generate images from text using AI
docs/ai/toc.yml docs/ai/toc
docs/azure/index.yml Azure for .NET developers

Copilot AI and others added 2 commits October 21, 2025 20:23
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tutorial for AI text-to-image feature in .NET Add tutorial for text-to-image generation using Microsoft.Extensions.AI Oct 21, 2025
Copilot AI requested a review from gewarren October 21, 2025 20:27
Copilot finished work on behalf of gewarren October 21, 2025 20:27
@gewarren gewarren marked this pull request as ready for review October 22, 2025 21:22
@gewarren gewarren requested a review from a team as a code owner October 22, 2025 21:22
Copy link
Contributor

Copilot AI left a 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 comprehensive quickstart tutorial demonstrating how to generate images from text prompts using the Microsoft.Extensions.AI library's experimental IImageGenerator interface. The tutorial provides step-by-step instructions with working code examples for Azure OpenAI integration, covering basic image generation, configuration options, error handling, and best practices.

Key changes:

  • Adds new quickstart tutorial text-to-image.md with complete Azure OpenAI implementation
  • Reorganizes TOC structure with new "Text to image" section and expanded quickstarts
  • Includes working C# code example with proper error handling and configuration management
  • Updates existing generate-images.md title to clarify it uses DALLe directly

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs/ai/toc.yml Restructures navigation with expanded quickstarts section and new "Text to image" category containing both MEAI and DALLe tutorials
docs/ai/quickstarts/text-to-image.md Adds new comprehensive tutorial covering IImageGenerator usage with Azure OpenAI, including setup, code examples, options, error handling, and best practices
docs/ai/quickstarts/snippets/text-to-image/azure-openai/TextToImageAzureOpenAI.csproj Adds project file with required package references for the text-to-image quickstart sample
docs/ai/quickstarts/snippets/text-to-image/azure-openai/Program.cs Implements complete working example demonstrating basic generation, configuration options, and error handling patterns
docs/ai/quickstarts/generate-images.md Updates title to clarify distinction from MEAI tutorial by specifying it uses DALLe

@jeffhandley jeffhandley requested a review from ericstj October 23, 2025 01:05
@ericstj
Copy link
Member

ericstj commented Oct 23, 2025

@gewarren - gave first pass of feedback. Let me know what you think based on desired scope of this initial PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[New article]: AI text-to-image feature

3 participants