mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-08 03:07:53 +00:00
fix(bedrock): exclude temperature for Opus 4.7 and add test coverage
- Add supportsTemperature: false to Opus 4.7 model definition
- Conditionally exclude temperature from inferenceConfig when unsupported
- Add tests for adaptive thinking and temperature exclusion
Ported from PR #12288 commits a682355 and c2274d8
This commit is contained in:
parent
ba20c0d3d4
commit
12c4471d64
3 changed files with 113 additions and 2 deletions
|
|
@ -173,6 +173,7 @@ export const bedrockModels = {
|
|||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoningBudget: true,
|
||||
supportsTemperature: false,
|
||||
inputPrice: 5.0, // $5 per million input tokens (≤200K context)
|
||||
outputPrice: 25.0, // $25 per million output tokens (≤200K context)
|
||||
cacheWritesPrice: 6.25, // $6.25 per million tokens
|
||||
|
|
|
|||
|
|
@ -282,6 +282,110 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
|
|||
expect(reasoningChunks[1].text).toBe(" about this problem.")
|
||||
})
|
||||
|
||||
it("should use adaptive thinking for Opus 4.7 instead of enabled with budget_tokens", async () => {
|
||||
handler = new AwsBedrockHandler({
|
||||
apiProvider: "bedrock",
|
||||
apiModelId: "anthropic.claude-opus-4-7",
|
||||
awsRegion: "us-east-1",
|
||||
enableReasoningEffort: true,
|
||||
modelMaxTokens: 8192,
|
||||
modelMaxThinkingTokens: 4096,
|
||||
})
|
||||
|
||||
mockSend.mockResolvedValue({
|
||||
stream: (async function* () {
|
||||
yield { messageStart: { role: "assistant" } }
|
||||
yield {
|
||||
contentBlockStart: {
|
||||
content_block: { type: "thinking", thinking: "Thinking adaptively..." },
|
||||
contentBlockIndex: 0,
|
||||
},
|
||||
}
|
||||
yield { metadata: { usage: { inputTokens: 100, outputTokens: 50 } } }
|
||||
})(),
|
||||
})
|
||||
|
||||
const messages = [{ role: "user" as const, content: "Test message" }]
|
||||
const stream = handler.createMessage("System prompt", messages)
|
||||
|
||||
const chunks = []
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk)
|
||||
}
|
||||
|
||||
// Opus 4.7 must use thinking.type: "adaptive" with output_config.effort
|
||||
expect(mockSend).toHaveBeenCalledTimes(1)
|
||||
expect(capturedPayload).toBeDefined()
|
||||
expect(capturedPayload.additionalModelRequestFields).toBeDefined()
|
||||
expect(capturedPayload.additionalModelRequestFields.thinking).toEqual({
|
||||
type: "adaptive",
|
||||
})
|
||||
expect(capturedPayload.additionalModelRequestFields.output_config).toEqual({
|
||||
effort: "high",
|
||||
})
|
||||
|
||||
// Must NOT have budget_tokens (causes 400 error on Opus 4.7)
|
||||
expect(capturedPayload.additionalModelRequestFields.thinking).not.toHaveProperty("budget_tokens")
|
||||
})
|
||||
|
||||
it("should exclude temperature from inferenceConfig for Opus 4.7 (supportsTemperature: false)", async () => {
|
||||
handler = new AwsBedrockHandler({
|
||||
apiProvider: "bedrock",
|
||||
apiModelId: "anthropic.claude-opus-4-7",
|
||||
awsRegion: "us-east-1",
|
||||
modelTemperature: 0.7,
|
||||
})
|
||||
|
||||
mockSend.mockResolvedValue({
|
||||
stream: (async function* () {
|
||||
yield { messageStart: { role: "assistant" } }
|
||||
yield { metadata: { usage: { inputTokens: 100, outputTokens: 50 } } }
|
||||
})(),
|
||||
})
|
||||
|
||||
const messages = [{ role: "user" as const, content: "Test message" }]
|
||||
const stream = handler.createMessage("System prompt", messages)
|
||||
|
||||
for await (const chunk of stream) {
|
||||
// consume stream
|
||||
}
|
||||
|
||||
expect(mockSend).toHaveBeenCalledTimes(1)
|
||||
expect(capturedPayload).toBeDefined()
|
||||
// Temperature must NOT be present for Opus 4.7
|
||||
expect(capturedPayload.inferenceConfig).not.toHaveProperty("temperature")
|
||||
// maxTokens should still be present
|
||||
expect(capturedPayload.inferenceConfig).toHaveProperty("maxTokens")
|
||||
})
|
||||
|
||||
it("should include temperature in inferenceConfig for models that support it", async () => {
|
||||
handler = new AwsBedrockHandler({
|
||||
apiProvider: "bedrock",
|
||||
apiModelId: "anthropic.claude-sonnet-4-20250514-v1:0",
|
||||
awsRegion: "us-east-1",
|
||||
modelTemperature: 0.5,
|
||||
})
|
||||
|
||||
mockSend.mockResolvedValue({
|
||||
stream: (async function* () {
|
||||
yield { messageStart: { role: "assistant" } }
|
||||
yield { metadata: { usage: { inputTokens: 100, outputTokens: 50 } } }
|
||||
})(),
|
||||
})
|
||||
|
||||
const messages = [{ role: "user" as const, content: "Test message" }]
|
||||
const stream = handler.createMessage("System prompt", messages)
|
||||
|
||||
for await (const chunk of stream) {
|
||||
// consume stream
|
||||
}
|
||||
|
||||
expect(mockSend).toHaveBeenCalledTimes(1)
|
||||
expect(capturedPayload).toBeDefined()
|
||||
// Temperature should be present for Sonnet 4
|
||||
expect(capturedPayload.inferenceConfig).toHaveProperty("temperature", 0.5)
|
||||
})
|
||||
|
||||
it("should support API key authentication", async () => {
|
||||
handler = new AwsBedrockHandler({
|
||||
apiProvider: "bedrock",
|
||||
|
|
|
|||
|
|
@ -431,7 +431,10 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
|
|||
|
||||
const inferenceConfig: BedrockInferenceConfig = {
|
||||
maxTokens: modelConfig.maxTokens || (modelConfig.info.maxTokens as number),
|
||||
temperature: modelConfig.temperature ?? (this.options.modelTemperature as number),
|
||||
// Only include temperature if the model supports it (Opus 4.7 deprecated temperature)
|
||||
...(modelConfig.info.supportsTemperature !== false && {
|
||||
temperature: modelConfig.temperature ?? (this.options.modelTemperature as number),
|
||||
}),
|
||||
}
|
||||
|
||||
// Check if 1M context is enabled for supported Claude 4 models
|
||||
|
|
@ -769,7 +772,10 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
|
|||
|
||||
const inferenceConfig: BedrockInferenceConfig = {
|
||||
maxTokens: modelConfig.maxTokens || (modelConfig.info.maxTokens as number),
|
||||
temperature: modelConfig.temperature ?? (this.options.modelTemperature as number),
|
||||
// Only include temperature if the model supports it (Opus 4.7 deprecated temperature)
|
||||
...(modelConfig.info.supportsTemperature !== false && {
|
||||
temperature: modelConfig.temperature ?? (this.options.modelTemperature as number),
|
||||
}),
|
||||
}
|
||||
|
||||
// For completePrompt, use a unique conversation ID based on the prompt
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue