mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
feat(normalizer): 稳定请求体字段顺序以提升 prompt cache 命中率
在 FormatNormalizer 基类新增 _reorder_request_keys 方法,OpenAI/OpenAI CLI normalizer 各自定义前缀字段顺序(model, tools, messages / model, instructions, tools, input),确保静态字段前置、动态内容后置。同时调整 OpenAI CLI 中 instructions 字段的构建位置使其在 input 之前。
This commit is contained in:
@@ -54,6 +54,23 @@ def test_openai_cli_request_to_claude() -> None:
|
||||
assert claude_req["messages"][0]["content"] == "hi"
|
||||
|
||||
|
||||
def test_claude_request_to_openai_cli_places_instructions_before_input() -> None:
|
||||
reg = _make_registry_with_cli()
|
||||
|
||||
claude_req = {
|
||||
"model": "claude-3-5-sonnet-latest",
|
||||
"system": "You are precise.",
|
||||
"messages": [{"role": "user", "content": "hi"}],
|
||||
"max_tokens": 12,
|
||||
}
|
||||
|
||||
openai_cli_req = reg.convert_request(claude_req, "claude:chat", "openai:cli")
|
||||
|
||||
assert openai_cli_req["instructions"] == "You are precise."
|
||||
assert list(openai_cli_req.keys())[:3] == ["model", "instructions", "input"]
|
||||
assert openai_cli_req["input"][0]["role"] == "user"
|
||||
|
||||
|
||||
def test_claude_response_to_openai_cli() -> None:
|
||||
reg = _make_registry_with_cli()
|
||||
|
||||
@@ -426,6 +443,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 out["tools"] == [
|
||||
{
|
||||
"type": "custom",
|
||||
@@ -504,6 +522,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 out["tools"] == [
|
||||
{
|
||||
"type": "web_search",
|
||||
|
||||
Reference in New Issue
Block a user