diff options
Diffstat (limited to 'src/config_file.zig')
| -rw-r--r-- | src/config_file.zig | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/config_file.zig b/src/config_file.zig index 229a5b2..e5bbe99 100644 --- a/src/config_file.zig +++ b/src/config_file.zig @@ -146,6 +146,10 @@ pub fn buildProviderConfig( .model = wire_model, .api_version = if (def_opt) |d| (d.api_version orelse "2023-06-01") else "2023-06-01", .max_tokens = max_tokens, + .thinking = if (def_opt) |d| d.thinking else .enabled, + .effort = if (def_opt) |d| d.effort else .medium, + .thinking_budget_tokens = if (def_opt) |d| d.thinking_budget_tokens else 32_000, + .thinking_interleaved = if (def_opt) |d| d.thinking_interleaved else false, } }, } } @@ -911,6 +915,10 @@ test "buildProviderConfig: anthropic ref pulls knobs from model defs" { .reasoning = .high, .max_tokens = 8192, .api_version = try a.dupe(u8, "2023-06-01"), + .thinking = .enabled, + .effort = .medium, + .thinking_budget_tokens = 16_000, + .thinking_interleaved = false, }); const ref = try parseModelRef("anthropic:sonnet"); @@ -919,6 +927,10 @@ test "buildProviderConfig: anthropic ref pulls knobs from model defs" { try testing.expectEqualStrings("claude-sonnet-4-20250514", pc.anthropic_messages.model); try testing.expectEqual(@as(u32, 8192), pc.anthropic_messages.max_tokens); try testing.expectEqualStrings("sk-ant", pc.anthropic_messages.api_key); + try testing.expectEqual(panto.Thinking.enabled, pc.anthropic_messages.thinking); + try testing.expectEqual(panto.Effort.medium, pc.anthropic_messages.effort); + try testing.expectEqual(@as(?u32, 16_000), pc.anthropic_messages.thinking_budget_tokens); + try testing.expectEqual(false, pc.anthropic_messages.thinking_interleaved); } test "buildProviderConfig: missing alias uses the alias verbatim as wire model" { @@ -947,6 +959,75 @@ test "buildProviderConfig: missing alias uses the alias verbatim as wire model" try testing.expectEqual(panto.ReasoningEffort.default, pc.openai_chat.reasoning); } +test "buildProviderConfig: anthropic adaptive thinking threaded from model def" { + const a = testing.allocator; + var env = emptyEnv(a); + defer env.deinit(); + try env.put("ANTHROPIC_API_KEY", "sk-ant"); + + const src = + \\[providers.anthropic] + \\style = "anthropic_messages" + \\base_url = "https://api.anthropic.com" + \\api_key_env_var = "ANTHROPIC_API_KEY" + ; + const doc = try parseDoc(a, src); + defer doc.deinit(); + var cfg = try resolve(a, &env, doc.root); + defer cfg.deinit(); + + var models = models_toml.ModelRegistry.init(a); + defer models.deinit(); + try models.entries.append(a, .{ + .provider = try a.dupe(u8, "anthropic"), + .alias = try a.dupe(u8, "opus"), + .model = try a.dupe(u8, "claude-opus-4-8"), + .reasoning = .default, + .max_tokens = null, + .api_version = null, + .thinking = .adaptive, + .effort = .high, + .thinking_budget_tokens = null, + .thinking_interleaved = false, + }); + + const ref = try parseModelRef("anthropic:opus"); + const pc = try buildProviderConfig(&cfg, &models, ref); + try testing.expectEqual(panto.Thinking.adaptive, pc.anthropic_messages.thinking); + try testing.expectEqual(panto.Effort.high, pc.anthropic_messages.effort); + try testing.expectEqual(@as(?u32, null), pc.anthropic_messages.thinking_budget_tokens); +} + +test "buildProviderConfig: anthropic missing alias falls back to struct defaults" { + const a = testing.allocator; + var env = emptyEnv(a); + defer env.deinit(); + try env.put("ANTHROPIC_API_KEY", "sk-ant"); + + const src = + \\[providers.anthropic] + \\style = "anthropic_messages" + \\base_url = "https://api.anthropic.com" + \\api_key_env_var = "ANTHROPIC_API_KEY" + ; + const doc = try parseDoc(a, src); + defer doc.deinit(); + var cfg = try resolve(a, &env, doc.root); + defer cfg.deinit(); + + var models = models_toml.ModelRegistry.init(a); + defer models.deinit(); + + // No model def at all — alias used verbatim, defaults applied. + const ref = try parseModelRef("anthropic:claude-haiku-4-5-20251001"); + const pc = try buildProviderConfig(&cfg, &models, ref); + try testing.expectEqual(APIStyle.anthropic_messages, pc.style()); + try testing.expectEqual(panto.Thinking.enabled, pc.anthropic_messages.thinking); + try testing.expectEqual(panto.Effort.medium, pc.anthropic_messages.effort); + try testing.expectEqual(@as(?u32, 32_000), pc.anthropic_messages.thinking_budget_tokens); + try testing.expectEqual(false, pc.anthropic_messages.thinking_interleaved); +} + test "buildProviderConfig: unknown provider errors" { const a = testing.allocator; var env = emptyEnv(a); |
