fix: improve xai cache hit rate (#35970)
This commit is contained in:
parent
f95f877e5f
commit
ccb6b7c3ea
9 changed files with 281 additions and 109 deletions
|
|
@ -73,7 +73,7 @@
|
|||
"@ai-sdk/provider": "3.0.8",
|
||||
"@ai-sdk/togetherai": "2.0.41",
|
||||
"@ai-sdk/vercel": "2.0.39",
|
||||
"@ai-sdk/xai": "3.0.82",
|
||||
"@ai-sdk/xai": "3.0.102",
|
||||
"@aws-sdk/credential-providers": "3.1057.0",
|
||||
"@clack/prompts": "1.0.0-alpha.1",
|
||||
"@effect/opentelemetry": "catalog:",
|
||||
|
|
|
|||
|
|
@ -1127,7 +1127,12 @@ export function options(input: {
|
|||
}
|
||||
}
|
||||
|
||||
if (input.model.providerID === "openai" || input.providerOptions?.setCacheKey) {
|
||||
if (
|
||||
input.providerOptions?.setCacheKey !== false &&
|
||||
(input.model.providerID === "openai" ||
|
||||
input.model.api.npm === "@ai-sdk/xai" ||
|
||||
input.providerOptions?.setCacheKey)
|
||||
) {
|
||||
result["promptCacheKey"] = input.sessionID
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ describe("ProviderTransform.options - setCacheKey", () => {
|
|||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should set promptCacheKey for openai provider regardless of setCacheKey", () => {
|
||||
test("should set promptCacheKey for openai provider by default", () => {
|
||||
const openaiModel = {
|
||||
...mockModel,
|
||||
providerID: "openai",
|
||||
|
|
@ -87,6 +87,56 @@ describe("ProviderTransform.options - setCacheKey", () => {
|
|||
expect(result.promptCacheKey).toBe(sessionID)
|
||||
})
|
||||
|
||||
test("should not set promptCacheKey for openai when explicitly disabled", () => {
|
||||
const openaiModel = {
|
||||
...mockModel,
|
||||
providerID: "openai",
|
||||
api: {
|
||||
id: "gpt-4",
|
||||
url: "https://api.openai.com",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options({
|
||||
model: openaiModel,
|
||||
sessionID,
|
||||
providerOptions: { setCacheKey: false },
|
||||
})
|
||||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should set promptCacheKey for the xAI SDK by default regardless of provider ID", () => {
|
||||
const xaiModel = {
|
||||
...mockModel,
|
||||
providerID: "custom-xai",
|
||||
api: {
|
||||
id: "grok-4",
|
||||
url: "https://api.x.ai",
|
||||
npm: "@ai-sdk/xai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options({ model: xaiModel, sessionID, providerOptions: {} })
|
||||
expect(result.promptCacheKey).toBe(sessionID)
|
||||
})
|
||||
|
||||
test("should not set promptCacheKey for the xAI SDK when explicitly disabled", () => {
|
||||
const xaiModel = {
|
||||
...mockModel,
|
||||
providerID: "xai",
|
||||
api: {
|
||||
id: "grok-4",
|
||||
url: "https://api.x.ai",
|
||||
npm: "@ai-sdk/xai",
|
||||
},
|
||||
}
|
||||
const result = ProviderTransform.options({
|
||||
model: xaiModel,
|
||||
sessionID,
|
||||
providerOptions: { setCacheKey: false },
|
||||
})
|
||||
expect(result.promptCacheKey).toBeUndefined()
|
||||
})
|
||||
|
||||
test("should set store=false for openai provider", () => {
|
||||
const openaiModel = {
|
||||
...mockModel,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue