mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [Breaking] Simplified Content types to a single class with classmethod constructors. (#3252)
* ported Content to a new model * fixed linting * fixes * fixed data format handling * fix for 3.10 mypy * fix * fix int test
This commit is contained in:
committed by
GitHub
Unverified
parent
73761aa4a3
commit
83e6229c11
@@ -82,7 +82,7 @@ with open("path/to/your/image.jpg", "rb") as f:
|
||||
image_uri = f"data:image/jpeg;base64,{image_base64}"
|
||||
|
||||
# Use in DataContent
|
||||
DataContent(
|
||||
Content.from_uri(
|
||||
uri=image_uri,
|
||||
media_type="image/jpeg"
|
||||
)
|
||||
@@ -96,7 +96,7 @@ with open("path/to/your/image.jpg", "rb") as f:
|
||||
image_bytes = f.read()
|
||||
|
||||
# Use in DataContent
|
||||
DataContent(
|
||||
Content.from_data(
|
||||
data=image_bytes,
|
||||
media_type="image/jpeg"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import ChatMessage, DataContent, Role, TextContent
|
||||
from agent_framework import ChatMessage, Content, Role
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -26,7 +26,10 @@ async def test_image() -> None:
|
||||
image_uri = create_sample_image()
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[TextContent(text="What's in this image?"), DataContent(uri=image_uri, media_type="image/png")],
|
||||
contents=[
|
||||
Content.from_text(text="What's in this image?"),
|
||||
Content.from_uri(uri=image_uri, media_type="image/png"),
|
||||
],
|
||||
)
|
||||
|
||||
response = await client.get_response(message)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework import ChatMessage, DataContent, Role, TextContent
|
||||
from agent_framework import ChatMessage, Content, Role
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -35,7 +35,10 @@ async def test_image() -> None:
|
||||
image_uri = create_sample_image()
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[TextContent(text="What's in this image?"), DataContent(uri=image_uri, media_type="image/png")],
|
||||
contents=[
|
||||
Content.from_text(text="What's in this image?"),
|
||||
Content.from_uri(uri=image_uri, media_type="image/png"),
|
||||
],
|
||||
)
|
||||
|
||||
response = await client.get_response(message)
|
||||
@@ -50,8 +53,8 @@ async def test_pdf() -> None:
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[
|
||||
TextContent(text="What information can you extract from this document?"),
|
||||
DataContent(
|
||||
Content.from_text(text="What information can you extract from this document?"),
|
||||
Content.from_data(
|
||||
data=pdf_bytes,
|
||||
media_type="application/pdf",
|
||||
additional_properties={"filename": "sample.pdf"},
|
||||
|
||||
@@ -5,7 +5,7 @@ import base64
|
||||
import struct
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework import ChatMessage, DataContent, Role, TextContent
|
||||
from agent_framework import ChatMessage, Content, Role
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
ASSETS_DIR = Path(__file__).resolve().parent.parent / "sample_assets"
|
||||
@@ -47,7 +47,10 @@ async def test_image() -> None:
|
||||
image_uri = create_sample_image()
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[TextContent(text="What's in this image?"), DataContent(uri=image_uri, media_type="image/png")],
|
||||
contents=[
|
||||
Content.from_text(text="What's in this image?"),
|
||||
Content.from_uri(uri=image_uri, media_type="image/png"),
|
||||
],
|
||||
)
|
||||
|
||||
response = await client.get_response(message)
|
||||
@@ -62,8 +65,8 @@ async def test_audio() -> None:
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[
|
||||
TextContent(text="What do you hear in this audio?"),
|
||||
DataContent(uri=audio_uri, media_type="audio/wav"),
|
||||
Content.from_text(text="What do you hear in this audio?"),
|
||||
Content.from_uri(uri=audio_uri, media_type="audio/wav"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -79,8 +82,8 @@ async def test_pdf() -> None:
|
||||
message = ChatMessage(
|
||||
role=Role.USER,
|
||||
contents=[
|
||||
TextContent(text="What information can you extract from this document?"),
|
||||
DataContent(
|
||||
Content.from_text(text="What information can you extract from this document?"),
|
||||
Content.from_data(
|
||||
data=pdf_bytes, media_type="application/pdf", additional_properties={"filename": "employee_report.pdf"}
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user