pi-splash-server 0.1.0 → 0.1.1
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/README.md +10 -8
- package/extensions/splash.ts +24 -14
- package/package.json +1 -1
- package/src/server.ts +11 -4
package/README.md
CHANGED
|
@@ -60,16 +60,18 @@ Update with `pi update`. To try it without installing:
|
|
|
60
60
|
In Pi:
|
|
61
61
|
|
|
62
62
|
```text
|
|
63
|
-
/splash doctor
|
|
64
|
-
/splash start
|
|
65
|
-
/splash
|
|
66
|
-
/splash use
|
|
67
|
-
/splash stop
|
|
68
|
-
/splash log
|
|
69
|
-
/splash install
|
|
70
|
-
/splash update
|
|
63
|
+
/splash doctor chip, memory, disk, runtime, recommended model and flags, what is left to download
|
|
64
|
+
/splash start [model] start the recommended model, or any repo or repo:QUANT, in the background and switch to it
|
|
65
|
+
/splash status and the next step
|
|
66
|
+
/splash use switch to a Splash server started outside Pi
|
|
67
|
+
/splash stop stop the server
|
|
68
|
+
/splash log last lines of the server log
|
|
69
|
+
/splash install put the runtime's install command into the editor
|
|
70
|
+
/splash update same for a newer runtime release
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
To start a different model, run `/splash stop` first.
|
|
74
|
+
|
|
73
75
|
`start` and `use` switch the session to the Splash model; `/model` switches
|
|
74
76
|
back, the server keeps running. The first start downloads the model (the
|
|
75
77
|
status bar shows what, how much and how fast). Loading takes about one to two
|
package/extensions/splash.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { providerConfig, providerName } from "../src/provider.ts";
|
|
|
9
9
|
import { countTokens, headKey, needsWarm, opensSession, readWarmed, warm, writeWarmed } from "../src/prewarm.ts";
|
|
10
10
|
import {
|
|
11
11
|
DEFAULT_PORT, STATE_DIR, describe, findLauncher, latestRelease, launcherVersion, logPath, probe, readRecord,
|
|
12
|
-
start, startedByUs, stop, versionOf, waitReady,
|
|
12
|
+
type ServedModel, servesModel, start, startedByUs, stop, versionOf, waitReady,
|
|
13
13
|
} from "../src/server.ts";
|
|
14
14
|
|
|
15
15
|
type Config = { port?: number; model?: string; flags?: string[]; stopOnExit?: boolean; keepAwake?: boolean; launcher?: string };
|
|
@@ -34,9 +34,8 @@ export default async function (pi: ExtensionAPI) {
|
|
|
34
34
|
const atLoad = await probe(port());
|
|
35
35
|
if (atLoad) pi.registerProvider(providerName(port()), providerConfig(port(), atLoad) as any);
|
|
36
36
|
|
|
37
|
-
async function register(ctx: any, switchTo: boolean) {
|
|
38
|
-
const
|
|
39
|
-
const served = await probe(p);
|
|
37
|
+
async function register(ctx: any, switchTo: boolean, p = port(), known?: ServedModel) {
|
|
38
|
+
const served = known ?? await probe(p);
|
|
40
39
|
if (!served) return null;
|
|
41
40
|
pi.registerProvider(providerName(p), providerConfig(p, served) as any);
|
|
42
41
|
if (switchTo) {
|
|
@@ -104,19 +103,29 @@ export default async function (pi: ExtensionAPI) {
|
|
|
104
103
|
|
|
105
104
|
async function startCmd(model: string | undefined, ctx: any) {
|
|
106
105
|
const p = port();
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const served = await probe(p);
|
|
107
|
+
if (served) {
|
|
108
|
+
if (model && !servesModel(model, served.ids)) {
|
|
109
|
+
ctx.ui.notify(`Port ${p} serves ${served.id}, not ${model}. Switch to what runs: /splash use. Or /splash stop, then /splash start ${model}.`, "error");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await register(ctx, true, p, served);
|
|
109
113
|
ctx.ui.notify(`Splash already serves on port ${p}; using it.`, "info");
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
112
|
-
if (following) {
|
|
113
|
-
ctx.ui.notify(`Already following the start on port ${p}: ${describe(readRecord(p))}.`, "info");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
116
|
const running = starting(p);
|
|
117
|
-
if (running) {
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
if (following || running) {
|
|
118
|
+
const loading = model && running && !startedByUs(p, running) ? undefined : ownedModel(p);
|
|
119
|
+
if (model && (!loading || !servesModel(model, [loading]))) {
|
|
120
|
+
ctx.ui.notify(`Port ${p} is starting ${loading ?? "an unknown model"}. Switch when ready: /splash use. Or /splash stop, then /splash start ${model}.`, "error");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (following) {
|
|
124
|
+
ctx.ui.notify(`Already following the start on port ${p}: ${describe(readRecord(p))}.`, "info");
|
|
125
|
+
} else if (running) {
|
|
126
|
+
ctx.ui.notify(`Splash is already starting on port ${p} (${describe(running)}); following it in the status bar.`, "info");
|
|
127
|
+
follow(p, running.pid, loading, ctx);
|
|
128
|
+
}
|
|
120
129
|
return;
|
|
121
130
|
}
|
|
122
131
|
const l = launcher();
|
|
@@ -145,7 +154,8 @@ export default async function (pi: ExtensionAPI) {
|
|
|
145
154
|
|
|
146
155
|
function ownedModel(p: number): string | undefined {
|
|
147
156
|
try {
|
|
148
|
-
|
|
157
|
+
const { model } = JSON.parse(readFileSync(join(STATE_DIR, `owned-${p}.json`), "utf8"));
|
|
158
|
+
return typeof model === "string" ? model : undefined;
|
|
149
159
|
} catch {
|
|
150
160
|
return undefined;
|
|
151
161
|
}
|
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type Record = {
|
|
|
15
15
|
failure?: { kind?: string; message?: string };
|
|
16
16
|
};
|
|
17
17
|
export type ServedModel = { id: string; context: number; inputModalities: string[]; laterSystem: boolean };
|
|
18
|
+
type ListedModel = ServedModel & { ids: string[] };
|
|
18
19
|
|
|
19
20
|
export function findLauncher(name: string): string | null {
|
|
20
21
|
try {
|
|
@@ -88,10 +89,16 @@ async function getJSON(url: string, timeoutMs = 2000): Promise<any> {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
export function
|
|
92
|
-
|
|
92
|
+
export function servesModel(requested: string, served: string[]): boolean {
|
|
93
|
+
return served.some((id) => id.toLowerCase() === requested.toLowerCase());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function parseModels(listing: any): Omit<ListedModel, "laterSystem"> | null {
|
|
97
|
+
if (!Array.isArray(listing?.data)) return null;
|
|
98
|
+
const m = listing.data[0];
|
|
93
99
|
if (!m || m.owned_by !== "splash" || !Number.isInteger(m.context_length) || m.context_length <= 0) return null;
|
|
94
|
-
|
|
100
|
+
const ids = listing.data.map((entry: any) => entry?.id).filter((id: unknown) => typeof id === "string");
|
|
101
|
+
return { id: m.id, ids, context: m.context_length, inputModalities: m.input_modalities ?? ["text"] };
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
export function parseLaterSystem(status: any): boolean {
|
|
@@ -100,7 +107,7 @@ export function parseLaterSystem(status: any): boolean {
|
|
|
100
107
|
return outcomes.every((o) => o === "native" || o === "patched");
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
export async function probe(port: number): Promise<
|
|
110
|
+
export async function probe(port: number): Promise<ListedModel | null> {
|
|
104
111
|
const model = parseModels(await getJSON(`${base(port)}/v1/models`));
|
|
105
112
|
if (!model) return null;
|
|
106
113
|
return { ...model, laterSystem: parseLaterSystem(await getJSON(`${base(port)}/status`)) };
|