Skip to content

Commit 9396cbf

Browse files
committed
feat: handle Opus 4.7 unsupported sampling params (temperature/topP/topK)
- Add noSamplingParams flag to FeatureFlags - Add CLAUDE_OPUS_4_7_DEFAULT_PARAMS without temperature - Add model entries for global/us.anthropic.claude-opus-4-7 - Strip temperature/topP from inferenceConfig for noSamplingParams models - Add prompt caching support for Opus 4.7
1 parent 8da008f commit 9396cbf

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

packages/cdk/lambda/utils/models.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ const CLAUDE_OPUS_4_6_DEFAULT_PARAMS: ConverseInferenceParams = {
137137
},
138138
};
139139

140+
const CLAUDE_OPUS_4_7_DEFAULT_PARAMS: ConverseInferenceParams = {
141+
inferenceConfig: {
142+
maxTokens: 128000,
143+
},
144+
};
145+
140146
const CLAUDE_SONNET_4_6_DEFAULT_PARAMS: ConverseInferenceParams = {
141147
inferenceConfig: {
142148
maxTokens: 64000,
@@ -504,7 +510,9 @@ const createConverseCommandInput = (
504510
modelId: model.modelId,
505511
messages: conversationWithCache,
506512
system: systemContextWithCache,
507-
inferenceConfig: params.inferenceConfig,
513+
inferenceConfig: modelMetadata[model.modelId].flags.noSamplingParams
514+
? { maxTokens: params.inferenceConfig?.maxTokens }
515+
: params.inferenceConfig,
508516
guardrailConfig,
509517
};
510518

@@ -513,9 +521,10 @@ const createConverseCommandInput = (
513521
(model.modelParameters?.reasoningConfig?.type === 'enabled' ||
514522
model.modelParameters?.reasoningConfig?.type === 'adaptive')
515523
) {
524+
const noSampling = modelMetadata[model.modelId].flags.noSamplingParams;
516525
converseCommandInput.inferenceConfig = {
517526
...params.inferenceConfig,
518-
temperature: 1, // reasoning requires temperature to be 1
527+
temperature: noSampling ? undefined : 1, // reasoning requires temperature to be 1, but some models don't support it
519528
topP: undefined, // reasoning does not require topP
520529
maxTokens: params.inferenceConfig?.maxTokens,
521530
};
@@ -989,6 +998,22 @@ export const BEDROCK_TEXT_GEN_MODELS: {
989998
extractConverseStreamOutput: (body: ConverseStreamOutput) => StreamingChunk;
990999
};
9911000
} = {
1001+
'global.anthropic.claude-opus-4-7': {
1002+
defaultParams: CLAUDE_OPUS_4_7_DEFAULT_PARAMS,
1003+
usecaseParams: USECASE_DEFAULT_PARAMS,
1004+
createConverseCommandInput: createConverseCommandInput,
1005+
createConverseStreamCommandInput: createConverseStreamCommandInput,
1006+
extractConverseOutput: extractConverseOutput,
1007+
extractConverseStreamOutput: extractConverseStreamOutput,
1008+
},
1009+
'us.anthropic.claude-opus-4-7': {
1010+
defaultParams: CLAUDE_OPUS_4_7_DEFAULT_PARAMS,
1011+
usecaseParams: USECASE_DEFAULT_PARAMS,
1012+
createConverseCommandInput: createConverseCommandInput,
1013+
createConverseStreamCommandInput: createConverseStreamCommandInput,
1014+
extractConverseOutput: extractConverseOutput,
1015+
extractConverseStreamOutput: extractConverseStreamOutput,
1016+
},
9921017
'global.anthropic.claude-opus-4-6-v1': {
9931018
defaultParams: CLAUDE_OPUS_4_6_DEFAULT_PARAMS,
9941019
usecaseParams: USECASE_DEFAULT_PARAMS,

packages/common/src/application/model.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ const MODEL_FEATURE: Record<string, FeatureFlags> = {
4848
reasoning: true,
4949
adaptiveThinking: true,
5050
},
51+
TEXT_DOC_IMAGE_ADAPTIVE_THINKING_NO_SAMPLING: {
52+
text: true,
53+
doc: true,
54+
image: true,
55+
video: false,
56+
reasoning: true,
57+
adaptiveThinking: true,
58+
noSamplingParams: true,
59+
},
5160
TEXT_DOC_IMAGE_VIDEO: { text: true, doc: true, image: true, video: true },
5261
IMAGE_GEN: { image_gen: true },
5362
VIDEO_GEN: { video_gen: true },
@@ -110,11 +119,11 @@ export const modelMetadata: Record<string, ModelMetadata> = {
110119
displayName: 'Claude Opus 4',
111120
},
112121
'global.anthropic.claude-opus-4-7': {
113-
flags: MODEL_FEATURE.TEXT_DOC_IMAGE_ADAPTIVE_THINKING,
122+
flags: MODEL_FEATURE.TEXT_DOC_IMAGE_ADAPTIVE_THINKING_NO_SAMPLING,
114123
displayName: 'Claude Opus 4.7',
115124
},
116125
'us.anthropic.claude-opus-4-7': {
117-
flags: MODEL_FEATURE.TEXT_DOC_IMAGE_ADAPTIVE_THINKING,
126+
flags: MODEL_FEATURE.TEXT_DOC_IMAGE_ADAPTIVE_THINKING_NO_SAMPLING,
118127
displayName: 'Claude Opus 4.7',
119128
},
120129
'global.anthropic.claude-opus-4-6-v1': {
@@ -735,6 +744,7 @@ export const BEDROCK_SPEECH_TO_SPEECH_MODELS = Object.keys(
735744
// Prompt caching
736745
// https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
737746
export const SUPPORTED_CACHE_FIELDS: Record<string, PromptCacheField[]> = {
747+
'anthropic.claude-opus-4-7': ['messages', 'system', 'tools'],
738748
'anthropic.claude-opus-4-6-v1': ['messages', 'system', 'tools'],
739749
'anthropic.claude-sonnet-4-6': ['messages', 'system', 'tools'],
740750
'anthropic.claude-opus-4-5-20251101-v1:0': ['messages', 'system', 'tools'],

packages/types/src/model.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type FeatureFlags = {
77
video?: boolean;
88
reasoning?: boolean;
99
adaptiveThinking?: boolean;
10+
noSamplingParams?: boolean;
1011

1112
image_gen?: boolean;
1213
video_gen?: boolean;

0 commit comments

Comments
 (0)