UNPKG

@tomisakae/tomibot

Version:

TomiBot - AI Chatbot CLI với Google Genkit. Một chatbot AI thông minh chạy trên command line với giao diện đẹp.

66 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseAIService = void 0; class BaseAIService { constructor(config, options = {}) { this.initialized = false; this.history = []; this.config = config; this.options = { retryAttempts: 3, retryDelay: 1000, enableLogging: true, ...options, }; } isReady() { return this.initialized && !!this.config.apiKey; } isInitialized() { return this.initialized; } clearHistory() { this.history = []; } getHistory() { return [...this.history]; } getModelInfo() { return { provider: this.config.provider, model: this.config.model, initialized: this.initialized, historyCount: this.history.length, capabilities: this.getCapabilities(), }; } addToHistory(message) { this.history.push(message); if (this.history.length > 50) { this.history = this.history.slice(-50); } } generateMessageId() { return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`; } async withRetry(operation, context) { let lastError; for (let attempt = 1; attempt <= this.options.retryAttempts; attempt++) { try { return await operation(); } catch (error) { lastError = error; if (attempt < this.options.retryAttempts) { await this.delay(this.options.retryDelay * attempt); } } } throw new Error(`${context} failed after ${this.options.retryAttempts} attempts: ${lastError?.message || 'Unknown error'}`); } delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } } exports.BaseAIService = BaseAIService; //# sourceMappingURL=ai.interface.js.map