Skip to content

Commit

Permalink
Start ollama service when possible
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jan 6, 2025
1 parent e8be59d commit bd52a7b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
40 changes: 35 additions & 5 deletions src/ollama/ollamaServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,36 @@ export class OllamaServer implements IModelServer {
}

async startServer(): Promise<boolean> {
// 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<boolean> {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions src/panels/setupGranitePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { IModelServer } from '../modelServer';
import { MockServer } from '../ollama/mockServer';
import { OllamaServer } from "../ollama/ollamaServer";
import { Telemetry } from '../telemetry';
import { terminalCommandRunner } from '../terminal/terminalCommandRunner';
import { getNonce } from "../utils/getNonce";
import { getUri } from "../utils/getUri";
import { getSystemInfo } from "../utils/sysUtils";
Expand Down Expand Up @@ -241,13 +240,8 @@ export class SetupGranitePage {
});
break;
case "startOllama":
await terminalCommandRunner.runInTerminal(
'ollama start',
{
name: "Start Ollama",
show: true,
}
);
await this.server.startServer();
break;
case "installOllama":
await this.server.installServer(data.mode);
break;
Expand Down

0 comments on commit bd52a7b

Please sign in to comment.