Skip to content

feat(configuration): auto restart servers after changing configuration #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"id": "firecoder.chat-gui",
"name": "",
"visibility": "visible",
"when": "config.firecoder.experimental.chat"
"when": "config.firecoder.experimental.chat || config.firecoder.cloud.use"
}
]
},
Expand Down
9 changes: 7 additions & 2 deletions src/common/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Server {
...(useGPU ? ["--n-gpu-layers", "100"] : []),
"--cont-batching",
"--embedding",
"--slots-endpoint-disable",
"--log-disable",
],
{
Expand All @@ -143,7 +144,9 @@ class Server {
msgString.includes('"path":"/health"') ||
msgString.includes('"path":"/tokenize"') ||
msgString.includes("/model.json") ||
msgString.includes("sampled token:")
msgString.includes("process_single_task") ||
msgString.includes("sampled token:") ||
msgString.includes("update_slots")
) {
return;
}
Expand All @@ -159,7 +162,9 @@ class Server {
msgString.includes('"path":"/health"') ||
msgString.includes('"path":"/tokenize"') ||
msgString.includes("/model.json") ||
msgString.includes("sampled token:")
msgString.includes("process_single_task") ||
msgString.includes("sampled token:") ||
msgString.includes("update_slots")
) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Configuration {
public get<T extends keyof ConfigurationPropertiesType>(
property: T
): ConfigurationPropertiesType[T]["possibleValues"] {
this.configuration = vscode.workspace.getConfiguration("firecoder");

return (
this.configuration.get(property) ??
ConfigurationProperties[property]["default"]
Expand Down
63 changes: 43 additions & 20 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ export async function activate(context: vscode.ExtensionContext) {
sendTelemetry: true,
});

if (
configuration.get("cloud.use") ||
configuration.get("experimental.chat")
) {
const provider = new ChatPanel(context.extensionUri);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
"firecoder.chat-gui",
provider,
{
webviewOptions: { retainContextWhenHidden: true },
}
)
);
context.subscriptions.push(
vscode.commands.registerCommand("firecoder.startNewChat", async () => {
await provider.sendMessageToWebview("startNewChat", {});
})
);
}
const provider = new ChatPanel(context.extensionUri);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider("firecoder.chat-gui", provider, {
webviewOptions: { retainContextWhenHidden: true },
})
);
context.subscriptions.push(
vscode.commands.registerCommand("firecoder.startNewChat", async () => {
await provider.sendMessageToWebview("startNewChat", {});
})
);

statusBar.init(context);

Expand Down Expand Up @@ -66,6 +57,38 @@ export async function activate(context: vscode.ExtensionContext) {
})
);

vscode.workspace.onDidChangeConfiguration(async (event) => {
if (
event.affectsConfiguration("firecoder.cloud.use") ||
event.affectsConfiguration("firecoder.experimental.chat") ||
event.affectsConfiguration("firecoder.completion.manuallyMode") ||
event.affectsConfiguration("firecoder.completion.autoMode") ||
event.affectsConfiguration(
"firecoder.experimental.useGpu.linux.nvidia"
) ||
event.affectsConfiguration("firecoder.experimental.useGpu.osx.metal") ||
event.affectsConfiguration(
"firecoder.experimental.useGpu.windows.nvidia"
) ||
event.affectsConfiguration("firecoder.server.usePreRelease")
) {
Object.values(servers).forEach((server) => server.stopServer());
const serversToStart = [
...new Set([
configuration.get("completion.autoMode"),
configuration.get("completion.manuallyMode"),
...(configuration.get("experimental.chat") &&
!configuration.get("cloud.use")
? ["chat-medium" as const]
: []),
]),
];
await Promise.all(
serversToStart.map((serverType) => servers[serverType].startServer())
);
}
});

(async () => {
if (configuration.get("cloud.use")) {
Logger.info("Use cloud for chat", {
Expand Down