Elffuss BraidHub

kikocis/continue public

61bef27a1dcd · 1.8 KiBRawPermalink
1import { ILLM, LLMFullCompletionOptions } from "..";
2
3import { removeCodeBlocksAndTrim, removeQuotesAndEscapes } from ".";
4
5import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
6import type { IMessenger } from "../protocol/messenger";
7import { renderChatMessage } from "./messageContent";
8
9export class ChatDescriber {
10 static maxTokens = 12;
11 static prompt: string | undefined =
12 "Given the following... please reply with a title for the chat that is 3-4 words in length, all words used should be directly related to the content of the chat, avoid using verbs unless they are directly related to the content of the chat, no additional text or explanation, you don't need ending punctuation.\n\n";
13 static messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>;
14
15 static async describe(
16 model: ILLM,
17 completionOptions: LLMFullCompletionOptions,
18 message: string,
19 ): Promise<string | undefined> {
20 if (!ChatDescriber.prompt) {
21 return;
22 }
23
24 // Clean up and distill the message we want to send to the LLM
25 message = removeCodeBlocksAndTrim(message);
26
27 if (!message) {
28 return;
29 }
30
31 completionOptions.maxTokens = ChatDescriber.maxTokens;
32
33 // Prompt the user's current LLM for the title
34 const titleResponse = await model.chat(
35 [
36 {
37 role: "user",
38 content: ChatDescriber.prompt + message,
39 },
40 ],
41 new AbortController().signal,
42 completionOptions,
43 );
44
45 // Set the title
46 return removeQuotesAndEscapes(renderChatMessage(titleResponse));
47 }
48
49 // // TODO: Allow the user to manually set specific/tailored prompts to generate their titles
50 // static async setup() {
51 // if(config?.prompt) {
52 // ChatDescriber.prompt = config?.prompt;
53 // }
54 // }
55}