feat(ai): add chat-template thinking compat

closes #5673
This commit is contained in:
Armin Ronacher
2026-06-19 23:34:17 +02:00
parent 128330e36f
commit 8b97e75c6b
12 changed files with 248 additions and 8 deletions

View File

@@ -434,6 +434,43 @@ describe("ModelRegistry", () => {
expect(compat?.cacheControlFormat).toBe("anthropic");
});
test("compat schema accepts chat template thinking configuration", () => {
writeRawModelsJson({
demo: {
baseUrl: "https://example.com/v1",
apiKey: "DEMO_KEY",
api: "openai-completions",
models: [
{
id: "demo-model",
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 1000,
maxTokens: 100,
compat: {
thinkingFormat: "chat-template",
chatTemplateKwargs: {
preserve_thinking: true,
thinking: { $var: "thinking.enabled" },
},
},
},
],
},
});
const registry = ModelRegistry.create(authStorage, modelsJsonPath);
const compat = registry.find("demo", "demo-model")?.compat as OpenAICompletionsCompat | undefined;
expect(registry.getError()).toBeUndefined();
expect(compat?.thinkingFormat).toBe("chat-template");
expect(compat?.chatTemplateKwargs).toEqual({
preserve_thinking: true,
thinking: { $var: "thinking.enabled" },
});
});
test("compat schema accepts Anthropic eager tool input streaming flag", () => {
writeRawModelsJson({
demo: {