feat(bedrock): Add token caching for any amazon-bedrock provider (#18959)
This commit is contained in:
@@ -194,7 +194,10 @@ export namespace ProviderTransform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const msg of unique([...system, ...final])) {
|
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
|
const shouldUseContentOptions = !useMessageLevelOptions && Array.isArray(msg.content) && msg.content.length > 0
|
||||||
|
|
||||||
if (shouldUseContentOptions) {
|
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", () => {
|
describe("ProviderTransform.message - cache control on gateway", () => {
|
||||||
const createModel = (overrides: Partial<any> = {}) =>
|
const createModel = (overrides: Partial<any> = {}) =>
|
||||||
({
|
({
|
||||||
|
|||||||
Reference in New Issue
Block a user