-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
52 lines (42 loc) · 1.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as vscode from "vscode";
import { randomUUID } from "crypto";
import { HistoryMessage, getPromptChat } from "../prompt/promptChat";
import Logger from "../logger";
import { sendChatRequest } from "./localChat";
import { servers } from "../server";
const logCompletion = () => {
const uuid = randomUUID();
return {
info: (text: any) =>
Logger.info(text, { component: `Chat: ${uuid.slice(-8)}` }),
uuid: () => uuid,
};
};
export async function* chat(history: HistoryMessage[]) {
const loggerCompletion = logCompletion();
loggerCompletion.info("Chat: started");
const prompt = await getPromptChat(history);
const parameters = {
n_predict: 8192,
stop: [],
temperature: 0.7,
};
try {
Logger.info(`Start request;`, {
component: "chat",
sendTelemetry: true,
});
yield* sendChatRequest(
prompt,
parameters,
loggerCompletion.uuid(),
servers["chat-medium"].serverUrl
);
loggerCompletion.info("Request: finished");
} catch (error) {
const Error = error as Error;
Logger.error(error);
const errorMessage = Error.message;
vscode.window.showErrorMessage(errorMessage);
}
}