UNPKG

capsule-ai-cli

Version:

The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing

60 lines (57 loc) 2.21 kB
import { providerRegistry } from '../providers/base.js'; import { stateService } from './state.js'; import chalk from 'chalk'; export class SummarizerService { async summarizeMessages(messages) { let conversationText = ''; messages.forEach(msg => { if (msg.role === 'user' || msg.role === 'assistant') { const content = typeof msg.content === 'string' ? msg.content : '[multimodal content]'; const truncatedContent = content.length > 500 ? content.substring(0, 500) + '...' : content; conversationText += `${msg.role.toUpperCase()}: ${truncatedContent}\n\n`; } }); const summaryPrompt = `Please create a concise summary of the following conversation. Focus on preserving: 1. Key topics discussed 2. Important decisions or conclusions 3. Any action items or next steps 4. Technical details that might be referenced later Keep the summary under 500 words and structure it clearly. Conversation: ${conversationText} Summary:`; try { const providerName = stateService.getProvider(); const modelName = stateService.getModel(); const provider = providerRegistry.get(providerName); if (!provider) { throw new Error(`Provider ${providerName} not initialized`); } const messages = [ { role: 'system', content: 'You are a helpful assistant that creates concise summaries of conversations.' }, { role: 'user', content: summaryPrompt } ]; const response = await provider.complete(messages, { model: modelName, temperature: 0.3, maxTokens: 1000 }); return response.content; } catch (error) { console.log(chalk.yellow('\nFailed to create AI summary, error:', error)); throw error; } } } export const summarizerService = new SummarizerService(); //# sourceMappingURL=summarizer.js.map