Python: follow on work on OpenAI (#169)

* updated openai, fcc works, with sample

* reduced files in openai
This commit is contained in:
Eduard van Valkenburg
2025-07-12 07:15:51 +02:00
committed by GitHub
Unverified
parent 80c1e2ee0a
commit 407ed6de70
32 changed files with 693 additions and 668 deletions
+24 -1
View File
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft. All rights reserved.
from agent_framework import AITool, ai_function
from agent_framework import AIFunction, AITool, ai_function
def test_ai_function_decorator():
@@ -12,6 +12,7 @@ def test_ai_function_decorator():
return x + y
assert isinstance(test_tool, AITool)
assert isinstance(test_tool, AIFunction)
assert test_tool.name == "test_tool"
assert test_tool.description == "A test tool"
assert test_tool.parameters() == {
@@ -23,6 +24,27 @@ def test_ai_function_decorator():
assert test_tool(1, 2) == 3
def test_ai_function_decorator_without_args():
"""Test the ai_function decorator."""
@ai_function
def test_tool(x: int, y: int) -> int:
"""A simple function that adds two numbers."""
return x + y
assert isinstance(test_tool, AITool)
assert isinstance(test_tool, AIFunction)
assert test_tool.name == "test_tool"
assert test_tool.description == "A simple function that adds two numbers."
assert test_tool.parameters() == {
"properties": {"x": {"title": "X", "type": "integer"}, "y": {"title": "Y", "type": "integer"}},
"required": ["x", "y"],
"title": "test_tool_input",
"type": "object",
}
assert test_tool(1, 2) == 3
async def test_ai_function_decorator_with_async():
"""Test the ai_function decorator with an async function."""
@@ -32,6 +54,7 @@ async def test_ai_function_decorator_with_async():
return x + y
assert isinstance(async_test_tool, AITool)
assert isinstance(async_test_tool, AIFunction)
assert async_test_tool.name == "async_test_tool"
assert async_test_tool.description == "An async test tool"
assert async_test_tool.parameters() == {
+13 -5
View File
@@ -274,7 +274,7 @@ def test_chat_message_contents():
assert isinstance(message.contents[1], TextContent)
assert message.contents[0].text == "Hello, how are you?"
assert message.contents[1].text == "I'm fine, thank you!"
assert message.text == "Hello, how are you?\nI'm fine, thank you!"
assert message.text == "Hello, how are you? I'm fine, thank you!"
# region: ChatResponse
@@ -348,7 +348,7 @@ def test_chat_response_updates_to_chat_response_one():
# Check the type and content
assert len(chat_response.messages) == 1
assert chat_response.text == "I'm doing well, \nthank you!"
assert chat_response.text == "I'm doing well, thank you!"
assert isinstance(chat_response.messages[0], ChatMessage)
assert len(chat_response.messages[0].contents) == 1
assert chat_response.messages[0].message_id == "1"
@@ -396,7 +396,7 @@ def test_chat_response_updates_to_chat_response_multiple():
# Check the type and content
assert len(chat_response.messages) == 1
assert chat_response.text == "I'm doing well, \nthank you!"
assert chat_response.text == "I'm doing well, thank you!"
assert isinstance(chat_response.messages[0], ChatMessage)
assert len(chat_response.messages[0].contents) == 3
assert chat_response.messages[0].message_id == "1"
@@ -422,11 +422,19 @@ def test_chat_response_updates_to_chat_response_multiple_multiple():
# Check the type and content
assert len(chat_response.messages) == 1
assert chat_response.text == "I'm doing well, \nthank you!\nMore context\nFinal part"
assert isinstance(chat_response.messages[0], ChatMessage)
assert len(chat_response.messages[0].contents) == 3
assert chat_response.messages[0].message_id == "1"
assert len(chat_response.messages[0].contents) == 3
assert isinstance(chat_response.messages[0].contents[0], TextContent)
assert chat_response.messages[0].contents[0].text == "I'm doing well, thank you!"
assert isinstance(chat_response.messages[0].contents[1], TextReasoningContent)
assert chat_response.messages[0].contents[1].text == "Additional context"
assert isinstance(chat_response.messages[0].contents[2], TextContent)
assert chat_response.messages[0].contents[2].text == "More context Final part"
assert chat_response.text == "I'm doing well, thank you! More context Final part"
# region: ChatToolMode