UNPKG

@justinechang39/maki

Version:

AI-powered CLI agent for file operations, CSV manipulation, todo management, and web content fetching using OpenRouter

98 lines (97 loc) 3 kB
import { SELECTED_MODEL } from './config.js'; import { SYSTEM_PROMPT } from './system-prompt.js'; /** * Creates cache-optimized system message based on model type * * For different models: * - Gemini: Implicit caching (automatic) - no special handling needed * - OpenAI: Automatic caching - no special handling needed * - Anthropic: Explicit cache_control required for large prompts */ export function createCacheOptimizedSystemMessage() { // For Anthropic models, use explicit cache control on the system prompt // since it's large and static across conversations if (SELECTED_MODEL.includes('anthropic')) { return { role: 'system', content: [ { type: 'text', text: SYSTEM_PROMPT, cache_control: { type: 'ephemeral' } } ] }; } // For Gemini and OpenAI, use standard format - they handle caching automatically return { role: 'system', content: SYSTEM_PROMPT }; } /** * Creates cache-optimized user message for large content * Useful for RAG data, large CSV files, or extensive context */ export function createCacheOptimizedUserMessage(content, largeContext) { if (!largeContext) { return { role: 'user', content: content }; } // For Anthropic models with large context, cache the context if (SELECTED_MODEL.includes('anthropic')) { return { role: 'user', content: [ { type: 'text', text: content }, { type: 'text', text: largeContext, cache_control: { type: 'ephemeral' } } ] }; } // For other models, combine normally - they handle implicit caching return { role: 'user', content: `${content}\n\n${largeContext}` }; } /** * Gets cache optimization info for current model */ export function getCacheInfo() { if (SELECTED_MODEL.includes('gemini')) { return { type: 'implicit', description: 'Automatic caching (0.25x cost for cached tokens)', minTokens: SELECTED_MODEL.includes('2.5-pro') ? 2048 : 1028 }; } if (SELECTED_MODEL.includes('openai') || SELECTED_MODEL.includes('gpt')) { return { type: 'implicit', description: 'Automatic caching (0.5x-0.75x cost for cached tokens)', minTokens: 1024 }; } if (SELECTED_MODEL.includes('anthropic')) { return { type: 'explicit', description: 'Manual cache control (0.1x reads, 1.25x writes)', minTokens: 1024, maxBreakpoints: 4, ttl: '5 minutes' }; } return { type: 'none', description: 'No caching support detected' }; }