feat(bedrock): Add token caching for any amazon-bedrock provider (#18959)
parent
bc608fb081
commit
024979f3fd
|
|
@ -194,7 +194,10 @@ export namespace ProviderTransform {
|
|||
}
|
||||
|
||||
for (const msg of unique([...system, ...final])) {
|
||||
const useMessageLevelOptions = model.providerID === "anthropic" || model.providerID.includes("bedrock")
|
||||
const useMessageLevelOptions =
|
||||
model.providerID === "anthropic" ||
|
||||
model.providerID.includes("bedrock") ||
|
||||
model.api.npm === "@ai-sdk/amazon-bedrock"
|
||||
const shouldUseContentOptions = !useMessageLevelOptions && Array.isArray(msg.content) && msg.content.length > 0
|
||||
|
||||
if (shouldUseContentOptions) {
|
||||
|
|
|
|||
|
|
@ -1629,6 +1629,43 @@ describe("ProviderTransform.message - claude w/bedrock custom inference profile"
|
|||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.message - bedrock caching with non-bedrock providerID", () => {
|
||||
test("applies cache options at message level when npm package is amazon-bedrock", () => {
|
||||
const model = {
|
||||
id: "aws/us.anthropic.claude-opus-4-6-v1",
|
||||
providerID: "aws",
|
||||
api: {
|
||||
id: "us.anthropic.claude-opus-4-6-v1",
|
||||
url: "https://bedrock-runtime.us-east-1.amazonaws.com",
|
||||
npm: "@ai-sdk/amazon-bedrock",
|
||||
},
|
||||
name: "Claude Opus 4.6",
|
||||
capabilities: {},
|
||||
options: {},
|
||||
headers: {},
|
||||
} as any
|
||||
|
||||
const msgs = [
|
||||
{
|
||||
role: "system",
|
||||
content: [{ type: "text", text: "You are a helpful assistant" }],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [{ type: "text", text: "Hello" }],
|
||||
},
|
||||
] as any[]
|
||||
|
||||
const result = ProviderTransform.message(msgs, model, {}) as any[]
|
||||
|
||||
// Cache should be at the message level and not the content-part level
|
||||
expect(result[0].providerOptions?.bedrock).toEqual({
|
||||
cachePoint: { type: "default" },
|
||||
})
|
||||
expect(result[0].content[0].providerOptions?.bedrock).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.message - cache control on gateway", () => {
|
||||
const createModel = (overrides: Partial<any> = {}) =>
|
||||
({
|
||||
|
|
|
|||
Loading…
Reference in New Issue