separate from llmStreamChat; call within saveSession
This commit is contained in:
parent
f77d5591a9
commit
b3ea895d4d
8 changed files with 40 additions and 23 deletions
11
core/core.ts
11
core/core.ts
|
|
@ -402,12 +402,6 @@ export class Core {
|
|||
if (config.experimental?.readResponseTTS && "completion" in next.value) {
|
||||
void TTS.read(next.value?.completion);
|
||||
}
|
||||
|
||||
// TODO: better detection of when we should prompt for a title; currently only doing it on the user's first chat
|
||||
if (config.experimental?.getChatTitles && "completion" in next.value && msg.data.messages.filter(m => m.role === "user").length === 1) {
|
||||
void ChatDescriber.describe(model, msg.data.completionOptions, next.value?.completion);
|
||||
}
|
||||
|
||||
return { done: true, content: next.value };
|
||||
}
|
||||
|
||||
|
|
@ -489,6 +483,11 @@ export class Core {
|
|||
on("tts/kill", async () => {
|
||||
void TTS.kill();
|
||||
});
|
||||
|
||||
on("chatDescriber/describe", async (msg) => {
|
||||
const currentModel = await this.getSelectedModel();
|
||||
return await ChatDescriber.describe(currentModel, {}, msg.data);
|
||||
});
|
||||
|
||||
async function* runNodeJsSlashCommand(
|
||||
configHandler: ConfigHandler,
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
},
|
||||
ProtocolGeneratorType<DiffLine>,
|
||||
];
|
||||
"chatDescriber/describe": [string, string | undefined];
|
||||
"stats/getTokensPerDay": [
|
||||
undefined,
|
||||
{ day: string; promptTokens: number; generatedTokens: number }[],
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"llm/streamChat",
|
||||
"llm/listModels",
|
||||
"streamDiffLines",
|
||||
"chatDescriber/describe",
|
||||
"stats/getTokensPerDay",
|
||||
"stats/getTokensPerModel",
|
||||
"index/setPaused",
|
||||
|
|
@ -58,6 +59,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"refreshSubmenuItems",
|
||||
"isContinueInputFocused",
|
||||
"didChangeAvailableProfiles",
|
||||
"setCurrentChatTitle",
|
||||
"setTTSActive",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -14,5 +14,4 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
void,
|
||||
];
|
||||
setTTSActive: [boolean, void];
|
||||
setCurrentChatTitle: [string, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import type { IMessenger } from "./messenger";
|
|||
import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
|
||||
import { ILLM, LLMFullCompletionOptions } from "..";
|
||||
import { stripImages } from "../llm/images";
|
||||
import { removeQuotesAndEscapes } from ".";
|
||||
|
||||
/**
|
||||
* Removes code blocks from a message.
|
||||
|
|
@ -19,14 +20,14 @@ function removeCodeBlocksAndTrim(msgText: string): string {
|
|||
|
||||
export class ChatDescriber {
|
||||
static prompt: string | undefined =
|
||||
"Given the following... please reply with a short summary that is 4-12 words in length, summarizing what the user is asking for OR what the user is trying to accomplish. You should only respond with the summary, no additional text or explanation.\n\n";
|
||||
"Given the following... please reply with a short summary that is 4-12 words in length, you should summarize what the user is asking for OR what the user is trying to accomplish. You should only respond with the summary, no additional text or explanation, you don't need ending punctuation.\n\n";
|
||||
static messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>;
|
||||
|
||||
static async describe(
|
||||
model: ILLM,
|
||||
completionOptions: LLMFullCompletionOptions,
|
||||
message: string,
|
||||
) {
|
||||
): Promise<string | undefined> {
|
||||
if (!ChatDescriber.prompt) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -53,7 +54,7 @@ export class ChatDescriber {
|
|||
);
|
||||
|
||||
// Set the title
|
||||
ChatDescriber.messenger?.send("setCurrentChatTitle", titleResponse.content.toString());
|
||||
return removeQuotesAndEscapes(titleResponse.content.toString());
|
||||
}
|
||||
|
||||
// // TODO: Allow the user to manually set specific/tailored prompts to generate their titles
|
||||
|
|
|
|||
|
|
@ -33,6 +33,14 @@ function useHistory(dispatch: Dispatch) {
|
|||
return result.status === "success" ? result.content : [];
|
||||
}
|
||||
|
||||
async function getChatTitle(message?: string): Promise<string | undefined> {
|
||||
const result = await ideMessenger.request(
|
||||
"chatDescriber/describe",
|
||||
message,
|
||||
);
|
||||
return result.status === "success" ? result.content : undefined;
|
||||
}
|
||||
|
||||
async function saveSession() {
|
||||
if (state.history.length === 0) return;
|
||||
|
||||
|
|
@ -40,7 +48,25 @@ function useHistory(dispatch: Dispatch) {
|
|||
dispatch(newSession());
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Set default title if it isn't set (=== "New Session"), if it is set then use that title, fallback use the first user message
|
||||
if (
|
||||
state.config?.experimental?.getChatTitles &&
|
||||
stateCopy.title === "New Session"
|
||||
) {
|
||||
try {
|
||||
// Check if we have first assistant response
|
||||
let assistantResponse = stateCopy.history
|
||||
?.filter((h) => h.message.role === "assistant")[0]
|
||||
?.message?.content?.toString();
|
||||
|
||||
if (assistantResponse) {
|
||||
stateCopy.title = await getChatTitle(assistantResponse);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error("Unable to get chat title");
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback if we get an error above or if the user has not set getChatTitles
|
||||
let title =
|
||||
stateCopy.title === "New Session"
|
||||
? truncateText(
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import {
|
|||
setConfig,
|
||||
setInactive,
|
||||
setSelectedProfileId,
|
||||
setTTSActive,
|
||||
setCurrentChatTitle
|
||||
setTTSActive
|
||||
} from "../redux/slices/stateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
|
||||
|
|
@ -95,10 +94,6 @@ function useSetup(dispatch: Dispatch<any>) {
|
|||
dispatch(setTTSActive(status));
|
||||
});
|
||||
|
||||
useWebviewListener("setCurrentChatTitle", async (newTitle) => {
|
||||
dispatch(setCurrentChatTitle(newTitle));
|
||||
});
|
||||
|
||||
useWebviewListener("setColors", async (colors) => {
|
||||
Object.keys(colors).forEach((key) => {
|
||||
document.body.style.setProperty(key, colors[key]);
|
||||
|
|
|
|||
|
|
@ -159,9 +159,6 @@ export const stateSlice = createSlice({
|
|||
}
|
||||
// TODO
|
||||
},
|
||||
setCurrentChatTitle: (state, { payload }: PayloadAction<string>) => {
|
||||
state.title = payload;
|
||||
},
|
||||
addContextItems: (state, action: PayloadAction<ContextItemWithId[]>) => {
|
||||
state.contextItems = state.contextItems.concat(action.payload);
|
||||
},
|
||||
|
|
@ -462,8 +459,7 @@ export const {
|
|||
consumeMainEditorContent,
|
||||
setSelectedProfileId,
|
||||
deleteMessage,
|
||||
setIsGatheringContext,
|
||||
setCurrentChatTitle
|
||||
setIsGatheringContext
|
||||
} = stateSlice.actions;
|
||||
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue