pi-llama-switch 1.0.2 → 1.0.3

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Carlos Duplar Mello
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carlos Duplar Mello
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,216 +1,218 @@
1
- # pi-llama-switch
2
-
3
- <div align="center">
4
-
5
- <!-- Add a cover image: docs/cover.png -->
6
- Restart local LLM servers with different model configurations. For single-model setups where each model needs different flags: context size, vision projector, sampling params, GPU offload. Works with [llama.cpp](https://github.com/ggml-org/llama.cpp) and [vLLM](https://github.com/vllm-project/vllm) (experimental).
7
-
8
- [![npm version](https://img.shields.io/npm/v/pi-llama-switch.svg)](https://www.npmjs.com/package/pi-llama-switch)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
-
11
- </div>
12
-
13
- ## Features
14
-
15
- - **`/switch` command** -- interactive model picker or direct switch with `/switch qwen`
16
- - **`model_switch` tool** -- the LLM can request a switch programmatically
17
- - **Health checking** -- polls `/health` endpoint with progress updates
18
- - **Provider registration** -- after switch, Pi natively knows the active model via `/model` and `Ctrl+P`
19
- - **PID tracking** -- clean process lifecycle management with graceful shutdown
20
- - **Stderr logging** -- captures startup failures to `~/.pi/agent/llama-switch.log`
21
- - **Auto-reconnect** -- reconnects to a running server on Pi restart
22
- - **Multi-backend** -- works with llama.cpp and vLLM (experimental)
23
-
24
- ## Who is this for
25
-
26
- You have a single GPU and multiple local models, but each model needs different server flags. Instead of maintaining separate terminals or scripts, you switch between them with `/switch`.
27
-
28
- **Common setups:**
29
-
30
- - **Coding vs general-purpose:** Qwen3.6 for code (small context, fast) and Gemma 4 for general tasks (vision, larger context) -- each with different `--ctx-size` and `--mmproj` flags.
31
- - **Fast vs powerful:** A smaller model for quick tasks and a large one for complex reasoning -- small model loads in seconds, large one needs more time and VRAM.
32
- - **Text vs multimodal:** A text-only model for coding and a vision model for image analysis -- vision model needs `--mmproj`, which adds VRAM overhead.
33
-
34
- If you only run one model at a time and don't change server flags between models, you don't need this extension.
35
-
36
- ## Install
37
-
38
- ```bash
39
- pi install npm:pi-llama-switch
40
- ```
41
-
42
- Then restart your Pi session.
43
-
44
- ## Config
45
-
46
- Copy `examples/model-switcher.json` to `~/.pi/agent/model-switcher.json` and edit:
47
-
48
- ```json
49
- {
50
- "server": {
51
- "host": "127.0.0.1",
52
- "port": 8080,
53
- "healthTimeout": 60,
54
- "portReleaseTimeout": 15
55
- },
56
- "defaultModel": "qwen",
57
- "models": {
58
- "qwen": {
59
- "name": "Qwen3.6 35B-A3B",
60
- "description": "Coding/Reasoning",
61
- "command": [
62
- "llama-server",
63
- "-m", "~/models/qwen/Qwen3.6-35B-A3B.gguf",
64
- "-ngl", "999",
65
- "--flash-attn", "on",
66
- "--cache-type-k", "q8_0",
67
- "--cache-type-v", "q8_0",
68
- "--ctx-size", "8192",
69
- "--parallel", "1",
70
- "--host", "127.0.0.1",
71
- "--port", "8080"
72
- ],
73
- "vision": false,
74
- "contextWindow": 8192,
75
- "maxTokens": 4096,
76
- "tags": ["coding", "reasoning"]
77
- }
78
- }
79
- }
80
- ```
81
-
82
- ### vLLM
83
-
84
- The extension should also work with vLLM. See `examples/model-switcher-vllm.json` for a full example:
85
-
86
- ```json
87
- {
88
- "server": {
89
- "host": "127.0.0.1",
90
- "port": 8000,
91
- "healthTimeout": 120,
92
- "portReleaseTimeout": 15
93
- },
94
- "defaultModel": "qwen",
95
- "models": {
96
- "qwen": {
97
- "name": "Qwen3.6-35B-A3B",
98
- "description": "Coding/Reasoning",
99
- "command": [
100
- "python3", "-m", "vllm.entrypoints.openai.api_server",
101
- "--model", "~/models/qwen/Qwen3.6-35B-A3B",
102
- "--tensor-parallel-size", "1",
103
- "--gpu-memory-utilization", "0.9",
104
- "--max-model-len", "8192",
105
- "--host", "127.0.0.1",
106
- "--port", "8000"
107
- ],
108
- "vision": false,
109
- "contextWindow": 8192,
110
- "maxTokens": 4096,
111
- "tags": ["coding", "reasoning"]
112
- }
113
- }
114
- }
115
- ```
116
-
117
- > [!NOTE]
118
- > vLLM support is verified against docs but not tested end-to-end. The health endpoint and OpenAI-compatible API are standard. Report issues if you test this.
119
-
120
- ### Config fields
121
-
122
- | Field | Required | Description |
123
- |---|---|---|
124
- | `server.host` | yes | Server bind address |
125
- | `server.port` | yes | Server port |
126
- | `server.healthTimeout` | no | Seconds to wait for `/health` (default: 60) |
127
- | `server.portReleaseTimeout` | no | Seconds to wait for port release after stop (default: 30) |
128
- | `defaultModel` | no | Model key active on startup (default: first model) |
129
- | `models.<key>.name` | yes | Display name |
130
- | `models.<key>.description` | yes | Short description |
131
- | `models.<key>.command` | yes | Array-style command (no shell parsing needed) |
132
- | `models.<key>.vision` | no | Whether model supports images (default: false) |
133
- | `models.<key>.contextWindow` | no | Max context tokens for Pi (default: 8192) |
134
- | `models.<key>.maxTokens` | no | Max output tokens for Pi (default: 4096) |
135
- | `models.<key>.tags` | no | Tags for filtering (default: []) |
136
-
137
- ## Commands
138
-
139
- | Command | Description |
140
- |---|---|
141
- | `/switch` | Interactive model picker |
142
- | `/switch qwen` | Switch directly to model key |
143
- | `/switch list` | Print all available models |
144
- | `/switch status` | Show active model + server health |
145
- | `/switch reload` | Re-read config file |
146
- | `/switch logs` | Tail the last 50 lines of the log |
147
-
148
- ## Tool
149
-
150
- The `model_switch` tool lets the LLM switch models programmatically:
151
-
152
- ```typescript
153
- model_switch({
154
- model: "qwen", // model key from config
155
- dryRun: false // optional: print command without executing
156
- })
157
- ```
158
-
159
- ### Schema
160
-
161
- ```ts
162
- model_switch({
163
- model: string, // required: model key
164
- dryRun?: boolean, // optional: preview mode
165
- })
166
- ```
167
-
168
- Returns:
169
-
170
- ```ts
171
- {
172
- content: [{ type: "text", text: string }],
173
- details: {
174
- switched: boolean,
175
- model: string,
176
- name: string,
177
- contextWindow: number,
178
- error?: string,
179
- }
180
- }
181
- ```
182
-
183
- ## How it works
184
-
185
- 1. Stops the current server via `SIGTERM` (tracked PID, not `pkill`)
186
- 2. Waits for the port to be released
187
- 3. Spawns a new server with the model's command array
188
- 4. Polls `/health` until `status === "ok"` (or errors immediately on `status: "error"`)
189
- 5. Registers the new model with Pi's provider system
190
-
191
- ## Troubleshooting
192
-
193
- **Startup timeout:** Increase `server.healthTimeout` in your config. Large models on low VRAM can take 60+ seconds to load. vLLM models may need even longer for initial weight loading.
194
-
195
- **Logs:** Check `~/.pi/agent/llama-switch.log` for stderr output:
196
- ```bash
197
- # From Pi
198
- /switch logs
199
-
200
- # From terminal
201
- tail -50 ~/.pi/agent/llama-switch.log
202
- tail -f ~/.pi/agent/llama-switch.log # follow in real time
203
- ```
204
-
205
- **Port still in use after stop:** Increase `server.portReleaseTimeout` (default: 30s). Large context sizes take longer to flush KV cache.
206
-
207
- **Switch failed, server still running:** The extension kills orphaned processes on failure. If something slips through:
208
- ```bash
209
- lsof -ti:8080 | xargs kill -9
210
- ```
211
-
212
- **Config not reloading:** Run `/switch reload` after editing `~/.pi/agent/model-switcher.json`. Verify JSON validity first.
213
-
214
- ## License
215
-
216
- MIT
1
+ # pi-llama-switch
2
+
3
+ <div align="center">
4
+
5
+ <!-- Add a cover image: docs/cover.png -->
6
+ Restart local LLM servers with different model configurations. For single-model setups where each model needs different flags: context size, vision projector, sampling params, GPU offload. Works with [llama.cpp](https://github.com/ggml-org/llama.cpp) and [vLLM](https://github.com/vllm-project/vllm) (experimental).
7
+
8
+ [![npm version](https://img.shields.io/npm/v/pi-llama-switch.svg)](https://www.npmjs.com/package/pi-llama-switch)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+
11
+ </div>
12
+
13
+ ## Features
14
+
15
+ - **`/switch` command** -- interactive model picker or direct switch with `/switch qwen`
16
+ - **`model_switch` tool** -- the LLM can request a switch programmatically
17
+ - **Health checking** -- polls `/health` endpoint with progress updates
18
+ - **Provider registration** -- after switch, Pi natively knows the active model via `/model` and `Ctrl+P`
19
+ - **PID tracking** -- clean process lifecycle management with graceful shutdown
20
+ - **Stderr logging** -- captures startup failures to `~/.pi/agent/llama-switch.log`
21
+ - **Auto-reconnect** -- reconnects to a running server on Pi restart
22
+ - **Multi-backend** -- works with llama.cpp and vLLM (experimental)
23
+
24
+ ## Who is this for
25
+
26
+ You have a single GPU and multiple local models, but each model needs different server flags. Instead of maintaining separate terminals or scripts, you switch between them with `/switch`.
27
+
28
+ **Common setups:**
29
+
30
+ - **Coding vs general-purpose:** Qwen3.6 for code (small context, fast) and Gemma 4 for general tasks (vision, larger context) -- each with different `--ctx-size` and `--mmproj` flags.
31
+ - **Fast vs powerful:** A smaller model for quick tasks and a large one for complex reasoning -- small model loads in seconds, large one needs more time and VRAM.
32
+ - **Text vs multimodal:** A text-only model for coding and a vision model for image analysis -- vision model needs `--mmproj`, which adds VRAM overhead.
33
+
34
+ If you only run one model at a time and don't change server flags between models, you don't need this extension.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pi install npm:pi-llama-switch
40
+ ```
41
+
42
+ Then restart your Pi session.
43
+
44
+ ## Config
45
+
46
+ Copy `examples/model-switcher.json` to `~/.pi/agent/model-switcher.json` and edit:
47
+
48
+ ```json
49
+ {
50
+ "server": {
51
+ "host": "127.0.0.1",
52
+ "port": 8080,
53
+ "healthTimeout": 60,
54
+ "portReleaseTimeout": 15
55
+ },
56
+ "defaultModel": "qwen",
57
+ "models": {
58
+ "qwen": {
59
+ "name": "Qwen3.6 35B-A3B",
60
+ "description": "Coding/Reasoning",
61
+ "command": [
62
+ "llama-server",
63
+ "-m", "~/models/qwen/Qwen3.6-35B-A3B.gguf",
64
+ "-ngl", "999",
65
+ "--flash-attn", "on",
66
+ "--cache-type-k", "q8_0",
67
+ "--cache-type-v", "q8_0",
68
+ "--ctx-size", "8192",
69
+ "--parallel", "1",
70
+ "--host", "127.0.0.1",
71
+ "--port", "8080"
72
+ ],
73
+ "vision": false,
74
+ "contextWindow": 8192,
75
+ "maxTokens": 4096,
76
+ "tags": ["coding", "reasoning"]
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### vLLM
83
+
84
+ The extension should also work with vLLM. See `examples/model-switcher-vllm.json` for a full example:
85
+
86
+ ```json
87
+ {
88
+ "server": {
89
+ "host": "127.0.0.1",
90
+ "port": 8000,
91
+ "healthTimeout": 120,
92
+ "portReleaseTimeout": 15
93
+ },
94
+ "defaultModel": "qwen",
95
+ "models": {
96
+ "qwen": {
97
+ "name": "Qwen3.6-35B-A3B",
98
+ "description": "Coding/Reasoning",
99
+ "command": [
100
+ "python3", "-m", "vllm.entrypoints.openai.api_server",
101
+ "--model", "~/models/qwen/Qwen3.6-35B-A3B",
102
+ "--served-model-name", "qwen",
103
+ "--tensor-parallel-size", "1",
104
+ "--gpu-memory-utilization", "0.9",
105
+ "--max-model-len", "8192",
106
+ "--host", "127.0.0.1",
107
+ "--port", "8000"
108
+ ],
109
+ "vision": false,
110
+ "contextWindow": 8192,
111
+ "maxTokens": 4096,
112
+ "tags": ["coding", "reasoning"]
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ > [!NOTE]
119
+ > vLLM support is verified against docs but not tested end-to-end. The health endpoint and OpenAI-compatible API are standard. Report issues if you test this.
120
+
121
+ ### Config fields
122
+
123
+ | Field | Required | Description |
124
+ |---|---|---|
125
+ | `server.host` | yes | Server bind address |
126
+ | `server.port` | yes | Server port |
127
+ | `server.healthTimeout` | no | Seconds to wait for `/health` (default: 60) |
128
+ | `server.portReleaseTimeout` | no | Seconds to wait for port release after stop (default: 30) |
129
+ | `defaultModel` | no | Model key active on startup (default: first model) |
130
+ | `models.<key>.name` | yes | Display name |
131
+ | `models.<key>.description` | yes | Short description |
132
+ | `models.<key>.command` | yes | Array-style command (no shell parsing needed) |
133
+ | `models.<key>.modelId` | no | Overrides the model ID sent in OpenAI API requests when the backend serves a different ID (e.g. `org/model-name`). Defaults to `--served-model-name`, `--alias`, the vLLM `--model`/`serve` value, or the model key |
134
+ | `models.<key>.vision` | no | Whether model supports images (default: false) |
135
+ | `models.<key>.contextWindow` | no | Max context tokens for Pi (default: 8192) |
136
+ | `models.<key>.maxTokens` | no | Max output tokens for Pi (default: 4096) |
137
+ | `models.<key>.tags` | no | Tags for filtering (default: []) |
138
+
139
+ ## Commands
140
+
141
+ | Command | Description |
142
+ |---|---|
143
+ | `/switch` | Interactive model picker |
144
+ | `/switch qwen` | Switch directly to model key |
145
+ | `/switch list` | Print all available models |
146
+ | `/switch status` | Show active model + server health |
147
+ | `/switch reload` | Re-read config file |
148
+ | `/switch logs` | Tail the last 50 lines of the log |
149
+
150
+ ## Tool
151
+
152
+ The `model_switch` tool lets the LLM switch models programmatically:
153
+
154
+ ```typescript
155
+ model_switch({
156
+ model: "qwen", // model key from config
157
+ dryRun: false // optional: print command without executing
158
+ })
159
+ ```
160
+
161
+ ### Schema
162
+
163
+ ```ts
164
+ model_switch({
165
+ model: string, // required: model key
166
+ dryRun?: boolean, // optional: preview mode
167
+ })
168
+ ```
169
+
170
+ Returns:
171
+
172
+ ```ts
173
+ {
174
+ content: [{ type: "text", text: string }],
175
+ details: {
176
+ switched: boolean,
177
+ model: string,
178
+ name: string,
179
+ contextWindow: number,
180
+ error?: string,
181
+ }
182
+ }
183
+ ```
184
+
185
+ ## How it works
186
+
187
+ 1. Stops the current server via `SIGTERM` (tracked PID, not `pkill`)
188
+ 2. Waits for the port to be released
189
+ 3. Spawns a new server with the model's command array
190
+ 4. Polls `/health` until `status === "ok"` (or errors immediately on `status: "error"`)
191
+ 5. Registers the new model with Pi's provider system
192
+
193
+ ## Troubleshooting
194
+
195
+ **Startup timeout:** Increase `server.healthTimeout` in your config. Large models on low VRAM can take 60+ seconds to load. vLLM models may need even longer for initial weight loading.
196
+
197
+ **Logs:** Check `~/.pi/agent/llama-switch.log` for stderr output:
198
+ ```bash
199
+ # From Pi
200
+ /switch logs
201
+
202
+ # From terminal
203
+ tail -50 ~/.pi/agent/llama-switch.log
204
+ tail -f ~/.pi/agent/llama-switch.log # follow in real time
205
+ ```
206
+
207
+ **Port still in use after stop:** Increase `server.portReleaseTimeout` (default: 30s). Large context sizes take longer to flush KV cache.
208
+
209
+ **Switch failed, server still running:** The extension kills orphaned processes on failure. If something slips through:
210
+ ```bash
211
+ lsof -ti:8080 | xargs kill -9
212
+ ```
213
+
214
+ **Config not reloading:** Run `/switch reload` after editing `~/.pi/agent/model-switcher.json`. Verify JSON validity first.
215
+
216
+ ## License
217
+
218
+ MIT
@@ -1,61 +1,65 @@
1
- {
2
- "server": {
3
- "host": "127.0.0.1",
4
- "port": 8000,
5
- "healthTimeout": 120,
6
- "portReleaseTimeout": 15
7
- },
8
- "defaultModel": "qwen",
9
- "models": {
10
- "qwen": {
11
- "name": "Qwen3.6-35B-A3B",
12
- "description": "Coding/Reasoning",
13
- "command": [
14
- "python3",
15
- "-m",
16
- "vllm.entrypoints.openai.api_server",
17
- "--model",
18
- "~/models/qwen/Qwen3.6-35B-A3B",
19
- "--tensor-parallel-size",
20
- "1",
21
- "--gpu-memory-utilization",
22
- "0.9",
23
- "--max-model-len",
24
- "8192",
25
- "--host",
26
- "127.0.0.1",
27
- "--port",
28
- "8000"
29
- ],
30
- "vision": false,
31
- "contextWindow": 8192,
32
- "maxTokens": 4096,
33
- "tags": ["coding", "reasoning"]
34
- },
35
- "llama": {
36
- "name": "Llama 4 Scout",
37
- "description": "General purpose",
38
- "command": [
39
- "python3",
40
- "-m",
41
- "vllm.entrypoints.openai.api_server",
42
- "--model",
43
- "~/models/meta-llama/Llama-4-Scout-17B-16E-Instruct",
44
- "--tensor-parallel-size",
45
- "2",
46
- "--gpu-memory-utilization",
47
- "0.95",
48
- "--max-model-len",
49
- "16384",
50
- "--host",
51
- "127.0.0.1",
52
- "--port",
53
- "8000"
54
- ],
55
- "vision": false,
56
- "contextWindow": 16384,
57
- "maxTokens": 8192,
58
- "tags": ["general"]
59
- }
60
- }
61
- }
1
+ {
2
+ "server": {
3
+ "host": "127.0.0.1",
4
+ "port": 8000,
5
+ "healthTimeout": 120,
6
+ "portReleaseTimeout": 15
7
+ },
8
+ "defaultModel": "qwen",
9
+ "models": {
10
+ "qwen": {
11
+ "name": "Qwen3.6-35B-A3B",
12
+ "description": "Coding/Reasoning",
13
+ "command": [
14
+ "python3",
15
+ "-m",
16
+ "vllm.entrypoints.openai.api_server",
17
+ "--model",
18
+ "~/models/qwen/Qwen3.6-35B-A3B",
19
+ "--served-model-name",
20
+ "qwen",
21
+ "--tensor-parallel-size",
22
+ "1",
23
+ "--gpu-memory-utilization",
24
+ "0.9",
25
+ "--max-model-len",
26
+ "8192",
27
+ "--host",
28
+ "127.0.0.1",
29
+ "--port",
30
+ "8000"
31
+ ],
32
+ "vision": false,
33
+ "contextWindow": 8192,
34
+ "maxTokens": 4096,
35
+ "tags": ["coding", "reasoning"]
36
+ },
37
+ "llama": {
38
+ "name": "Llama 4 Scout",
39
+ "description": "General purpose",
40
+ "command": [
41
+ "python3",
42
+ "-m",
43
+ "vllm.entrypoints.openai.api_server",
44
+ "--model",
45
+ "~/models/meta-llama/Llama-4-Scout-17B-16E-Instruct",
46
+ "--served-model-name",
47
+ "llama",
48
+ "--tensor-parallel-size",
49
+ "2",
50
+ "--gpu-memory-utilization",
51
+ "0.95",
52
+ "--max-model-len",
53
+ "16384",
54
+ "--host",
55
+ "127.0.0.1",
56
+ "--port",
57
+ "8000"
58
+ ],
59
+ "vision": false,
60
+ "contextWindow": 16384,
61
+ "maxTokens": 8192,
62
+ "tags": ["general"]
63
+ }
64
+ }
65
+ }