mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(coding-agent): add prompt cache warming (#9668)
This commit is contained in:
parent
7d5eb0ee3b
commit
c596d09d9c
32 changed files with 1380 additions and 69 deletions
|
|
@ -20,6 +20,7 @@ import type {
|
|||
KnownProvider,
|
||||
Model,
|
||||
ModelCost,
|
||||
ModelPromptCache,
|
||||
OpenAICompletionsCompat,
|
||||
OpenAIResponsesCompat,
|
||||
} from "../src/types.ts";
|
||||
|
|
@ -931,6 +932,21 @@ function applyOpenAIExplicitPromptCacheMetadata(model: Model<Api>): void {
|
|||
};
|
||||
}
|
||||
|
||||
// Anthropic ephemeral entries have a hard five-minute lifetime; `ttl: "1h"`
|
||||
// extends it to one hour. Only direct Anthropic is annotated so cache warming
|
||||
// does not assume equivalent behavior through proxies.
|
||||
// https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
||||
const ANTHROPIC_PROMPT_CACHE: ModelPromptCache = { short: 300, long: 3600 };
|
||||
|
||||
function applyPromptCacheMetadata(model: Model<Api>): void {
|
||||
if (model.provider === "anthropic" && model.api === "anthropic-messages") {
|
||||
model.promptCache = ANTHROPIC_PROMPT_CACHE;
|
||||
}
|
||||
// Do not add OpenAI lifetimes yet. Before enabling warming for explicit
|
||||
// OpenAI caches, re-evaluate it using observed expiry, replay, and billing
|
||||
// behavior; a documented TTL alone does not establish full cache loss.
|
||||
}
|
||||
|
||||
function isGemma4Model(modelId: string): boolean {
|
||||
return /gemma-?4/.test(modelId.toLowerCase());
|
||||
}
|
||||
|
|
@ -3055,6 +3071,7 @@ async function generateModels() {
|
|||
applyOpenAICompletionsTranscriptMetadata(model);
|
||||
applyOpenAIResponsesTranscriptMetadata(model);
|
||||
applyOpenAIExplicitPromptCacheMetadata(model);
|
||||
applyPromptCacheMetadata(model);
|
||||
}
|
||||
applyAnthropicAllowedFallbackModelMetadata(allModels.filter(isAnthropicFallbackMetadataModel));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue