UNPKG

ollama-code-qwen

Version:

Un assistant IA en ligne de commande utilisant Ollama et le modèle qwen2.5-coder pour aider au développement, avec des capacités MCP améliorées et détection d'intentions en français et anglais

231 lines (198 loc) 5.68 kB
/** * Interface minimale pour les terminaux distants ou lents * Remplace l'interface TUI complète par une version simplifiée */ import readline from 'readline'; import chalk from 'chalk'; import { marked } from 'marked'; import TerminalRenderer from 'marked-terminal'; // Configuration du renderer pour Markdown minimaliste marked.setOptions({ renderer: new TerminalRenderer({ code: chalk.cyan, blockquote: chalk.gray.italic, table: chalk.white, listitem: chalk.yellow, strong: chalk.bold, em: chalk.italic, heading: chalk.bold }) }); export class MinimalInterface { /** * Initialise l'interface minimale * @param {Object} options - Options de configuration */ constructor(options = {}) { this.model = options.model || 'qwen2.5-coder:14b'; this.host = options.host || 'http://localhost:11434'; this.version = options.version || '0.4.0'; this.onSubmit = options.onSubmit || (() => {}); this.onCommand = options.onCommand || (() => {}); this.onExit = options.onExit || (() => {}); this.rl = readline.createInterface({ input: process.stdin, output: process.stdout, prompt: chalk.blue('> '), terminal: true }); this.conversation = []; this.loading = false; this.loadingInterval = null; } /** * Démarre l'interface */ start() { console.clear(); console.log(chalk.green.bold(`\n=== Ollama Code (Mode Minimal) - ${this.version} ===`)); console.log(chalk.gray(`Modèle: ${this.model} | Serveur: ${this.host}`)); console.log(chalk.gray('Type /help for available commands, Ctrl+C to exit\n')); this.setupInputHandler(); } /** * Configure le gestionnaire d'entrée */ setupInputHandler() { this.rl.on('line', async (line) => { if (this.loading) return; // Ignorer les entrées pendant le chargement const input = line.trim(); if (!input) { this.rl.prompt(); return; } if (input.startsWith('/')) { // Traiter comme une commande if (input === '/exit' || input === '/quit') { this.handleExit(); return; } try { await this.onCommand(input); } catch (error) { console.error(chalk.red(`Error: ${error.message}`)); } finally { this.rl.prompt(); } } else { // Traiter comme une entrée utilisateur console.log(chalk.cyan('\nVous:'), input); this.startLoading('Reflection en cours...'); try { await this.onSubmit(input); } catch (error) { console.error(chalk.red(`\nError: ${error.message}`)); } finally { this.stopLoading(); this.rl.prompt(); } } }); this.rl.on('close', () => { this.handleExit(); }); this.rl.prompt(); } /** * Gère la sortie de l'application */ handleExit() { this.stopLoading(); console.log(chalk.green('\nAu revoir!')); if (this.onExit) { this.onExit(); } process.exit(0); } /** * Ajoute un message système * @param {string} message - Message à afficher */ addSystemMessage(message) { console.log(chalk.green('\nSystème:'), message); } /** * Ajoute un message de l'assistant * @param {string} message - Message à afficher */ addAssistantMessage(message) { console.log(chalk.magenta('\nAssistant:')); console.log(marked(message)); } /** * Affiche une erreur * @param {string} message - Message d'erreur */ showError(message) { console.error(chalk.red(`\nErreur: ${message}`)); } /** * Démarre l'animation de chargement * @param {string} message - Message de chargement */ startLoading(message = 'Loading...') { this.loading = true; const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; let i = 0; process.stdout.write(chalk.yellow(`\n${message} `)); this.loadingInterval = setInterval(() => { process.stdout.write(`\r${chalk.yellow(`${message} ${frames[i % frames.length]}`)}`); i++; }, 100); } /** * Arrête l'animation de chargement */ stopLoading() { if (this.loadingInterval) { clearInterval(this.loadingInterval); this.loadingInterval = null; process.stdout.write('\r\n'); } this.loading = false; } /** * Démarre le streaming de réponse */ startResponseStream() { console.log(chalk.magenta('\nAssistant: ')); process.stdout.write(chalk.white('')); } /** * Met à jour le streaming de réponse * @param {string} content - Contenu à afficher */ updateResponseStream(content) { // Rien à faire en mode minimal, car nous affichons simplement au fur et à mesure process.stdout.write(chalk.white(content.slice(-1))); } /** * Arrête le streaming de réponse */ stopResponseStream() { process.stdout.write('\n\n'); } /** * Met le focus sur l'entrée */ focusInput() { this.rl.prompt(); } /** * Efface l'écran de chat */ clearChat() { console.clear(); console.log(chalk.green.bold(`\n=== Ollama Code (Mode Minimal) - ${this.version} ===`)); console.log(chalk.gray(`Modèle: ${this.model} | Serveur: ${this.host}`)); console.log(chalk.gray('Type /help for available commands, Ctrl+C to exit\n')); this.rl.prompt(); } /** * Met à jour la barre de statut * @param {string} status - Statut à afficher */ updateStatus(status) { console.log(chalk.gray(`\nStatus: ${status}`)); } }