Python: Fixed middleware and multimodal input samples (#4022)

* Fix streaming branch in weather override middleware sample

The streaming branch of weather_override_middleware only prefixed the
original weather data via a transform hook instead of replacing the
content with the 'perfect weather' override like the non-streaming
branch does. Replace with a new ResponseStream that yields the override
content as ChatResponseUpdate chunks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fixed exception handling middleware sample

* Fixed runtime context delegation middleware example

* Fixed multimodal input examples

* Small update

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Dmytro Struk
2026-02-17 19:49:33 -05:00
committed by GitHub
Unverified
parent df58775d64
commit 2dd731f90f
8 changed files with 204 additions and 33 deletions
@@ -9,7 +9,7 @@ from azure.identity import AzureCliCredential
def create_sample_image() -> str:
"""Create a simple 1x1 pixel PNG image for testing."""
# This is a tiny red pixel in PNG format
# This is a tiny yellow pixel in PNG format
png_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="
return f"data:image/png;base64,{png_data}"
@@ -32,7 +32,7 @@ async def test_image() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"Image Response: {response}")
@@ -18,7 +18,7 @@ def load_sample_pdf() -> bytes:
def create_sample_image() -> str:
"""Create a simple 1x1 pixel PNG image for testing."""
# This is a tiny red pixel in PNG format
# This is a tiny yellow pixel in PNG format
png_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="
return f"data:image/png;base64,{png_data}"
@@ -41,7 +41,7 @@ async def test_image() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"Image Response: {response}")
@@ -62,7 +62,7 @@ async def test_pdf() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"PDF Response: {response}")
@@ -19,7 +19,7 @@ def load_sample_pdf() -> bytes:
def create_sample_image() -> str:
"""Create a simple 1x1 pixel PNG image for testing."""
# This is a tiny red pixel in PNG format
# This is a tiny yellow pixel in PNG format
png_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="
return f"data:image/png;base64,{png_data}"
@@ -53,7 +53,7 @@ async def test_image() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"Image Response: {response}")
@@ -70,7 +70,7 @@ async def test_audio() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"Audio Response: {response}")
@@ -89,7 +89,7 @@ async def test_pdf() -> None:
],
)
response = await client.get_response(message)
response = await client.get_response([message])
print(f"PDF Response: {response}")