Python: Fix broken Content API imports in Python samples#3639
Merged
Conversation
Co-authored-by: moonbox3 <35585003+moonbox3@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix broken import paths for image analysis fields
Fix broken Content API imports in Python samples
Feb 3, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes broken imports in 11 Python sample files that were using deprecated Content API classes. The samples were attempting to import TextContent, UriContent, and DataContent classes that have been consolidated into a unified Content class with factory methods.
Changes:
- Updated all affected samples to import the unified
Contentclass instead of deprecated content type classes - Replaced constructor calls with factory methods (
Content.from_text(),Content.from_uri()) - Converted
isinstance()type checks to property-based checks usingcontent.type
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
handoff_with_code_interpreter_file.py |
Updated import and replaced isinstance(content, TextContent) with content.type == "text" |
override_result_with_middleware.py |
Changed TextContent(text=...) to Content.from_text(text=...) |
devui/weather_agent_azure/agent.py |
Changed TextContent(text=...) to Content.from_text(text=...) |
openai_responses_client_with_code_interpreter.py |
Replaced isinstance() checks with content.type == "text" |
openai_responses_client_streaming_image_generation.py |
Updated import and replaced isinstance(content, DataContent) with content.type == "data" |
openai_responses_client_image_generation.py |
Updated import and replaced isinstance() checks with output.type in ("data", "uri") |
openai_responses_client_image_analysis.py |
Replaced TextContent() and UriContent() with Content.from_text() and Content.from_uri() |
custom_chat_client.py |
Changed TextContent(text=...) to Content.from_text(text=...) |
custom_agent.py |
Changed TextContent(text=...) to Content.from_text(text=...) in multiple locations |
azure_responses_client_image_analysis.py |
Replaced TextContent() and UriContent() with Content.from_text() and Content.from_uri() |
azure_ai_with_code_interpreter_file_download.py |
Replaced isinstance(content, TextContent) checks with content.type == "text" |
python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py
Show resolved
Hide resolved
.../samples/getting_started/agents/openai/openai_responses_client_streaming_image_generation.py
Show resolved
Hide resolved
markwallace-microsoft
approved these changes
Feb 3, 2026
eavanvalkenburg
approved these changes
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
Python samples were using deprecated
TextContent,UriContent, andDataContentclasses that are no longer exported. The framework consolidated these into a unifiedContentclass with factory methods (Content.from_text(),Content.from_uri(), etc.) but 11 sample files were not updated, causing ImportError for users.Description
Updated all affected samples to use the current Content API:
Import changes:
TextContent, UriContent, DataContent→ContentConstructor changes:
TextContent(text="...")→Content.from_text(text="...")UriContent(uri="...", media_type="...")→Content.from_uri(uri="...", media_type="...")Type checks:
isinstance(content, TextContent)→content.type == "text"Affected files (11):
agents/azure_openai/azure_responses_client_image_analysis.pyagents/openai/openai_responses_client_image_analysis.pyagents/openai/openai_responses_client_image_generation.pyagents/openai/openai_responses_client_streaming_image_generation.pyagents/openai/openai_responses_client_with_code_interpreter.pyagents/azure_ai/azure_ai_with_code_interpreter_file_download.pyagents/custom/custom_agent.pyagents/custom/custom_chat_client.pydevui/weather_agent_azure/agent.pymiddleware/override_result_with_middleware.pyworkflows/orchestration/handoff_with_code_interpreter_file.pyExample change:
Contribution Checklist
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.