From 3058acae73136f392aaf778d38192c66077b801a Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Thu, 18 Dec 2025 13:42:20 +0000 Subject: [PATCH] feat(anthropic): effort param and testapp --- js/plugins/anthropic/src/models.ts | 9 ++- js/plugins/anthropic/src/runner/beta.ts | 8 ++- js/testapps/anthropic/package.json | 1 + js/testapps/anthropic/src/beta/effort.ts | 79 ++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 js/testapps/anthropic/src/beta/effort.ts diff --git a/js/plugins/anthropic/src/models.ts b/js/plugins/anthropic/src/models.ts index 9ba8129ef1..d9359e01b1 100644 --- a/js/plugins/anthropic/src/models.ts +++ b/js/plugins/anthropic/src/models.ts @@ -123,7 +123,14 @@ export const KNOWN_CLAUDE_MODELS: Record< ), 'claude-opus-4-5': commonRef( 'claude-opus-4-5', - AnthropicThinkingConfigSchema, + AnthropicThinkingConfigSchema.extend({ + output_config: z + .object({ + effort: z.enum(['low', 'medium', 'high']).optional(), + }) + .passthrough() + .optional(), + }), { supports: { multiturn: true, diff --git a/js/plugins/anthropic/src/runner/beta.ts b/js/plugins/anthropic/src/runner/beta.ts index 9fd7a306a1..76b07bdaac 100644 --- a/js/plugins/anthropic/src/runner/beta.ts +++ b/js/plugins/anthropic/src/runner/beta.ts @@ -84,7 +84,7 @@ const BETA_APIS = [ // 'context-management-2025-06-27', // 'model-context-window-exceeded-2025-08-26', // 'skills-2025-10-02', - // 'effort-param-2025-11-24', + 'effort-2025-11-24', // 'advanced-tool-use-2025-11-20', 'structured-outputs-2025-11-13', ]; @@ -308,6 +308,9 @@ export class BetaRunner extends BaseRunner { }; if (betaSystem !== undefined) body.system = betaSystem; + if (request.config?.output_config !== undefined) + body.output_config = request.config + .output_config as BetaMessageCreateParamsNonStreaming['output_config']; if (request.config?.stopSequences !== undefined) body.stop_sequences = request.config.stopSequences; if (request.config?.temperature !== undefined) @@ -379,6 +382,9 @@ export class BetaRunner extends BaseRunner { }; if (betaSystem !== undefined) body.system = betaSystem; + if (request.config?.output_config !== undefined) + body.output_config = request.config + .output_config as BetaMessageCreateParamsStreaming['output_config']; if (request.config?.stopSequences !== undefined) body.stop_sequences = request.config.stopSequences; if (request.config?.temperature !== undefined) diff --git a/js/testapps/anthropic/package.json b/js/testapps/anthropic/package.json index 08e1a0d2fd..cbd26f79c9 100644 --- a/js/testapps/anthropic/package.json +++ b/js/testapps/anthropic/package.json @@ -10,6 +10,7 @@ "start:beta": "node lib/beta/basic.js", "dev:stable": "genkit start -- npx tsx --watch src/stable/basic.ts", "dev:beta": "genkit start -- npx tsx --watch src/beta/basic.ts", + "dev:beta:effort": "genkit start -- npx tsx --watch src/beta/effort.ts", "dev:stable:text-plain": "genkit start -- npx tsx --watch src/stable/text-plain.ts", "dev:stable:webp": "genkit start -- npx tsx --watch src/stable/webp.ts", "dev:stable:pdf": "genkit start -- npx tsx --watch src/stable/pdf.ts", diff --git a/js/testapps/anthropic/src/beta/effort.ts b/js/testapps/anthropic/src/beta/effort.ts new file mode 100644 index 0000000000..03e83a60af --- /dev/null +++ b/js/testapps/anthropic/src/beta/effort.ts @@ -0,0 +1,79 @@ +/** + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { anthropic } from '@genkit-ai/anthropic'; +import { genkit } from 'genkit'; + +const ai = genkit({ + plugins: [ + // Default all flows in this sample to the beta surface + anthropic({ + apiVersion: 'beta', + cacheSystemPrompt: true, + apiKey: process.env.ANTHROPIC_API_KEY, + }), + ], +}); + +const betaOpus45 = anthropic.model('claude-opus-4-5', { apiVersion: 'beta' }); + +ai.defineFlow('anthropic-beta-low-effort', async () => { + const { text } = await ai.generate({ + model: betaOpus45, + prompt: `Create me a Mathematics class using the programming language Python.`, + config: { + maxOutputTokens: 4096, + temperature: 0.6, + output_config: { + effort: 'low', + }, + }, + }); + + return text; +}); + +ai.defineFlow('anthropic-beta-medium-effort', async () => { + const { text } = await ai.generate({ + model: betaOpus45, + prompt: `Create me a Mathematics class using the programming language Python.`, + config: { + maxOutputTokens: 4096, + temperature: 0.6, + output_config: { + effort: 'medium', + }, + }, + }); + + return text; +}); + +ai.defineFlow('anthropic-beta-high-effort', async () => { + const { text } = await ai.generate({ + model: betaOpus45, + prompt: `Create me a Mathematics class using the programming language Python.`, + config: { + maxOutputTokens: 4096, + temperature: 0.6, + output_config: { + effort: 'high', + }, + }, + }); + + return text; +});