Skip to content

Commit d1b6672

Browse files
authored
feat(configuration): auto restart servers after changing configuration (#33)
1 parent a00523c commit d1b6672

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"id": "firecoder.chat-gui",
4848
"name": "",
4949
"visibility": "visible",
50-
"when": "config.firecoder.experimental.chat"
50+
"when": "config.firecoder.experimental.chat || config.firecoder.cloud.use"
5151
}
5252
]
5353
},

src/common/server/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Server {
127127
...(useGPU ? ["--n-gpu-layers", "100"] : []),
128128
"--cont-batching",
129129
"--embedding",
130+
"--slots-endpoint-disable",
130131
"--log-disable",
131132
],
132133
{
@@ -143,7 +144,9 @@ class Server {
143144
msgString.includes('"path":"/health"') ||
144145
msgString.includes('"path":"/tokenize"') ||
145146
msgString.includes("/model.json") ||
146-
msgString.includes("sampled token:")
147+
msgString.includes("process_single_task") ||
148+
msgString.includes("sampled token:") ||
149+
msgString.includes("update_slots")
147150
) {
148151
return;
149152
}
@@ -159,7 +162,9 @@ class Server {
159162
msgString.includes('"path":"/health"') ||
160163
msgString.includes('"path":"/tokenize"') ||
161164
msgString.includes("/model.json") ||
162-
msgString.includes("sampled token:")
165+
msgString.includes("process_single_task") ||
166+
msgString.includes("sampled token:") ||
167+
msgString.includes("update_slots")
163168
) {
164169
return;
165170
}

src/common/utils/configuration.ts

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class Configuration {
8989
public get<T extends keyof ConfigurationPropertiesType>(
9090
property: T
9191
): ConfigurationPropertiesType[T]["possibleValues"] {
92+
this.configuration = vscode.workspace.getConfiguration("firecoder");
93+
9294
return (
9395
this.configuration.get(property) ??
9496
ConfigurationProperties[property]["default"]

src/extension.ts

+43-20
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,17 @@ export async function activate(context: vscode.ExtensionContext) {
1919
sendTelemetry: true,
2020
});
2121

22-
if (
23-
configuration.get("cloud.use") ||
24-
configuration.get("experimental.chat")
25-
) {
26-
const provider = new ChatPanel(context.extensionUri);
27-
context.subscriptions.push(
28-
vscode.window.registerWebviewViewProvider(
29-
"firecoder.chat-gui",
30-
provider,
31-
{
32-
webviewOptions: { retainContextWhenHidden: true },
33-
}
34-
)
35-
);
36-
context.subscriptions.push(
37-
vscode.commands.registerCommand("firecoder.startNewChat", async () => {
38-
await provider.sendMessageToWebview("startNewChat", {});
39-
})
40-
);
41-
}
22+
const provider = new ChatPanel(context.extensionUri);
23+
context.subscriptions.push(
24+
vscode.window.registerWebviewViewProvider("firecoder.chat-gui", provider, {
25+
webviewOptions: { retainContextWhenHidden: true },
26+
})
27+
);
28+
context.subscriptions.push(
29+
vscode.commands.registerCommand("firecoder.startNewChat", async () => {
30+
await provider.sendMessageToWebview("startNewChat", {});
31+
})
32+
);
4233

4334
statusBar.init(context);
4435

@@ -66,6 +57,38 @@ export async function activate(context: vscode.ExtensionContext) {
6657
})
6758
);
6859

60+
vscode.workspace.onDidChangeConfiguration(async (event) => {
61+
if (
62+
event.affectsConfiguration("firecoder.cloud.use") ||
63+
event.affectsConfiguration("firecoder.experimental.chat") ||
64+
event.affectsConfiguration("firecoder.completion.manuallyMode") ||
65+
event.affectsConfiguration("firecoder.completion.autoMode") ||
66+
event.affectsConfiguration(
67+
"firecoder.experimental.useGpu.linux.nvidia"
68+
) ||
69+
event.affectsConfiguration("firecoder.experimental.useGpu.osx.metal") ||
70+
event.affectsConfiguration(
71+
"firecoder.experimental.useGpu.windows.nvidia"
72+
) ||
73+
event.affectsConfiguration("firecoder.server.usePreRelease")
74+
) {
75+
Object.values(servers).forEach((server) => server.stopServer());
76+
const serversToStart = [
77+
...new Set([
78+
configuration.get("completion.autoMode"),
79+
configuration.get("completion.manuallyMode"),
80+
...(configuration.get("experimental.chat") &&
81+
!configuration.get("cloud.use")
82+
? ["chat-medium" as const]
83+
: []),
84+
]),
85+
];
86+
await Promise.all(
87+
serversToStart.map((serverType) => servers[serverType].startServer())
88+
);
89+
}
90+
});
91+
6992
(async () => {
7093
if (configuration.get("cloud.use")) {
7194
Logger.info("Use cloud for chat", {

0 commit comments

Comments
 (0)