mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 18:24:21 +01:00
better amazon bedrock caching with anthropic models
This commit is contained in:
@@ -185,6 +185,7 @@ export namespace Provider {
|
|||||||
source,
|
source,
|
||||||
info,
|
info,
|
||||||
options,
|
options,
|
||||||
|
getModel,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,19 @@ export namespace ProviderTransform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (providerID === "amazon-bedrock" || modelID.includes("anthropic")) {
|
||||||
|
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
||||||
|
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
||||||
|
|
||||||
|
for (const msg of unique([...system, ...final])) {
|
||||||
|
msg.providerMetadata = {
|
||||||
|
...msg.providerMetadata,
|
||||||
|
bedrock: {
|
||||||
|
cachePoint: { type: "ephemeral" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -882,8 +882,12 @@ export namespace Session {
|
|||||||
reasoning: 0,
|
reasoning: 0,
|
||||||
cache: {
|
cache: {
|
||||||
write: (metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
|
write: (metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
|
||||||
|
// @ts-expect-error
|
||||||
|
metadata?.["bedrock"]?.["usage"]?.["cacheWriteInputTokens"] ??
|
||||||
0) as number,
|
0) as number,
|
||||||
read: (metadata?.["anthropic"]?.["cacheReadInputTokens"] ??
|
read: (metadata?.["anthropic"]?.["cacheReadInputTokens"] ??
|
||||||
|
// @ts-expect-error
|
||||||
|
metadata?.["bedrock"]?.["usage"]?.["cacheReadInputTokens"] ??
|
||||||
0) as number,
|
0) as number,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user