mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 05:45:04 +03:00
feat(cache): add OpenAI prompt_cache_key and Gemini cachedContent support
Provider-specific caching enhancements:
OpenAI:
- Auto-generate prompt_cache_key from message prefix hash
- Key format: omni-{prefix_hash_32chars}
- Preserves client-provided keys (doesn't override)
Gemini:
- Preserve cachedContent ID if provided by client
- Enables explicit Gemini caching for long prompts
- cachedContentTokenCount already tracked in responses
This commit is contained in:
@@ -1 +1 @@
|
||||
export { analyzePrefix, shouldInjectCacheControl } from "./prefixAnalyzer";
|
||||
export { analyzePrefix, shouldInjectCacheControl, generatePromptCacheKey } from "./prefixAnalyzer";
|
||||
|
||||
@@ -75,3 +75,11 @@ export function analyzePrefix(messages: Message[]): PrefixAnalysis {
|
||||
export function shouldInjectCacheControl(analysis: PrefixAnalysis, minTokens = 1024): boolean {
|
||||
return analysis.prefixTokens >= minTokens && analysis.confidence >= 0.7;
|
||||
}
|
||||
|
||||
export function generatePromptCacheKey(messages: Message[]): string {
|
||||
const analysis = analyzePrefix(messages);
|
||||
if (analysis.prefixHash) {
|
||||
return `omni-${analysis.prefixHash.slice(0, 32)}`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user