fix: apply content-level caching for non-anthropic providers (#1305)
This commit is contained in:
committed by
GitHub
parent
613b5fbe48
commit
827469c725
@@ -7,9 +7,7 @@ export namespace ProviderTransform {
|
|||||||
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
|
||||||
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
|
||||||
|
|
||||||
for (const msg of unique([...system, ...final])) {
|
const providerOptions = {
|
||||||
msg.providerOptions = {
|
|
||||||
...msg.providerOptions,
|
|
||||||
anthropic: {
|
anthropic: {
|
||||||
cacheControl: { type: "ephemeral" },
|
cacheControl: { type: "ephemeral" },
|
||||||
},
|
},
|
||||||
@@ -23,6 +21,25 @@ export namespace ProviderTransform {
|
|||||||
cache_control: { type: "ephemeral" },
|
cache_control: { type: "ephemeral" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const msg of unique([...system, ...final])) {
|
||||||
|
const shouldUseContentOptions = providerID !== "anthropic" && Array.isArray(msg.content) && msg.content.length > 0
|
||||||
|
|
||||||
|
if (shouldUseContentOptions) {
|
||||||
|
const lastContent = msg.content[msg.content.length - 1]
|
||||||
|
if (lastContent && typeof lastContent === "object") {
|
||||||
|
lastContent.providerOptions = {
|
||||||
|
...lastContent.providerOptions,
|
||||||
|
...providerOptions,
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.providerOptions = {
|
||||||
|
...msg.providerOptions,
|
||||||
|
...providerOptions,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return msgs
|
return msgs
|
||||||
|
|||||||
Reference in New Issue
Block a user