@juspay/neurolink 11.22.0 → 11.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,289 +0,0 @@
1
- import { spawnSync } from "child_process";
2
- import chalk from "chalk";
3
- import ora from "ora";
4
- import inquirer from "inquirer";
5
- import { logger } from "../../utils/logger.js";
6
- import { OllamaUtils } from "../utils/ollamaUtils.js";
7
- export function addOllamaCommands(cli) {
8
- cli.command("ollama <command>", "Manage Ollama local AI models", (yargs) => {
9
- return yargs
10
- .command("list-models", "List installed Ollama models", {}, listModelsHandler)
11
- .command("pull <model>", "Download an Ollama model", {
12
- model: {
13
- describe: "Model name to download",
14
- type: "string",
15
- demandOption: true,
16
- },
17
- }, pullModelHandler)
18
- .command("remove <model>", "Remove an Ollama model", {
19
- model: {
20
- describe: "Model name to remove",
21
- type: "string",
22
- demandOption: true,
23
- },
24
- }, removeModelHandler)
25
- .command("status", "Check Ollama service status", {}, statusHandler)
26
- .command("start", "Start Ollama service", {}, startHandler)
27
- .command("stop", "Stop Ollama service", {}, stopHandler)
28
- .command("setup", "Interactive Ollama setup", {}, setupHandler)
29
- .demandCommand(1, "Please specify a command");
30
- }, () => { });
31
- }
32
- async function listModelsHandler() {
33
- const spinner = ora("Fetching installed models...").start();
34
- try {
35
- const res = spawnSync("ollama", ["list"], { encoding: "utf8" });
36
- if (res.error) {
37
- throw res.error;
38
- }
39
- spinner.succeed("Installed models:");
40
- const output = res.stdout?.toString().trim();
41
- if (output) {
42
- logger.always(output);
43
- }
44
- else {
45
- logger.always(chalk.yellow('No models installed. Use "neurolink ollama pull <model>" to download a model.'));
46
- }
47
- }
48
- catch (error) {
49
- spinner.fail("Failed to list models. Is Ollama installed?");
50
- const errorMessage = error instanceof Error ? error.message : String(error);
51
- logger.error(chalk.red("Error:", errorMessage));
52
- logger.always(chalk.blue("\nTip: Install Ollama from https://ollama.ai"));
53
- process.exit(1);
54
- }
55
- }
56
- async function pullModelHandler(argv) {
57
- const { model } = argv;
58
- logger.always(chalk.blue(`Downloading model: ${model}`));
59
- logger.always(chalk.gray("This may take several minutes..."));
60
- try {
61
- const res = spawnSync("ollama", ["pull", model], { stdio: "inherit" });
62
- if (res.error) {
63
- throw res.error;
64
- }
65
- if (res.status !== 0) {
66
- throw new Error(`ollama pull exited with code ${res.status}`);
67
- }
68
- logger.always(chalk.green(`\n✅ Successfully downloaded ${model}`));
69
- logger.always(chalk.blue(`\nTest it with: npx @juspay/neurolink generate "Hello!" --provider ollama --model ${model}`));
70
- }
71
- catch (error) {
72
- logger.error(chalk.red(`\n❌ Failed to download ${model}`));
73
- const errorMessage = error instanceof Error ? error.message : String(error);
74
- logger.error(chalk.red("Error:", errorMessage));
75
- process.exit(1);
76
- }
77
- }
78
- async function removeModelHandler(argv) {
79
- const { model } = argv;
80
- const { confirm } = await inquirer.prompt([
81
- {
82
- type: "confirm",
83
- name: "confirm",
84
- message: `Are you sure you want to remove model "${model}"?`,
85
- default: false,
86
- },
87
- ]);
88
- if (!confirm) {
89
- logger.always(chalk.yellow("Removal cancelled."));
90
- return;
91
- }
92
- const spinner = ora(`Removing model ${model}...`).start();
93
- try {
94
- const res = spawnSync("ollama", ["rm", model], { encoding: "utf8" });
95
- if (res.error) {
96
- throw res.error;
97
- }
98
- if (res.status !== 0) {
99
- throw new Error(`ollama rm exited with ${res.status}`);
100
- }
101
- spinner.succeed(`Successfully removed ${model}`);
102
- }
103
- catch (_error) {
104
- spinner.fail(`Failed to remove ${model}`);
105
- const errorMessage = _error instanceof Error ? _error.message : String(_error);
106
- logger.error(chalk.red("Error:", errorMessage));
107
- process.exit(1);
108
- }
109
- }
110
- async function statusHandler() {
111
- const spinner = ora("Checking Ollama service status...").start();
112
- try {
113
- const res = spawnSync("ollama", ["list"], { encoding: "utf8" });
114
- if (res.error) {
115
- throw res.error;
116
- }
117
- if (res.status !== 0) {
118
- throw new Error("Ollama not running");
119
- }
120
- spinner.succeed("Ollama service is running");
121
- }
122
- catch (error) {
123
- spinner.fail("Ollama service is not running");
124
- logger.debug("Ollama status check failed:", error);
125
- logger.always(chalk.yellow("\nStart Ollama with: ollama serve"));
126
- process.exit(1);
127
- }
128
- }
129
- async function startHandler() {
130
- await OllamaUtils.startOllamaService();
131
- }
132
- async function stopHandler() {
133
- const spinner = ora("Stopping Ollama service...").start();
134
- try {
135
- if (process.platform === "darwin") {
136
- try {
137
- spawnSync("pkill", ["ollama"], { encoding: "utf8" });
138
- }
139
- catch {
140
- spawnSync("killall", ["Ollama"], { encoding: "utf8" });
141
- }
142
- }
143
- else if (process.platform === "linux") {
144
- try {
145
- spawnSync("systemctl", ["stop", "ollama"], { encoding: "utf8" });
146
- }
147
- catch {
148
- spawnSync("pkill", ["ollama"], { encoding: "utf8" });
149
- }
150
- }
151
- else {
152
- spawnSync("taskkill", ["/F", "/IM", "ollama.exe"], { encoding: "utf8" });
153
- }
154
- spinner.succeed("Ollama service stopped");
155
- }
156
- catch (err) {
157
- spinner.fail("Failed to stop Ollama service");
158
- logger.error(chalk.red("It may not be running or requires manual stop"));
159
- logger.error(chalk.red(`Error details: ${err}`));
160
- }
161
- }
162
- async function setupHandler() {
163
- logger.always(chalk.blue("🦙 Welcome to Ollama Setup!\n"));
164
- // Check installation
165
- const checkSpinner = ora("Checking Ollama installation...").start();
166
- let isInstalled = false;
167
- try {
168
- spawnSync("ollama", ["--version"], { encoding: "utf8" });
169
- isInstalled = true;
170
- checkSpinner.succeed("Ollama is installed");
171
- }
172
- catch {
173
- checkSpinner.fail("Ollama is not installed");
174
- }
175
- if (!isInstalled) {
176
- logger.always(chalk.yellow("\nOllama needs to be installed first."));
177
- logger.always(chalk.blue("\nInstallation instructions:"));
178
- if (process.platform === "darwin") {
179
- logger.always("\nFor macOS:");
180
- logger.always(chalk.gray(" brew install ollama"));
181
- logger.always(chalk.gray(" # or download from https://ollama.ai"));
182
- }
183
- else if (process.platform === "linux") {
184
- logger.always("\nFor Linux:");
185
- logger.always(chalk.gray(" curl -fsSL https://ollama.ai/install.sh | sh"));
186
- }
187
- else {
188
- logger.always("\nFor Windows:");
189
- logger.always(chalk.gray(" Download from https://ollama.ai"));
190
- }
191
- const { proceedAnyway } = await inquirer.prompt([
192
- {
193
- type: "confirm",
194
- name: "proceedAnyway",
195
- message: "Would you like to continue with setup anyway?",
196
- default: false,
197
- },
198
- ]);
199
- if (!proceedAnyway) {
200
- logger.always(chalk.blue("\nInstall Ollama and run setup again!"));
201
- return;
202
- }
203
- }
204
- // Check if service is running
205
- let serviceRunning = false;
206
- try {
207
- spawnSync("ollama", ["list"], { encoding: "utf8" });
208
- serviceRunning = true;
209
- logger.always(chalk.green("\n✅ Ollama service is running"));
210
- }
211
- catch {
212
- logger.always(chalk.yellow("\n⚠️ Ollama service is not running"));
213
- const { startService } = await inquirer.prompt([
214
- {
215
- type: "confirm",
216
- name: "startService",
217
- message: "Would you like to start the Ollama service?",
218
- default: true,
219
- },
220
- ]);
221
- if (startService) {
222
- await startHandler();
223
- serviceRunning = true;
224
- }
225
- }
226
- if (serviceRunning) {
227
- // List available models
228
- logger.always(chalk.blue("\n📦 Popular Ollama models:"));
229
- logger.always(" • llama2 (7B) - General purpose");
230
- logger.always(" • codellama (7B) - Code generation");
231
- logger.always(" • mistral (7B) - Fast and efficient");
232
- logger.always(" • tinyllama (1B) - Lightweight");
233
- logger.always(" • phi (2.7B) - Microsoft's compact model");
234
- const { downloadModel } = await inquirer.prompt([
235
- {
236
- type: "confirm",
237
- name: "downloadModel",
238
- message: "Would you like to download a model?",
239
- default: true,
240
- },
241
- ]);
242
- if (downloadModel) {
243
- const { selectedModel } = await inquirer.prompt([
244
- {
245
- type: "select",
246
- name: "selectedModel",
247
- message: "Select a model to download:",
248
- choices: [
249
- {
250
- name: "llama2 (7B) - Recommended for general use",
251
- value: "llama2",
252
- },
253
- {
254
- name: "codellama (7B) - Best for code generation",
255
- value: "codellama",
256
- },
257
- { name: "mistral (7B) - Fast and efficient", value: "mistral" },
258
- { name: "tinyllama (1B) - Lightweight, fast", value: "tinyllama" },
259
- { name: "phi (2.7B) - Microsoft's compact model", value: "phi" },
260
- { name: "Other (enter manually)", value: "other" },
261
- ],
262
- },
263
- ]);
264
- let modelToDownload = selectedModel;
265
- if (selectedModel === "other") {
266
- const { customModel } = await inquirer.prompt([
267
- {
268
- type: "input",
269
- name: "customModel",
270
- message: "Enter the model name:",
271
- validate: (input) => input.trim().length > 0 || "Model name is required",
272
- },
273
- ]);
274
- modelToDownload = customModel;
275
- }
276
- await pullModelHandler({ model: modelToDownload });
277
- }
278
- }
279
- logger.always(chalk.green("\n✅ Setup complete!\n"));
280
- logger.always(chalk.blue("Next steps:"));
281
- logger.always("1. List models: " + chalk.gray("neurolink ollama list-models"));
282
- logger.always("2. Generate text: " +
283
- chalk.gray('neurolink generate "Hello!" --provider ollama'));
284
- logger.always("3. Use specific model: " +
285
- chalk.gray('neurolink generate "Hello!" --provider ollama --model codellama'));
286
- logger.always(chalk.gray("\nFor more information, see: https://docs.neurolink.ai/providers/ollama"));
287
- }
288
- export default addOllamaCommands;
289
- //# sourceMappingURL=ollama.js.map