diff --git a/src/ollama/ollamaServer.ts b/src/ollama/ollamaServer.ts index 5f63f2e..f397109 100644 --- a/src/ollama/ollamaServer.ts +++ b/src/ollama/ollamaServer.ts @@ -92,11 +92,36 @@ export class OllamaServer implements IModelServer { } async startServer(): Promise { - // await terminalCommandRunner.runInTerminal("ollama list", { - // name: "Granite Code Setup", - // show: true, - // }); - return true; + let startCommand: string | undefined; + if (isWin()) { + startCommand = [ + `$ErrorActionPreference = "Stop"`, + `& "ollama app.exe"`, + ].join(' ; '); + } else if (isMac()) { + startCommand = [ + 'set -e', // Exit immediately if a command exits with a non-zero status + 'open -a Ollama.app', + ].join(' && '); + } else {//Linux + const start_ollama_sh = path.join(this.context.extensionPath, 'start_ollama.sh'); + startCommand = [ + 'set -e', // Exit immediately if a command exits with a non-zero status + `chmod +x "${start_ollama_sh}"`, // Ensure the script is executable + `"${start_ollama_sh}"`, // Use quotes in case the path contains spaces + ].join(' && '); + } + if (startCommand) { + await terminalCommandRunner.runInTerminal( + startCommand, + { + name: "Start Ollama", + show: true, + } + ); + return true; + } + return false; } async installServer(mode: string): Promise { @@ -398,6 +423,11 @@ function isLinux(): boolean { function isWin(): boolean { return PLATFORM.startsWith("win"); } + +function isMac(): boolean { + return PLATFORM === "darwin"; +} + function isDevspaces() { //sudo is not available on Red Hat DevSpaces return process.env['DEVWORKSPACE_ID'] !== undefined; diff --git a/src/panels/setupGranitePage.ts b/src/panels/setupGranitePage.ts index 8098f95..c744245 100644 --- a/src/panels/setupGranitePage.ts +++ b/src/panels/setupGranitePage.ts @@ -239,6 +239,9 @@ export class SetupGranitePage { }, }); break; + case "startOllama": + await this.server.startServer(); + break; case "installOllama": await this.server.installServer(data.mode); break; diff --git a/src/terminal/terminalCommandRunner.ts b/src/terminal/terminalCommandRunner.ts index 9f4537c..828fa5b 100644 --- a/src/terminal/terminalCommandRunner.ts +++ b/src/terminal/terminalCommandRunner.ts @@ -18,7 +18,7 @@ class TerminalCommandRunner implements Disposable { public async runInTerminal(command: string, options: ITerminalOptions): Promise { let terminal: Terminal | undefined; - const name = "Granite Models Setup"; + const name = options.name; if (window.terminals.length) { terminal = window.terminals.find(t => name === t.name); } diff --git a/webviews/src/App.tsx b/webviews/src/App.tsx index fd48c2e..f0bbed0 100644 --- a/webviews/src/App.tsx +++ b/webviews/src/App.tsx @@ -122,6 +122,12 @@ function App() { }); } + function handleStartOllama(): void { + vscode.postMessage({ + command: "startOllama" + }); + } + const REFETCH_MODELS_INTERVAL_MS = 1500; let ollamaStatusChecker: NodeJS.Timeout | undefined; @@ -313,30 +319,36 @@ function App() { {/* New section for additional buttons */} - {serverStatus === ServerStatus.missing && - installationModes.length > 0 && ( -
- {installationModes.some( - (mode) => mode.supportsRefresh === true - ) && ( -

- - This page will refresh once Ollama is installed. - -

- )} - {installationModes.map((mode) => ( - - ))} -
- )} + {serverStatus === ServerStatus.missing && installationModes.length > 0 && ( +
+ {installationModes.some(mode => mode.supportsRefresh === true) && ( +

This page will refresh once Ollama is installed.

+ )} + {installationModes.map((mode) => ( + + ))} +
+ )} + + { + // show start ollama button when server stopped + serverStatus === ServerStatus.stopped && ( + + ) + } + {(diskSpaceCheck.warnings.length > 0 || diskSpaceCheck.errors.length > 0) && (