Unverified Commit 720d3cd0 authored by Chauncey's avatar Chauncey Committed by GitHub
Browse files

[CI] fix ruff format (#26579)


Signed-off-by: default avatarchaunceyjiang <chaunceyjiang@gmail.com>
parent ab196ede
...@@ -208,13 +208,15 @@ async def test_gpt_oss_multi_turn_chat(gptoss_client: OpenAI, with_tool_parser: ...@@ -208,13 +208,15 @@ async def test_gpt_oss_multi_turn_chat(gptoss_client: OpenAI, with_tool_parser:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI, async def test_gpt_oss_tool_message_array_content(
with_tool_parser: bool): gptoss_client: OpenAI, with_tool_parser: bool
):
"""Test that tool messages support both string and array content formats.""" """Test that tool messages support both string and array content formats."""
if not with_tool_parser: if not with_tool_parser:
pytest.skip("skip non-tool for array content tests") pytest.skip("skip non-tool for array content tests")
tools = [{ tools = [
{
"type": "function", "type": "function",
"function": { "function": {
"name": "get_weather", "name": "get_weather",
...@@ -222,37 +224,33 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI, ...@@ -222,37 +224,33 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
"parameters": { "parameters": {
"type": "object", "type": "object",
"properties": { "properties": {
"city": { "city": {"type": "string"},
"type": "string" "state": {"type": "string"},
},
"state": {
"type": "string"
},
}, },
"required": ["city", "state"], "required": ["city", "state"],
}, },
}, },
}] }
]
# Test 1: Tool message with string content # Test 1: Tool message with string content
messages_string = [{ messages_string = [
"role": "user", {"role": "user", "content": "What's the weather in Paris?"},
"content": "What's the weather in Paris?" {
}, { "role": "assistant",
"role": "tool_calls": [
"assistant", {
"tool_calls": [{
"id": "call_123", "id": "call_123",
"type": "function", "type": "function",
"function": { "function": {
"name": "get_weather", "name": "get_weather",
"arguments": '{"city": "Paris", "state": "TX"}' "arguments": '{"city": "Paris", "state": "TX"}',
},
} }
}] ],
}, { },
"role": "tool", {"role": "tool", "content": "The weather in Paris, TX is sunny, 22°C"},
"content": "The weather in Paris, TX is sunny, 22°C" ]
}]
response_string = await gptoss_client.chat.completions.create( response_string = await gptoss_client.chat.completions.create(
model=GPT_OSS_MODEL_NAME, model=GPT_OSS_MODEL_NAME,
...@@ -265,28 +263,28 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI, ...@@ -265,28 +263,28 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
assert response_string.choices[0].message is not None assert response_string.choices[0].message is not None
# Test 2: Tool message with array content # Test 2: Tool message with array content
messages_array = [{ messages_array = [
"role": "user", {"role": "user", "content": "What's the weather in Dallas?"},
"content": "What's the weather in Dallas?" {
}, { "role": "assistant",
"role": "tool_calls": [
"assistant", {
"tool_calls": [{
"id": "call_456", "id": "call_456",
"type": "function", "type": "function",
"function": { "function": {
"name": "get_weather", "name": "get_weather",
"arguments": '{"city": "Dallas", "state": "TX"}' "arguments": '{"city": "Dallas", "state": "TX"}',
},
} }
}] ],
}, { },
"role": {
"tool", "role": "tool",
"content": [{ "content": [
"type": "text", {"type": "text", "text": "f2e897a7-2705-4337-8193-2a8f57b81618"}
"text": "f2e897a7-2705-4337-8193-2a8f57b81618" ],
}] },
}] ]
response_array = await gptoss_client.chat.completions.create( response_array = await gptoss_client.chat.completions.create(
model=GPT_OSS_MODEL_NAME, model=GPT_OSS_MODEL_NAME,
...@@ -299,34 +297,30 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI, ...@@ -299,34 +297,30 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
assert response_array.choices[0].message is not None assert response_array.choices[0].message is not None
# Test 3: Tool message with multiple array content items # Test 3: Tool message with multiple array content items
messages_multi_array = [{ messages_multi_array = [
"role": "user", {"role": "user", "content": "Search for information"},
"content": "Search for information" {
}, { "role": "assistant",
"role": "tool_calls": [
"assistant", {
"tool_calls": [{
"id": "call_789", "id": "call_789",
"type": "function", "type": "function",
"function": { "function": {
"name": "get_weather", "name": "get_weather",
"arguments": '{"city": "Austin", "state": "TX"}' "arguments": '{"city": "Austin", "state": "TX"}',
},
} }
}] ],
}, { },
"role": {
"tool", "role": "tool",
"content": [{ "content": [
"type": "text", {"type": "text", "text": "Weather data: "},
"text": "Weather data: " {"type": "text", "text": "Austin, TX - Partly cloudy, 25°C"},
}, { {"type": "text", "text": " with 60% humidity"},
"type": "text", ],
"text": "Austin, TX - Partly cloudy, 25°C" },
}, { ]
"type": "text",
"text": " with 60% humidity"
}]
}]
response_multi_array = await gptoss_client.chat.completions.create( response_multi_array = await gptoss_client.chat.completions.create(
model=GPT_OSS_MODEL_NAME, model=GPT_OSS_MODEL_NAME,
......
...@@ -260,8 +260,10 @@ def parse_chat_input(chat_msg) -> list[Message]: ...@@ -260,8 +260,10 @@ def parse_chat_input(chat_msg) -> list[Message]:
# Handle array format for tool message content # Handle array format for tool message content
# by concatenating all text parts. # by concatenating all text parts.
content = "".join( content = "".join(
item.get("text", "") for item in content item.get("text", "")
if isinstance(item, dict) and item.get("type") == "text") for item in content
if isinstance(item, dict) and item.get("type") == "text"
)
msg = Message.from_author_and_content( msg = Message.from_author_and_content(
Author.new(Role.TOOL, f"functions.{name}"), content Author.new(Role.TOOL, f"functions.{name}"), content
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment