mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] update to v1.0.0 (#5062)
* updates to final deprecated pieces and versions * fix mypy * fix readme links
This commit is contained in:
committed by
GitHub
Unverified
parent
5f06b68535
commit
3446eb8d5d
@@ -11,7 +11,7 @@ This package provides:
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install agent-framework-openai --pre
|
||||
pip install agent-framework-openai
|
||||
```
|
||||
|
||||
## Which chat client should I use?
|
||||
|
||||
@@ -4,7 +4,7 @@ description = "OpenAI integrations for Microsoft Agent Framework."
|
||||
authors = [{ name = "Microsoft", email = "af-support@microsoft.com"}]
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
version = "1.0.0rc6"
|
||||
version = "1.0.0"
|
||||
license-files = ["LICENSE"]
|
||||
urls.homepage = "https://aka.ms/agent-framework"
|
||||
urls.source = "https://github.com/microsoft/agent-framework/tree/main/python"
|
||||
@@ -12,7 +12,7 @@ urls.release_notes = "https://github.com/microsoft/agent-framework/releases?q=ta
|
||||
urls.issues = "https://github.com/microsoft/agent-framework/issues"
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Intended Audience :: Developers",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
@@ -23,7 +23,7 @@ classifiers = [
|
||||
"Typing :: Typed",
|
||||
]
|
||||
dependencies = [
|
||||
"agent-framework-core>=1.0.0rc6",
|
||||
"agent-framework-core>=1.0.0,<2",
|
||||
"openai>=1.99.0,<3",
|
||||
]
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ async def test_get_response_with_all_parameters() -> None:
|
||||
"""Test request preparation with a comprehensive parameter set."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
_, run_options, _ = await client._prepare_request(
|
||||
messages=[Message(role="user", text="Test message")],
|
||||
messages=[Message(role="user", contents=["Test message"])],
|
||||
options={
|
||||
"include": ["message.output_text.logprobs"],
|
||||
"instructions": "You are a helpful assistant",
|
||||
@@ -320,7 +320,7 @@ async def test_web_search_tool_with_location() -> None:
|
||||
)
|
||||
|
||||
_, run_options, _ = await client._prepare_request(
|
||||
messages=[Message(role="user", text="What's the weather?")],
|
||||
messages=[Message(role="user", contents=["What's the weather?"])],
|
||||
options={"tools": [web_search_tool], "tool_choice": "auto"},
|
||||
)
|
||||
|
||||
@@ -346,7 +346,7 @@ async def test_code_interpreter_tool_variations() -> None:
|
||||
code_tool_with_files = OpenAIChatClient.get_code_interpreter_tool(file_ids=["file1", "file2"])
|
||||
|
||||
_, run_options, _ = await client._prepare_request(
|
||||
messages=[Message(role="user", text="Process these files")],
|
||||
messages=[Message(role="user", contents=["Process these files"])],
|
||||
options={"tools": [code_tool_with_files]},
|
||||
)
|
||||
|
||||
@@ -367,7 +367,7 @@ async def test_content_filter_exception() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "create", side_effect=mock_error):
|
||||
with pytest.raises(OpenAIContentFilterException) as exc_info:
|
||||
await client.get_response(messages=[Message(role="user", text="Test message")])
|
||||
await client.get_response(messages=[Message(role="user", contents=["Test message"])])
|
||||
|
||||
assert "content error" in str(exc_info.value)
|
||||
|
||||
@@ -404,7 +404,7 @@ async def test_chat_message_parsing_with_function_calls() -> None:
|
||||
function_result = Content.from_function_result(call_id="test-call-id", result="Function executed successfully")
|
||||
|
||||
messages = [
|
||||
Message(role="user", text="Call a function"),
|
||||
Message(role="user", contents=["Call a function"]),
|
||||
Message(role="assistant", contents=[function_call]),
|
||||
Message(role="tool", contents=[function_result]),
|
||||
]
|
||||
@@ -450,7 +450,7 @@ async def test_response_format_parse_path() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "parse", return_value=mock_parsed_response):
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="Test message")],
|
||||
messages=[Message(role="user", contents=["Test message"])],
|
||||
options={"response_format": OutputStruct, "store": True},
|
||||
)
|
||||
assert response.response_id == "parsed_response_123"
|
||||
@@ -477,7 +477,7 @@ async def test_response_format_parse_path_with_conversation_id() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "parse", return_value=mock_parsed_response):
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="Test message")],
|
||||
messages=[Message(role="user", contents=["Test message"])],
|
||||
options={"response_format": OutputStruct, "store": True},
|
||||
)
|
||||
assert response.response_id == "parsed_response_123"
|
||||
@@ -515,7 +515,7 @@ async def test_response_format_dict_parse_path() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "create", return_value=mock_response):
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="Test message")],
|
||||
messages=[Message(role="user", contents=["Test message"])],
|
||||
options={"response_format": response_format},
|
||||
)
|
||||
|
||||
@@ -540,7 +540,7 @@ async def test_bad_request_error_non_content_filter() -> None:
|
||||
with patch.object(client.client.responses, "parse", side_effect=mock_error):
|
||||
with pytest.raises(ChatClientException) as exc_info:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="Test message")],
|
||||
messages=[Message(role="user", contents=["Test message"])],
|
||||
options={"response_format": OutputStruct},
|
||||
)
|
||||
|
||||
@@ -561,7 +561,7 @@ async def test_streaming_content_filter_exception_handling() -> None:
|
||||
mock_create.side_effect.code = "content_filter"
|
||||
|
||||
with pytest.raises(OpenAIContentFilterException, match="service encountered a content error"):
|
||||
response_stream = client.get_response(stream=True, messages=[Message(role="user", text="Test")])
|
||||
response_stream = client.get_response(stream=True, messages=[Message(role="user", contents=["Test"])])
|
||||
async for _ in response_stream:
|
||||
break
|
||||
|
||||
@@ -926,7 +926,7 @@ async def test_local_shell_tool_is_invoked_in_function_loop() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "create", side_effect=[mock_response1, mock_response2]) as mock_create:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="What Python version is available?")],
|
||||
messages=[Message(role="user", contents=["What Python version is available?"])],
|
||||
options={"tools": [local_shell_tool]},
|
||||
)
|
||||
|
||||
@@ -999,7 +999,7 @@ async def test_shell_call_is_invoked_as_local_shell_function_loop() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "create", side_effect=[mock_response1, mock_response2]) as mock_create:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="What Python version is available?")],
|
||||
messages=[Message(role="user", contents=["What Python version is available?"])],
|
||||
options={"tools": [local_shell_tool]},
|
||||
)
|
||||
|
||||
@@ -1264,8 +1264,8 @@ def test_prepare_messages_for_openai_assistant_history_uses_output_text_with_ann
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
|
||||
messages = [
|
||||
Message(role="user", text="What is async/await?"),
|
||||
Message(role="assistant", text="Async/await enables non-blocking concurrency."),
|
||||
Message(role="user", contents=["What is async/await?"]),
|
||||
Message(role="assistant", contents=["Async/await enables non-blocking concurrency."]),
|
||||
]
|
||||
|
||||
prepared = client._prepare_messages_for_openai(messages)
|
||||
@@ -2263,7 +2263,7 @@ async def test_end_to_end_mcp_approval_flow(span_exporter) -> None:
|
||||
# Patch the create call to return the two mocked responses in sequence
|
||||
with patch.object(client.client.responses, "create", side_effect=[mock_response1, mock_response2]) as mock_create:
|
||||
# First call: get the approval request
|
||||
response = await client.get_response(messages=[Message(role="user", text="Trigger approval")])
|
||||
response = await client.get_response(messages=[Message(role="user", contents=["Trigger approval"])])
|
||||
assert response.messages[0].contents[0].type == "function_approval_request"
|
||||
req = response.messages[0].contents[0]
|
||||
assert req.id == "approval-1"
|
||||
@@ -2515,7 +2515,7 @@ def test_streaming_annotation_added_with_unknown_type() -> None:
|
||||
async def test_service_response_exception_includes_original_error_details() -> None:
|
||||
"""Test that ChatClientException messages include original error details in the new format."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
messages = [Message(role="user", text="test message")]
|
||||
messages = [Message(role="user", contents=["test message"])]
|
||||
|
||||
mock_response = MagicMock()
|
||||
original_error_message = "Request rate limit exceeded"
|
||||
@@ -2540,7 +2540,7 @@ async def test_service_response_exception_includes_original_error_details() -> N
|
||||
async def test_get_response_streaming_with_response_format() -> None:
|
||||
"""Test get_response streaming with response_format."""
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
messages = [Message(role="user", text="Test streaming with format")]
|
||||
messages = [Message(role="user", contents=["Test streaming with format"])]
|
||||
|
||||
# It will fail due to invalid API key, but exercises the code path
|
||||
with pytest.raises(ChatClientException):
|
||||
@@ -3090,7 +3090,7 @@ def test_parse_response_from_openai_image_generation_fallback():
|
||||
|
||||
async def test_prepare_options_store_parameter_handling() -> None:
|
||||
client = OpenAIChatClient(model="test-model", api_key="test-key")
|
||||
messages = [Message(role="user", text="Test message")]
|
||||
messages = [Message(role="user", contents=["Test message"])]
|
||||
|
||||
test_conversation_id = "test-conversation-123"
|
||||
chat_options = ChatOptions(store=True, conversation_id=test_conversation_id)
|
||||
@@ -3142,7 +3142,7 @@ async def test_instructions_sent_first_turn_then_skipped_for_continuation() -> N
|
||||
|
||||
with patch.object(client.client.responses, "create", return_value=mock_response) as mock_create:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="Hello")],
|
||||
messages=[Message(role="user", contents=["Hello"])],
|
||||
options={"instructions": "Reply in uppercase."},
|
||||
)
|
||||
|
||||
@@ -3153,7 +3153,7 @@ async def test_instructions_sent_first_turn_then_skipped_for_continuation() -> N
|
||||
assert first_input_messages[1]["role"] == "user"
|
||||
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="Tell me a joke")],
|
||||
messages=[Message(role="user", contents=["Tell me a joke"])],
|
||||
options={
|
||||
"instructions": "Reply in uppercase.",
|
||||
"conversation_id": "resp_123",
|
||||
@@ -3175,7 +3175,7 @@ async def test_instructions_not_repeated_for_continuation_ids(
|
||||
|
||||
with patch.object(client.client.responses, "create", return_value=mock_response) as mock_create:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="Continue conversation")],
|
||||
messages=[Message(role="user", contents=["Continue conversation"])],
|
||||
options={"instructions": "Be helpful.", "conversation_id": conversation_id},
|
||||
)
|
||||
|
||||
@@ -3191,7 +3191,7 @@ async def test_instructions_included_without_conversation_id() -> None:
|
||||
|
||||
with patch.object(client.client.responses, "create", return_value=mock_response) as mock_create:
|
||||
await client.get_response(
|
||||
messages=[Message(role="user", text="Hello")],
|
||||
messages=[Message(role="user", contents=["Hello"])],
|
||||
options={"instructions": "You are a helpful assistant."},
|
||||
)
|
||||
|
||||
@@ -3300,14 +3300,14 @@ async def test_integration_options(
|
||||
# Prepare test message
|
||||
if option_name.startswith("tools") or option_name.startswith("tool_choice"):
|
||||
# Use weather-related prompt for tool tests
|
||||
messages = [Message(role="user", text="What is the weather in Seattle?")]
|
||||
messages = [Message(role="user", contents=["What is the weather in Seattle?"])]
|
||||
elif option_name.startswith("response_format"):
|
||||
# Use prompt that works well with structured output
|
||||
messages = [Message(role="user", text="The weather in Seattle is sunny")]
|
||||
messages.append(Message(role="user", text="What is the weather in Seattle?"))
|
||||
messages = [Message(role="user", contents=["The weather in Seattle is sunny"])]
|
||||
messages.append(Message(role="user", contents=["What is the weather in Seattle?"]))
|
||||
else:
|
||||
# Generic prompt for simple options
|
||||
messages = [Message(role="user", text="Say 'Hello World' briefly.")]
|
||||
messages = [Message(role="user", contents=["Say 'Hello World' briefly."])]
|
||||
|
||||
# Build options dict
|
||||
options: dict[str, Any] = {option_name: option_value}
|
||||
@@ -3358,7 +3358,7 @@ async def test_integration_web_search() -> None:
|
||||
"messages": [
|
||||
Message(
|
||||
role="user",
|
||||
text="What is the current weather? Do not ask for my current location.",
|
||||
contents=["What is the current weather? Do not ask for my current location."],
|
||||
)
|
||||
],
|
||||
"options": {
|
||||
@@ -3390,7 +3390,7 @@ async def test_integration_file_search() -> None:
|
||||
messages=[
|
||||
Message(
|
||||
role="user",
|
||||
text="What is the weather today? Do a file search to find the answer.",
|
||||
contents=["What is the weather today? Do a file search to find the answer."],
|
||||
)
|
||||
],
|
||||
options={
|
||||
@@ -3424,7 +3424,7 @@ async def test_integration_streaming_file_search() -> None:
|
||||
messages=[
|
||||
Message(
|
||||
role="user",
|
||||
text="What is the weather today? Do a file search to find the answer.",
|
||||
contents=["What is the weather today? Do a file search to find the answer."],
|
||||
)
|
||||
],
|
||||
options={
|
||||
@@ -3468,7 +3468,7 @@ async def test_integration_tool_rich_content_image() -> None:
|
||||
messages = [
|
||||
Message(
|
||||
role="user",
|
||||
text="Call the get_test_image tool and describe what you see.",
|
||||
contents=["Call the get_test_image tool and describe what you see."],
|
||||
)
|
||||
]
|
||||
options: dict[str, Any] = {"tools": [get_test_image], "tool_choice": "auto"}
|
||||
|
||||
@@ -285,14 +285,14 @@ async def test_integration_options(
|
||||
|
||||
for streaming in [False, True]:
|
||||
if option_name in {"tools", "tool_choice"}:
|
||||
messages = [Message(role="user", text="What is the weather in Seattle?")]
|
||||
messages = [Message(role="user", contents=["What is the weather in Seattle?"])]
|
||||
elif option_name == "response_format":
|
||||
messages = [
|
||||
Message(role="user", text="The weather in Seattle is sunny"),
|
||||
Message(role="user", text="What is the weather in Seattle?"),
|
||||
Message(role="user", contents=["The weather in Seattle is sunny"]),
|
||||
Message(role="user", contents=["What is the weather in Seattle?"]),
|
||||
]
|
||||
else:
|
||||
messages = [Message(role="user", text="Say 'Hello World' briefly.")]
|
||||
messages = [Message(role="user", contents=["Say 'Hello World' briefly."])]
|
||||
|
||||
options: dict[str, Any] = {option_name: option_value}
|
||||
if option_name == "tool_choice":
|
||||
@@ -339,7 +339,7 @@ async def test_integration_web_search() -> None:
|
||||
messages=[
|
||||
Message(
|
||||
role="user",
|
||||
text="What is the current weather? Do not ask for my current location.",
|
||||
contents=["What is the current weather? Do not ask for my current location."],
|
||||
)
|
||||
],
|
||||
options={
|
||||
@@ -361,7 +361,9 @@ async def test_integration_client_file_search() -> None:
|
||||
file_id, vector_store = await create_vector_store(client)
|
||||
try:
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="What is the weather today? Do a file search to find the answer.")],
|
||||
messages=[
|
||||
Message(role="user", contents=["What is the weather today? Do a file search to find the answer."])
|
||||
],
|
||||
options={
|
||||
"tools": [OpenAIChatClient.get_file_search_tool(vector_store_ids=[vector_store.vector_store_id])],
|
||||
"tool_choice": "auto",
|
||||
@@ -384,7 +386,9 @@ async def test_integration_client_file_search_streaming() -> None:
|
||||
file_id, vector_store = await create_vector_store(client)
|
||||
try:
|
||||
response_stream = client.get_response(
|
||||
messages=[Message(role="user", text="What is the weather today? Do a file search to find the answer.")],
|
||||
messages=[
|
||||
Message(role="user", contents=["What is the weather today? Do a file search to find the answer."])
|
||||
],
|
||||
stream=True,
|
||||
options={
|
||||
"tools": [OpenAIChatClient.get_file_search_tool(vector_store_ids=[vector_store.vector_store_id])],
|
||||
@@ -407,7 +411,7 @@ async def test_integration_client_agent_hosted_mcp_tool() -> None:
|
||||
async with AzureCliCredential() as credential:
|
||||
client = OpenAIChatClient(credential=credential)
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="How to create an Azure storage account using az cli?")],
|
||||
messages=[Message(role="user", contents=["How to create an Azure storage account using az cli?"])],
|
||||
options={
|
||||
"max_tokens": 5000,
|
||||
"tools": OpenAIChatClient.get_mcp_tool(
|
||||
@@ -432,7 +436,7 @@ async def test_integration_client_agent_hosted_code_interpreter_tool() -> None:
|
||||
client = OpenAIChatClient(credential=credential)
|
||||
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="Calculate the sum of numbers from 1 to 10 using Python code.")],
|
||||
messages=[Message(role="user", contents=["Calculate the sum of numbers from 1 to 10 using Python code."])],
|
||||
options={"tools": [OpenAIChatClient.get_code_interpreter_tool()]},
|
||||
)
|
||||
|
||||
@@ -496,7 +500,7 @@ async def test_azure_openai_chat_client_tool_rich_content_image() -> None:
|
||||
client.function_invocation_configuration["max_iterations"] = 2
|
||||
|
||||
for streaming in [False, True]:
|
||||
messages = [Message(role="user", text="Call the get_test_image tool and describe what you see.")]
|
||||
messages = [Message(role="user", contents=["Call the get_test_image tool and describe what you see."])]
|
||||
options: dict[str, Any] = {"tools": [get_test_image], "tool_choice": "auto"}
|
||||
|
||||
if streaming:
|
||||
|
||||
@@ -196,7 +196,7 @@ async def test_content_filter_exception_handling(
|
||||
) -> None:
|
||||
"""Test that content filter errors are properly handled."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
messages = [Message(role="user", text="test message")]
|
||||
messages = [Message(role="user", contents=["test message"])]
|
||||
|
||||
# Create a mock BadRequestError with content_filter code
|
||||
mock_response = MagicMock()
|
||||
@@ -271,7 +271,7 @@ async def test_mcp_tool_dict_causes_api_rejection(openai_unit_test_env: dict[str
|
||||
rather than a silent no-op.
|
||||
"""
|
||||
client = OpenAIChatCompletionClient()
|
||||
messages = [Message(role="user", text="test message")]
|
||||
messages = [Message(role="user", contents=["test message"])]
|
||||
|
||||
mcp_tool = {
|
||||
"type": "mcp",
|
||||
@@ -331,7 +331,7 @@ def get_weather(location: str) -> str:
|
||||
async def test_exception_message_includes_original_error_details() -> None:
|
||||
"""Test that exception messages include original error details in the new format."""
|
||||
client = OpenAIChatCompletionClient(model="test-model", api_key="test-key")
|
||||
messages = [Message(role="user", text="test message")]
|
||||
messages = [Message(role="user", contents=["test message"])]
|
||||
|
||||
mock_response = MagicMock()
|
||||
original_error_message = "Invalid API request format"
|
||||
@@ -1183,7 +1183,7 @@ def test_prepare_options_without_model(openai_unit_test_env: dict[str, str]) ->
|
||||
client = OpenAIChatCompletionClient()
|
||||
client.model = None # Remove model
|
||||
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
|
||||
with pytest.raises(ValueError, match="model must be a non-empty string"):
|
||||
client._prepare_options(messages, {})
|
||||
@@ -1221,7 +1221,7 @@ def test_prepare_options_with_instructions(
|
||||
"""Test that instructions are prepended as system message."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
|
||||
messages = [Message(role="user", text="Hello")]
|
||||
messages = [Message(role="user", contents=["Hello"])]
|
||||
options = {"instructions": "You are a helpful assistant."}
|
||||
|
||||
prepared_options = client._prepare_options(messages, options)
|
||||
@@ -1244,8 +1244,8 @@ def test_prepare_options_with_instructions_no_duplicate(
|
||||
|
||||
# Simulate messages that already contain the system instruction
|
||||
messages = [
|
||||
Message(role="system", text="You are a helpful assistant."),
|
||||
Message(role="user", text="Hello"),
|
||||
Message(role="system", contents=["You are a helpful assistant."]),
|
||||
Message(role="user", contents=["Hello"]),
|
||||
]
|
||||
options = {"instructions": "You are a helpful assistant."}
|
||||
|
||||
@@ -1416,7 +1416,7 @@ def test_tool_choice_required_with_function_name(
|
||||
"""Test that tool_choice with required mode and function name is correctly prepared."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
options = {
|
||||
"tools": [get_weather],
|
||||
"tool_choice": {"mode": "required", "required_function_name": "get_weather"},
|
||||
@@ -1434,7 +1434,7 @@ def test_response_format_dict_passthrough(openai_unit_test_env: dict[str, str])
|
||||
"""Test that response_format as dict is passed through directly."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
custom_format = {
|
||||
"type": "json_schema",
|
||||
"json_schema": {"name": "Test", "schema": {"type": "object"}},
|
||||
@@ -1503,7 +1503,7 @@ def test_prepare_options_removes_parallel_tool_calls_when_no_tools(
|
||||
"""Test that parallel_tool_calls is removed when no tools are present."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
options = {"allow_multiple_tool_calls": True}
|
||||
|
||||
prepared_options = client._prepare_options(messages, options)
|
||||
@@ -1516,7 +1516,7 @@ def test_prepare_options_excludes_conversation_id(openai_unit_test_env: dict[str
|
||||
"""Test that conversation_id is excluded from prepared options for chat completions."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
options = {"conversation_id": "12345", "temperature": 0.7}
|
||||
|
||||
prepared_options = client._prepare_options(messages, options)
|
||||
@@ -1532,7 +1532,7 @@ async def test_streaming_exception_handling(
|
||||
) -> None:
|
||||
"""Test that streaming errors are properly handled."""
|
||||
client = OpenAIChatCompletionClient()
|
||||
messages = [Message(role="user", text="test")]
|
||||
messages = [Message(role="user", contents=["test"])]
|
||||
|
||||
# Create a mock error during streaming
|
||||
mock_error = Exception("Streaming error")
|
||||
@@ -1640,14 +1640,14 @@ async def test_integration_options(
|
||||
# Prepare test message
|
||||
if option_name.startswith("tools") or option_name.startswith("tool_choice"):
|
||||
# Use weather-related prompt for tool tests
|
||||
messages = [Message(role="user", text="What is the weather in Seattle?")]
|
||||
messages = [Message(role="user", contents=["What is the weather in Seattle?"])]
|
||||
elif option_name.startswith("response_format"):
|
||||
# Use prompt that works well with structured output
|
||||
messages = [Message(role="user", text="The weather in Seattle is sunny")]
|
||||
messages.append(Message(role="user", text="What is the weather in Seattle?"))
|
||||
messages = [Message(role="user", contents=["The weather in Seattle is sunny"])]
|
||||
messages.append(Message(role="user", contents=["What is the weather in Seattle?"]))
|
||||
else:
|
||||
# Generic prompt for simple options
|
||||
messages = [Message(role="user", text="Say 'Hello World' briefly.")]
|
||||
messages = [Message(role="user", contents=["Say 'Hello World' briefly."])]
|
||||
|
||||
# Build options dict
|
||||
options: dict[str, Any] = {option_name: option_value}
|
||||
@@ -1705,7 +1705,7 @@ async def test_integration_web_search() -> None:
|
||||
"messages": [
|
||||
Message(
|
||||
role="user",
|
||||
text="Who are the main characters of Kpop Demon Hunters? Do a web search to find the answer.",
|
||||
contents=["Who are the main characters of Kpop Demon Hunters? Do a web search to find the answer."],
|
||||
)
|
||||
],
|
||||
"options": {
|
||||
@@ -1737,7 +1737,7 @@ async def test_integration_web_search() -> None:
|
||||
"messages": [
|
||||
Message(
|
||||
role="user",
|
||||
text="What is the current weather? Do not ask for my current location.",
|
||||
contents=["What is the current weather? Do not ask for my current location."],
|
||||
)
|
||||
],
|
||||
"options": {
|
||||
|
||||
@@ -195,14 +195,16 @@ async def test_azure_openai_chat_completion_client_response() -> None:
|
||||
messages = [
|
||||
Message(
|
||||
role="user",
|
||||
text=(
|
||||
"Emily and David, two passionate scientists, met during a research expedition to Antarctica. "
|
||||
"Bonded by their love for the natural world and shared curiosity, they uncovered a "
|
||||
"groundbreaking phenomenon in glaciology that could potentially reshape our understanding "
|
||||
"of climate change."
|
||||
),
|
||||
contents=[
|
||||
(
|
||||
"Emily and David, two passionate scientists, met during a research expedition to Antarctica. "
|
||||
"Bonded by their love for the natural world and shared curiosity, they uncovered a "
|
||||
"groundbreaking phenomenon in glaciology that could potentially reshape our understanding "
|
||||
"of climate change."
|
||||
)
|
||||
],
|
||||
),
|
||||
Message(role="user", text="who are Emily and David?"),
|
||||
Message(role="user", contents=["who are Emily and David?"]),
|
||||
]
|
||||
|
||||
response = await client.get_response(messages=messages)
|
||||
@@ -223,7 +225,7 @@ async def test_azure_openai_chat_completion_client_response_tools() -> None:
|
||||
client = OpenAIChatCompletionClient(credential=credential)
|
||||
|
||||
response = await client.get_response(
|
||||
messages=[Message(role="user", text="who are Emily and David?")],
|
||||
messages=[Message(role="user", contents=["who are Emily and David?"])],
|
||||
options={"tools": [get_story_text], "tool_choice": "auto"},
|
||||
)
|
||||
|
||||
@@ -244,14 +246,16 @@ async def test_azure_openai_chat_completion_client_streaming() -> None:
|
||||
messages=[
|
||||
Message(
|
||||
role="user",
|
||||
text=(
|
||||
"Emily and David, two passionate scientists, met during a research expedition to Antarctica. "
|
||||
"Bonded by their love for the natural world and shared curiosity, they uncovered a "
|
||||
"groundbreaking phenomenon in glaciology that could potentially reshape our understanding "
|
||||
"of climate change."
|
||||
),
|
||||
contents=[
|
||||
(
|
||||
"Emily and David, two passionate scientists, met during a research expedition to "
|
||||
"Antarctica. Bonded by their love for the natural world and shared curiosity, they "
|
||||
"uncovered a groundbreaking phenomenon in glaciology that could potentially reshape our "
|
||||
"understanding of climate change."
|
||||
)
|
||||
],
|
||||
),
|
||||
Message(role="user", text="who are Emily and David?"),
|
||||
Message(role="user", contents=["who are Emily and David?"]),
|
||||
],
|
||||
stream=True,
|
||||
)
|
||||
@@ -277,7 +281,7 @@ async def test_azure_openai_chat_completion_client_streaming_tools() -> None:
|
||||
client = OpenAIChatCompletionClient(credential=credential)
|
||||
|
||||
response = client.get_response(
|
||||
messages=[Message(role="user", text="who are Emily and David?")],
|
||||
messages=[Message(role="user", contents=["who are Emily and David?"])],
|
||||
stream=True,
|
||||
options={"tools": [get_story_text], "tool_choice": "auto"},
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ async def test_cmc(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
await openai_chat_completion.get_response(messages=chat_history)
|
||||
@@ -86,7 +86,7 @@ async def test_cmc_chat_options(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
await openai_chat_completion.get_response(
|
||||
@@ -107,7 +107,7 @@ async def test_cmc_no_fcc_in_response(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
orig_chat_history = deepcopy(chat_history)
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
@@ -129,7 +129,7 @@ async def test_cmc_structured_output_no_fcc(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
# Define a mock response format
|
||||
class Test(BaseModel):
|
||||
@@ -151,7 +151,7 @@ async def test_scmc_chat_options(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_streaming_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
async for msg in openai_chat_completion.get_response(
|
||||
@@ -177,7 +177,7 @@ async def test_cmc_general_exception(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
with pytest.raises(ChatClientException):
|
||||
@@ -194,7 +194,7 @@ async def test_cmc_additional_properties(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
await openai_chat_completion.get_response(messages=chat_history, options={"reasoning_effort": "low"})
|
||||
@@ -232,7 +232,7 @@ async def test_get_streaming(
|
||||
stream = MagicMock(spec=AsyncStream)
|
||||
stream.__aiter__.return_value = [content1, content2]
|
||||
mock_create.return_value = stream
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
orig_chat_history = deepcopy(chat_history)
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
@@ -272,7 +272,7 @@ async def test_get_streaming_singular(
|
||||
stream = MagicMock(spec=AsyncStream)
|
||||
stream.__aiter__.return_value = [content1, content2]
|
||||
mock_create.return_value = stream
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
orig_chat_history = deepcopy(chat_history)
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
@@ -312,7 +312,7 @@ async def test_get_streaming_structured_output_no_fcc(
|
||||
stream = MagicMock(spec=AsyncStream)
|
||||
stream.__aiter__.return_value = [content1, content2]
|
||||
mock_create.return_value = stream
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
|
||||
# Define a mock response format
|
||||
class Test(BaseModel):
|
||||
@@ -336,7 +336,7 @@ async def test_get_streaming_no_fcc_in_response(
|
||||
openai_unit_test_env: dict[str, str],
|
||||
):
|
||||
mock_create.return_value = mock_streaming_chat_completion_response
|
||||
chat_history.append(Message(role="user", text="hello world"))
|
||||
chat_history.append(Message(role="user", contents=["hello world"]))
|
||||
orig_chat_history = deepcopy(chat_history)
|
||||
|
||||
openai_chat_completion = OpenAIChatCompletionClient()
|
||||
|
||||
Reference in New Issue
Block a user