offgrid-ai 0.9.4 → 0.9.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "offgrid-ai",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "Privacy-first CLI for running local LLMs — discover, configure, run, benchmark",
5
5
  "author": "Eeshan Srivastava (https://eeshans.com)",
6
6
  "type": "module",
@@ -59,13 +59,7 @@ async function unloadOmlxModel(profile) {
59
59
  return { unloaded: true, backend: "omlx", modelId: targetId };
60
60
  }
61
61
 
62
- let detail = "";
63
- try {
64
- const body = await response.json();
65
- detail = body?.detail ?? body?.message ?? "";
66
- } catch {
67
- detail = await response.text().catch(() => "");
68
- }
62
+ const detail = await responseErrorDetail(response);
69
63
 
70
64
  if (response.status === 400 && /not loaded/i.test(detail)) {
71
65
  return { unloaded: true, backend: "omlx", modelId: targetId, reason: "model was not loaded" };
@@ -89,6 +83,17 @@ async function unloadOmlxModel(profile) {
89
83
  }
90
84
  }
91
85
 
86
+ async function responseErrorDetail(response) {
87
+ const text = await response.text().catch(() => "");
88
+ if (!text) return "";
89
+ try {
90
+ const body = JSON.parse(text);
91
+ return body?.detail ?? body?.message ?? text;
92
+ } catch {
93
+ return text;
94
+ }
95
+ }
96
+
92
97
  export async function finalizeBenchmarkRun(runDirectory, runResult, speedMetrics) {
93
98
  const metadataPath = join(runDirectory, "metadata.json");
94
99
  const metadata = JSON.parse(await readFile(metadataPath, "utf8"));
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { ensureDirs } from "../config.mjs";
5
5
  import { backendFor } from "../backends.mjs";
6
6
  import { hasPi, hasPiModel, syncPiConfig } from "../harness-pi.mjs";
7
- import { serverReady, startServer, waitForReady, stopProfile } from "../process.mjs";
7
+ import { serverReady, startServer, waitForReady, stopProfile, modelAvailableOnServer } from "../process.mjs";
8
8
  import { loadProfiles } from "../profiles.mjs";
9
9
  import { pc, createPrompt } from "../ui.mjs";
10
10
  import { linkBenchmarkRepo } from "./repo.mjs";
@@ -28,9 +28,20 @@ async function chooseBenchmarkAction(prompt, canRun) {
28
28
  return await prompt.choice("Action", canRun ? choices : choices.filter((c) => c.value === "prepare"), canRun ? "run" : "prepare");
29
29
  }
30
30
 
31
+ function managedModelId(profile) {
32
+ return profile.omlxModel ?? profile.ollamaModel ?? profile.modelAlias ?? profile.label;
33
+ }
34
+
35
+ async function ensureManagedModelAvailableForBenchmark(profile, backend) {
36
+ if (backend.type !== "managed-server") return;
37
+ if (await modelAvailableOnServer(profile)) return;
38
+ throw new Error(`${managedModelId(profile)} is not available on ${backend.label} at ${profile.baseUrl}.`);
39
+ }
40
+
31
41
  async function ensureServerForBenchmark(profile) {
32
42
  const backend = backendFor(profile.backend);
33
43
  if (await serverReady(profile.baseUrl)) {
44
+ await ensureManagedModelAvailableForBenchmark(profile, backend);
34
45
  console.log(pc.green(`[ready] ${backend.label} at ${profile.baseUrl}`));
35
46
  return { started: false };
36
47
  }
@@ -52,6 +63,7 @@ export async function runPreparedBenchmark(profile, runDirectory, options = {})
52
63
  options.signal.addEventListener("abort", () => controller.abort(), { once: true });
53
64
  }
54
65
  let serverStarted = false;
66
+ let benchmarkStarted = false;
55
67
  let metadata = null;
56
68
 
57
69
  const onSigint = () => {
@@ -72,6 +84,7 @@ export async function runPreparedBenchmark(profile, runDirectory, options = {})
72
84
  await syncPiConfig(profile);
73
85
  }
74
86
 
87
+ benchmarkStarted = true;
75
88
  const runResult = await runBenchmarkInPi(profile, runDirectory, { signal: controller.signal });
76
89
 
77
90
  let speedMetrics = null;
@@ -110,11 +123,13 @@ export async function runPreparedBenchmark(profile, runDirectory, options = {})
110
123
  console.log(result.stopped ? pc.green(`[stop] ${result.message}`) : pc.dim(`[stop] ${result.message}`));
111
124
  }
112
125
  }
113
- const unloadResult = await unloadModelFromServer(profile);
114
- if (!unloadResult.unloaded && unloadResult.error) {
115
- console.log(pc.yellow(`[unload] ${unloadResult.backend}: ${unloadResult.error}`));
116
- } else if (!unloadResult.unloaded && unloadResult.reason) {
117
- console.log(pc.dim(`[unload] ${unloadResult.backend}: ${unloadResult.reason}`));
126
+ if (benchmarkStarted) {
127
+ const unloadResult = await unloadModelFromServer(profile);
128
+ if (!unloadResult.unloaded && unloadResult.error) {
129
+ console.log(pc.yellow(`[unload] ${unloadResult.backend}: ${unloadResult.error}`));
130
+ } else if (!unloadResult.unloaded && unloadResult.reason) {
131
+ console.log(pc.dim(`[unload] ${unloadResult.backend}: ${unloadResult.reason}`));
132
+ }
118
133
  }
119
134
  }
120
135