refactor(normalizer): 移除 request key reorder 机制,保持自然插入顺序

移除 OpenAI/OpenAI CLI normalizer 中的 _reorder_request_prefix_keys 及
基类 _reorder_request_keys 死代码,request_from_internal 直接返回构建
顺序的 dict,测试同步更新为验证自然插入顺序。
This commit is contained in:
fawney19
2026-03-18 14:01:56 +08:00
parent cbb66a5667
commit 696ec65175
5 changed files with 41 additions and 42 deletions

View File

@@ -504,7 +504,7 @@ def test_openai_cli_custom_tool_and_choice_convert_to_openai_chat() -> None:
out = reg.convert_request(openai_cli_req, "openai:cli", "openai:chat")
assert list(out.keys())[:3] == ["model", "tools", "messages"]
assert list(out.keys())[:3] == ["model", "messages", "tools"]
assert out["tools"] == [
{
"type": "custom",
@@ -583,7 +583,7 @@ def test_openai_chat_web_search_options_convert_to_openai_cli_tools() -> None:
out = reg.convert_request(openai_chat_req, "openai:chat", "openai:cli")
assert list(out.keys())[:3] == ["model", "tools", "input"]
assert list(out.keys())[:3] == ["model", "input", "tools"]
assert out["tools"] == [
{
"type": "web_search",
@@ -760,6 +760,22 @@ def test_openai_cli_request_tool_choice_flat_function_roundtrip_preserved() -> N
assert out["tool_choice"] == {"type": "function", "name": "read_file"}
def test_openai_cli_request_from_internal_keeps_natural_insertion_order() -> None:
normalizer = OpenAICliNormalizer()
internal = normalizer.request_to_internal(
{
"model": "gpt-test",
"input": [],
"max_output_tokens": 32,
"tools": [{"type": "function", "name": "read_file"}],
}
)
out = normalizer.request_from_internal(internal)
assert list(out.keys())[:4] == ["model", "input", "max_output_tokens", "tools"]
def test_claude_explicit_effort_preserved_in_openai_cli() -> None:
reg = _make_registry_with_cli()

View File

@@ -237,6 +237,27 @@ def test_openai_request_preserves_empty_string_legacy_function_call_arguments()
assert out["messages"][1]["tool_calls"][0]["function"]["arguments"] == ""
def test_openai_request_from_internal_keeps_natural_insertion_order() -> None:
n = OpenAINormalizer()
req = {
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "weather?"}],
"max_tokens": 12,
"tools": [
{
"type": "function",
"function": {"name": "get_weather", "parameters": {"type": "object"}},
}
],
}
internal = n.request_to_internal(req)
out = n.request_from_internal(internal)
assert list(out.keys())[:4] == ["model", "messages", "max_tokens", "tools"]
def test_openai_request_content_image_and_unknown_drop() -> None:
n = OpenAINormalizer()