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
@@ -10,9 +10,9 @@ from agent_framework import (
|
||||
AgentThread,
|
||||
BaseAgent,
|
||||
ChatMessage,
|
||||
Content,
|
||||
ContextProvider,
|
||||
Role,
|
||||
TextContent,
|
||||
normalize_messages,
|
||||
)
|
||||
from agent_framework._pydantic import AFBaseSettings
|
||||
@@ -332,7 +332,7 @@ class CopilotStudioAgent(BaseAgent):
|
||||
):
|
||||
yield ChatMessage(
|
||||
role=Role.ASSISTANT,
|
||||
contents=[TextContent(activity.text)],
|
||||
contents=[Content.from_text(activity.text)],
|
||||
author_name=activity.from_property.name if activity.from_property else None,
|
||||
message_id=activity.id,
|
||||
raw_representation=activity,
|
||||
|
||||
@@ -4,14 +4,7 @@ from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from agent_framework import (
|
||||
AgentResponse,
|
||||
AgentResponseUpdate,
|
||||
AgentThread,
|
||||
ChatMessage,
|
||||
Role,
|
||||
TextContent,
|
||||
)
|
||||
from agent_framework import AgentResponse, AgentResponseUpdate, AgentThread, ChatMessage, Content, Role
|
||||
from agent_framework.exceptions import ServiceException, ServiceInitializationError
|
||||
from microsoft_agents.copilotstudio.client import CopilotClient
|
||||
|
||||
@@ -136,7 +129,7 @@ class TestCopilotStudioAgent:
|
||||
assert isinstance(response, AgentResponse)
|
||||
assert len(response.messages) == 1
|
||||
content = response.messages[0].contents[0]
|
||||
assert isinstance(content, TextContent)
|
||||
assert content.type == "text"
|
||||
assert content.text == "Test response"
|
||||
assert response.messages[0].role == Role.ASSISTANT
|
||||
|
||||
@@ -150,13 +143,13 @@ class TestCopilotStudioAgent:
|
||||
mock_copilot_client.start_conversation.return_value = create_async_generator([conversation_activity])
|
||||
mock_copilot_client.ask_question.return_value = create_async_generator([mock_activity])
|
||||
|
||||
chat_message = ChatMessage(role=Role.USER, contents=[TextContent("test message")])
|
||||
chat_message = ChatMessage(role=Role.USER, contents=[Content.from_text("test message")])
|
||||
response = await agent.run(chat_message)
|
||||
|
||||
assert isinstance(response, AgentResponse)
|
||||
assert len(response.messages) == 1
|
||||
content = response.messages[0].contents[0]
|
||||
assert isinstance(content, TextContent)
|
||||
assert content.type == "text"
|
||||
assert content.text == "Test response"
|
||||
assert response.messages[0].role == Role.ASSISTANT
|
||||
|
||||
@@ -206,7 +199,7 @@ class TestCopilotStudioAgent:
|
||||
async for response in agent.run_stream("test message"):
|
||||
assert isinstance(response, AgentResponseUpdate)
|
||||
content = response.contents[0]
|
||||
assert isinstance(content, TextContent)
|
||||
assert content.type == "text"
|
||||
assert content.text == "Streaming response"
|
||||
response_count += 1
|
||||
|
||||
@@ -233,7 +226,7 @@ class TestCopilotStudioAgent:
|
||||
async for response in agent.run_stream("test message", thread=thread):
|
||||
assert isinstance(response, AgentResponseUpdate)
|
||||
content = response.contents[0]
|
||||
assert isinstance(content, TextContent)
|
||||
assert content.type == "text"
|
||||
assert content.text == "Streaming response"
|
||||
response_count += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user