Skip to content

Commit 3c4550a

Browse files
committed
fix: switch mutated anthropic provider to native AnthropicSchema
- override_providers!: anthropic now uses AnthropicSchema() + /v1 stripped base URL - openai stays ChatCompletionSchema() on full base URL - Add mutate regression test: schema type, base_url, cache_control emission
1 parent a3df1b2 commit 3c4550a

2 files changed

Lines changed: 58 additions & 14 deletions

File tree

src/OpenRouterCLIProxyAPI.jl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,27 @@ Set `gemini=true` to also override google-ai-studio.
169169
"""
170170
function override_providers!(base_url::String, api_key_env_var::String;
171171
gemini::Bool=false, verbose::Bool=false)
172-
schemas = Dict("anthropic" => ChatCompletionAnthropicSchema(), "openai" => ChatCompletionSchema())
173-
for name in ("anthropic", "openai")
174-
set_provider!(
175-
name,
176-
base_url,
177-
"Bearer",
178-
api_key_env_var,
179-
Dict{String,String}(),
180-
cli_proxy_model_transform,
181-
schemas[name],
182-
"$name (overridden to cli_proxy_api)"
183-
)
184-
end
172+
anthropic_base_url = replace(base_url, r"/v1/?$" => "")
173+
set_provider!(
174+
"anthropic",
175+
anthropic_base_url,
176+
"Bearer",
177+
api_key_env_var,
178+
Dict{String,String}(),
179+
cli_proxy_model_transform,
180+
AnthropicSchema(),
181+
"anthropic (overridden to cli_proxy_api)"
182+
)
183+
set_provider!(
184+
"openai",
185+
base_url,
186+
"Bearer",
187+
api_key_env_var,
188+
Dict{String,String}(),
189+
cli_proxy_model_transform,
190+
ChatCompletionSchema(),
191+
"openai (overridden to cli_proxy_api)"
192+
)
185193

186194
if gemini
187195
google_proxy_transform(id::AbstractString) = replace(id, r"^google/" => "")

test/runtests.jl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
using OpenRouterCLIProxyAPI
22
using Test
33
using Aqua
4+
using OpenRouter
5+
using OpenRouter: AnthropicSchema, ChatCompletionSchema, build_payload, get_provider_info, set_provider!
6+
7+
function restore_provider!(name::String, info)
8+
set_provider!(
9+
name,
10+
info.base_url,
11+
info.auth_header_format,
12+
info.api_key_env_var,
13+
copy(info.default_headers),
14+
info.model_name_transform,
15+
info.schema,
16+
info.notes,
17+
)
18+
end
419

520
@testset "OpenRouterCLIProxyAPI.jl" begin
621
@testset "Code quality (Aqua.jl)" begin
722
# Aqua.test_all(OpenRouterCLIProxyAPI)
823
end
9-
# Write your tests here.
24+
25+
@testset "mutate keeps Anthropic native request shape for caching" begin
26+
original = Dict(name => get_provider_info(name) for name in ("anthropic", "openai", "google-ai-studio"))
27+
28+
try
29+
setup_cli_proxy!(; mutate=true, base_url="http://localhost:8317/v1")
30+
31+
anthropic = get_provider_info("anthropic")
32+
openai = get_provider_info("openai")
33+
34+
@test anthropic.schema isa AnthropicSchema
35+
@test anthropic.base_url == "http://localhost:8317"
36+
@test openai.schema isa ChatCompletionSchema
37+
@test openai.base_url == "http://localhost:8317/v1"
38+
@test build_payload(anthropic.schema, "hello", "claude-3-5-haiku-20241022", nothing, false; cache=:last)["messages"][1]["content"][1]["cache_control"] == Dict("type" => "ephemeral")
39+
finally
40+
for (name, info) in original
41+
set_provider!(name, info.base_url, info.auth_header_format, info.api_key_env_var,
42+
copy(info.default_headers), info.model_name_transform, info.schema, info.notes)
43+
end
44+
end
45+
end
1046
end

0 commit comments

Comments
 (0)