Skip to content

Commit 152cd96

Browse files
committed
add check that server started
1 parent d560f57 commit 152cd96

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_modules
44
.vscode-test/
55
*.vsix
66
model.gguf
7-
server
7+
./server

.vscode/tasks.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
{
77
"label": "build",
88
"type": "npm",
9-
"script": "esbuild-watch",
10-
"problemMatcher": "$esbuild",
9+
"script": "watch",
10+
"problemMatcher": "$tsc-watch",
1111
"isBackground": true,
1212
"presentation": {
1313
"reveal": "never"

.vscodeignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ node_modules
1111
**/*.map
1212
**/*.ts
1313
model.gguf
14-
server
14+
./server

src/common/server/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { stopServer, startServer } from "./serverManager";

src/common/server.ts renamed to src/common/server/serverManager.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
2-
import { downloadModel, downloadServer } from "./download";
3-
import Logger from "./logger";
4-
import statusBar from "./statusBar";
2+
import { downloadModel, downloadServer } from "../download";
3+
import Logger from "../logger";
4+
import statusBar from "../statusBar";
55

66
let server: ChildProcessWithoutNullStreams | null;
77

8+
export const serverReady = async () => {
9+
try {
10+
const res = await fetch("http://localhost:39129/model.json", {
11+
method: "GET",
12+
});
13+
if (res.ok) {
14+
return true;
15+
} else {
16+
return false;
17+
}
18+
} catch (error) {
19+
return false;
20+
}
21+
};
22+
823
export const startServer = async () => {
24+
const serverIsStarted = await serverReady();
25+
if (serverIsStarted) {
26+
Logger.info("Server is started already.");
27+
return;
28+
}
29+
930
const { stopTask } = statusBar.startTask();
1031
const serverPath = await downloadServer();
1132
const modelPath = await downloadModel();
@@ -23,12 +44,10 @@ export const startServer = async () => {
2344
"39129",
2445
"--parallel",
2546
"4",
26-
"--threads",
27-
"8",
28-
"--threads-batch",
29-
"8",
3047
"--ctx-size",
3148
"2048",
49+
"--cont-batching",
50+
"--embedding",
3251
],
3352
{
3453
detached: false,
@@ -50,6 +69,7 @@ export const startServer = async () => {
5069
server.on("close", (code) => {
5170
Logger.trace(`child process exited with code ${code}`, "llama");
5271
});
72+
await serverReady();
5373
stopTask();
5474
};
5575

0 commit comments

Comments
 (0)