Skip to content

Commit 7e5470b

Browse files
committed
update
1 parent 31a1c90 commit 7e5470b

21 files changed

+930
-1902
lines changed

.vscodeignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ node_modules
1111
**/*.map
1212
**/*.ts
1313
model.gguf
14-
./server
14+
./server
15+
webviews/
16+
!webviews/build

package-lock.json

+2-103
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"deploy": "vsce publish --npm",
149149
"compile": "tsc -p ./",
150150
"watch": "tsc -watch -p ./",
151+
"package": "vsce package",
151152
"pretest": "npm run compile && npm run lint",
152153
"lint": "eslint src --ext ts",
153154
"test": "node ./out/test/runTest.js"
@@ -168,7 +169,6 @@
168169
},
169170
"dependencies": {
170171
"@grafana/faro-core": "^1.3.5",
171-
"@grafana/faro-web-sdk": "^1.3.5",
172-
"@vscode/webview-ui-toolkit": "^1.4.0"
172+
"@grafana/faro-web-sdk": "^1.3.5"
173173
}
174174
}

src/common/chat/index.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function* chat(history: HistoryMessage[]) {
2323
const prompt = await getPromptChat(history);
2424

2525
const parameters = {
26-
n_predict: 512,
26+
n_predict: 8192,
2727
stop: [],
2828
temperature: 0.7,
2929
};
@@ -41,15 +41,7 @@ export async function* chat(history: HistoryMessage[]) {
4141
servers["chat-medium"].serverUrl
4242
);
4343

44-
// if (chatResponse === null) {
45-
// return [];
46-
// }
47-
4844
loggerCompletion.info("Request: finished");
49-
// return {
50-
// role: "ai",
51-
// content: chatResponse.content,
52-
// };
5345
} catch (error) {
5446
const Error = error as Error;
5547
Logger.error(error);

src/common/chat/localChat.ts

+5-78
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ const logCompletion = (uuid = randomUUID() as string) => {
1111
};
1212
};
1313

14-
class CustomEvent extends Event {
15-
detail: any;
16-
constructor(message: any, data: any) {
17-
super(message, data);
18-
this.detail = data.detail;
19-
}
20-
}
21-
2214
const defualtParameters = {
2315
stream: true,
24-
n_predict: 128,
25-
temperature: 0.3,
16+
n_predict: 1024,
17+
temperature: 0.7,
2618
stop: [],
2719
repeat_last_n: 256,
2820
repeat_penalty: 1.18,
@@ -62,15 +54,6 @@ export async function* sendChatRequest(
6254

6355
const startTime = performance.now();
6456

65-
// const response = await fetch(`${url}/completion`, {
66-
// body: JSON.stringify(parametersForCompletion),
67-
// method: "POST",
68-
// headers: {
69-
// Connection: "keep-alive",
70-
// "Content-Type": "application/json",
71-
// Accept: "text/event-stream",
72-
// },
73-
// });
7457
let content = "";
7558
let timings;
7659
for await (const chunk of llama(prompt, parametersForCompletion, { url })) {
@@ -80,15 +63,7 @@ export async function* sendChatRequest(
8063
content += chunk.data.content;
8164
yield content;
8265
}
83-
// @ts-ignore
84-
// if (chunk.data.generation_settings) {
85-
// eventTarget.dispatchEvent(
86-
// new CustomEvent("generation_settings", {
87-
// // @ts-ignore
88-
// detail: chunk.data.generation_settings,
89-
// })
90-
// );
91-
// }
66+
9267
// @ts-ignore
9368
if (chunk.data.timings) {
9469
// @ts-ignore
@@ -154,26 +129,18 @@ export async function* sendChatRequest(
154129
}
155130
}
156131

157-
const paramDefaults = {
158-
stream: true,
159-
n_predict: 500,
160-
temperature: 0.2,
161-
// stop: ["</s>"],
162-
};
163-
164132
export async function* llama(
165133
prompt: string,
166134
params = {},
167135
config: { controller?: AbortController; url?: string } = {}
168136
) {
169-
let generation_settings;
170137
let controller = config.controller;
171138

172139
if (!controller) {
173140
controller = new AbortController();
174141
}
175142

176-
const completionParams = { ...paramDefaults, ...params, prompt };
143+
const completionParams = { ...params, prompt };
177144

178145
const response = await fetch(`${config.url}/completion`, {
179146
method: "POST",
@@ -183,7 +150,7 @@ export async function* llama(
183150
"Content-Type": "application/json",
184151
Accept: "text/event-stream",
185152
},
186-
// signal: controller.signal,
153+
signal: controller.signal,
187154
});
188155
// @ts-ignore
189156
const reader = response.body.getReader<any>();
@@ -241,10 +208,6 @@ export async function* llama(
241208
// @ts-ignore
242209
if (result.data.stop) {
243210
// @ts-ignore
244-
if (result.data.generation_settings) {
245-
// @ts-ignore
246-
generation_settings = result.data.generation_settings;
247-
}
248211
cont = false;
249212
break;
250213
}
@@ -284,39 +247,3 @@ export async function* llama(
284247

285248
return content;
286249
}
287-
288-
export const llamaEventTarget = (prompt: string, params = {}, config = {}) => {
289-
const eventTarget = new EventTarget();
290-
(async () => {
291-
let content = "";
292-
for await (const chunk of llama(prompt, params, config)) {
293-
// @ts-ignore
294-
if (chunk.data) {
295-
// @ts-ignore
296-
content += chunk.data.content;
297-
eventTarget.dispatchEvent(
298-
// @ts-ignore
299-
new CustomEvent("message", { detail: chunk.data })
300-
);
301-
}
302-
// @ts-ignore
303-
if (chunk.data.generation_settings) {
304-
eventTarget.dispatchEvent(
305-
new CustomEvent("generation_settings", {
306-
// @ts-ignore
307-
detail: chunk.data.generation_settings,
308-
})
309-
);
310-
}
311-
// @ts-ignore
312-
if (chunk.data.timings) {
313-
eventTarget.dispatchEvent(
314-
// @ts-ignore
315-
new CustomEvent("timings", { detail: chunk.data.timings })
316-
);
317-
}
318-
}
319-
eventTarget.dispatchEvent(new CustomEvent("done", { detail: { content } }));
320-
})();
321-
return eventTarget;
322-
};

0 commit comments

Comments
 (0)