From 4baa484b84c5184286cac2743575251454a5ee2b Mon Sep 17 00:00:00 2001 From: Agando Date: Mon, 25 May 2026 18:02:02 +0200 Subject: auto: 2026-05-25_18:02 changes --- modules/core/module-ollamamodels.js | 87 +++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 modules/core/module-ollamamodels.js (limited to 'modules/core/module-ollamamodels.js') diff --git a/modules/core/module-ollamamodels.js b/modules/core/module-ollamamodels.js new file mode 100644 index 0000000..9a7763a --- /dev/null +++ b/modules/core/module-ollamamodels.js @@ -0,0 +1,87 @@ +// Extracted from newOS4 index.html — OllamaModelsModule + class OllamaModelsModule { + constructor() { this.commands = {}; this.terminal = null; } + getHelpInfo() { + return { + 'models': 'models — List all available Ollama models', + 'model-info': 'model-info — Show details about a specific model', + 'model-pull': 'model-pull — Pull a model from Ollama registry', + 'model-delete': 'model-delete — Delete a model from local storage', + 'model-run': 'model-run [prompt] — Run inference with a model' + }; + } + registerCommands() { + this.commands['models'] = () => this.listModels(); + this.commands['model-info'] = (args) => this.modelInfo(args); + this.commands['model-pull'] = (args) => this.pullModel(args); + this.commands['model-delete'] = (args) => this.deleteModel(args); + this.commands['model-run'] = (args) => this.runModel(args); + } + async listModels() { + const endpoint = localStorage.getItem('webx11_ollama_endpoint') || 'http://localhost:11434'; + try { + const response = await fetch(`${endpoint}/api/tags`); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + const data = await response.json(); + const models = data.models || []; + if (models.length === 0) { + this.terminal.print("No models found. Run 'ollama pull ' first.", "warning"); return; + } + this.terminal.print("=== Available Ollama Models ===", "info"); + this.terminal.printHTML(` + + + + + `); + models.forEach(m => { + const sizeGB = (m.size / 1e9).toFixed(2); + this.terminal.printHTML(` + + + + `); + }); + this.terminal.printHTML(`
NameSizeFamily
${m.name}${sizeGB} GB${m.details?.family || 'N/A'}
`); + } catch (e) { + this.terminal.print(`Failed to fetch models: ${e.message}`, "error"); + } + } + async modelInfo(args) { + if (!args[0]) { + this.terminal.print("Usage: model-info ", "warning"); return; + } + const endpoint = localStorage.getItem('webx11_ollama_endpoint') || 'http://localhost:11434'; + try { + const response = await fetch(`${endpoint}/api/show`, { + method: 'POST', headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name: args[0] }) + }); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + const data = await response.json(); + this.terminal.print(`=== ${args[0]} ===`, "info"); + this.terminal.print(`License: ${data.license || 'N/A'}`); + this.terminal.print(`Parameters: ${data.details?.parameter_size || 'N/A'}`); + this.terminal.print(`Family: ${data.details?.family || 'N/A'}`); + } catch (e) { + this.terminal.print(`Failed to get model info: ${e.message}`, "error"); + } + } + pullModel(args) { + this.terminal.print("⚠️ Model pulling must be done via Ollama CLI", "warning"); + this.terminal.print(`Run: ollama pull ${args[0] || ''}`, "info"); + } + deleteModel(args) { + this.terminal.print("⚠️ Model deletion must be done via Ollama CLI", "warning"); + this.terminal.print(`Run: ollama rm ${args[0] || ''}`, "info"); + } + async runModel(args) { + if (!args[0]) { + this.terminal.print("Usage: model-run [prompt]", "warning"); return; + } + const model = args[0]; + const prompt = args.slice(1).join(' ') || 'Hello!'; + this.terminal.print(`Running ${model}...`, "info"); + await this.terminal.ollamaManager.chat(prompt, model); + } + } -- cgit v1.2.3