offgrid-ai 0.9.3 → 0.9.4

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.3",
3
+ "version": "0.9.4",
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",
@@ -1,7 +1,7 @@
1
1
  // ── Unload model from server memory after benchmark ────────────────────────────
2
2
 
3
3
  import { backendFor } from "../backends.mjs";
4
- import { apiRootUrl } from "../process.mjs";
4
+ import { apiRootUrl, serverModelIds } from "../process.mjs";
5
5
  import { existsSync } from "node:fs";
6
6
  import { readFile, writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
@@ -33,14 +33,62 @@ export async function unloadModelFromServer(profile) {
33
33
  }
34
34
 
35
35
  if (backend.id === "omlx") {
36
- // oMLX does not expose a model-unload endpoint. The model stays resident
37
- // until the oMLX server process is stopped.
38
- return { unloaded: false, backend: backend.id, reason: "no unload API available" };
36
+ return await unloadOmlxModel(profile);
39
37
  }
40
38
 
41
39
  return { unloaded: false, backend: backend.id, reason: "unsupported backend" };
42
40
  }
43
41
 
42
+ async function unloadOmlxModel(profile) {
43
+ const baseUrl = profile.baseUrl?.replace(/\/v1\/?$/u, "") || "";
44
+ const adminUrl = `${baseUrl}/admin/api/models`;
45
+ const modelId = profile.modelAlias || profile.omlxModel || profile.id;
46
+
47
+ try {
48
+ const ids = await serverModelIds(profile.baseUrl);
49
+ const match = ids.find((id) => id.toLowerCase() === modelId.toLowerCase());
50
+ const targetId = match ?? modelId;
51
+
52
+ const response = await fetch(`${adminUrl}/${encodeURIComponent(targetId)}/unload`, {
53
+ method: "POST",
54
+ headers: { "Content-Type": "application/json" },
55
+ signal: AbortSignal.timeout(30000),
56
+ });
57
+
58
+ if (response.ok) {
59
+ return { unloaded: true, backend: "omlx", modelId: targetId };
60
+ }
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
+ }
69
+
70
+ if (response.status === 400 && /not loaded/i.test(detail)) {
71
+ return { unloaded: true, backend: "omlx", modelId: targetId, reason: "model was not loaded" };
72
+ }
73
+
74
+ if (response.status === 401 || response.status === 403) {
75
+ return {
76
+ unloaded: false,
77
+ backend: "omlx",
78
+ modelId: targetId,
79
+ error: "oMLX admin authentication required. Enable skip_api_key_verification in oMLX settings, or unload manually from the admin panel.",
80
+ };
81
+ }
82
+
83
+ return { unloaded: false, backend: "omlx", modelId: targetId, error: `HTTP ${response.status}: ${detail}` };
84
+ } catch (err) {
85
+ if (err?.name === "AbortError" || err?.name === "TimeoutError") {
86
+ return { unloaded: false, backend: "omlx", modelId, error: "Unload request timed out. The model may still be unloading in the background." };
87
+ }
88
+ return { unloaded: false, backend: "omlx", modelId, error: err.message };
89
+ }
90
+ }
91
+
44
92
  export async function finalizeBenchmarkRun(runDirectory, runResult, speedMetrics) {
45
93
  const metadataPath = join(runDirectory, "metadata.json");
46
94
  const metadata = JSON.parse(await readFile(metadataPath, "utf8"));
package/src/process.mjs CHANGED
@@ -209,7 +209,7 @@ export async function waitForReady(profile, pid, rawLogPath) {
209
209
 
210
210
  // ── Internals ──────────────────────────────────────────────────────────────
211
211
 
212
- async function serverModelIds(baseUrl) {
212
+ export async function serverModelIds(baseUrl) {
213
213
  const result = await fetchJson(`${baseUrl.replace(/\/+$/u, "")}/models`);
214
214
  if (!result.ok) return [];
215
215
  return (Array.isArray(result.data?.data) ? result.data.data : [])