diff --git a/core/core.ts b/core/core.ts index ebd08f3bf..5650c3a25 100644 --- a/core/core.ts +++ b/core/core.ts @@ -28,6 +28,7 @@ import type { IMessenger, Message } from "./util/messenger"; import { editConfigJson } from "./util/paths"; import { Telemetry } from "./util/posthog"; import { TTS } from "./util/tts"; +import { ChatDescriber } from "./util/chatDescriber"; export class Core { // implements IMessenger @@ -401,6 +402,11 @@ 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 }; } @@ -476,8 +482,9 @@ export class Core { } }); - // Provide messenger to TTS so it can set GUI active / inactive state + // Provide messenger to utils so they can interact with GUI + state TTS.messenger = this.messenger; + ChatDescriber.messenger = this.messenger; on("tts/kill", async () => { void TTS.kill(); diff --git a/core/index.d.ts b/core/index.d.ts index c1c8ddc04..7d0bfb56a 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -952,6 +952,11 @@ interface ExperimentalConfig { */ readResponseTTS?: boolean; + /** + * Prompt the user's LLM for a title given the current chat content + */ + getChatTitles?: boolean; + /** * If set to true, we will attempt to pull down and install an instance of Chromium * that is compatible with the current version of Puppeteer. diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 1e2499ca7..3b0b79037 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -58,5 +58,6 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "refreshSubmenuItems", "isContinueInputFocused", "didChangeAvailableProfiles", + "setCurrentChatTitle", "setTTSActive", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index d3b127fdc..4a41becb1 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -14,4 +14,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { void, ]; setTTSActive: [boolean, void]; + setCurrentChatTitle: [string, void]; }; diff --git a/core/util/chatDescriber.ts b/core/util/chatDescriber.ts new file mode 100644 index 000000000..acb850d15 --- /dev/null +++ b/core/util/chatDescriber.ts @@ -0,0 +1,65 @@ +import type { IMessenger } from "./messenger"; +import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; +import { ILLM, LLMFullCompletionOptions } from ".."; +import { stripImages } from "../llm/images"; + +/** + * Removes code blocks from a message. + * + * Return modified message text. + */ +function removeCodeBlocksAndTrim(msgText: string): string { + const codeBlockRegex = /```[\s\S]*?```/g; + + // Remove code blocks from the message text + const textWithoutCodeBlocks = msgText.replace(codeBlockRegex, ""); + + return textWithoutCodeBlocks.trim(); +} + +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"; + static messenger: IMessenger; + + static async describe( + model: ILLM, + completionOptions: LLMFullCompletionOptions, + message: string, + ) { + if (!ChatDescriber.prompt) { + return; + } + + // Clean up and distill the message we want to send to the LLM + message = stripImages(message); + message = removeCodeBlocksAndTrim(message); + + if (!message) { + return; + } + + completionOptions.maxTokens = 24; + + // Prompt the user's current LLM for the title + const titleResponse = await model.chat( + [ + { + role: "user", + content: ChatDescriber.prompt + message, + }, + ], + completionOptions, + ); + + // Set the title + ChatDescriber.messenger?.send("setCurrentChatTitle", titleResponse.content.toString()); + } + + // // TODO: Allow the user to manually set specific/tailored prompts to generate their titles + // static async setup() { + // if(config?.prompt) { + // ChatDescriber.prompt = config?.prompt; + // } + // } +} diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 5bfd16377..bf3982055 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.214", + "version": "0.9.215", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.214", + "version": "0.9.215", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 2269b08dc..197340faa 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.214", + "version": "0.9.215", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" diff --git a/gui/src/hooks/useHistory.tsx b/gui/src/hooks/useHistory.tsx index 8e5fe22a2..7278d052c 100644 --- a/gui/src/hooks/useHistory.tsx +++ b/gui/src/hooks/useHistory.tsx @@ -1,7 +1,6 @@ import { Dispatch } from "@reduxjs/toolkit"; import { PersistedSessionInfo, SessionInfo } from "core"; -import { llmCanGenerateInParallel } from "core/llm/autodetect"; import { stripImages } from "core/llm/images"; import { useContext } from "react"; import { useSelector } from "react-redux"; @@ -21,9 +20,6 @@ function truncateText(text: string, maxLength: number) { function useHistory(dispatch: Dispatch) { const state = useSelector((state: RootState) => state.state); const defaultModel = useSelector(defaultModelSelector); - const disableSessionTitles = useSelector( - (store: RootState) => store.state.config.disableSessionTitles, - ); const ideMessenger = useContext(IdeMessengerContext); async function getHistory( @@ -44,6 +40,7 @@ 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 let title = stateCopy.title === "New Session" ? truncateText( @@ -53,32 +50,10 @@ function useHistory(dispatch: Dispatch) { .slice(-1)[0] || "", 50, ) + : stateCopy.title?.length > 0 + ? stateCopy.title : (await getSession(stateCopy.sessionId)).title; // to ensure titles are synced with updates from history page. - if ( - false && // Causing maxTokens to be set to 20 for main requests sometimes, so disabling until resolved - !disableSessionTitles && - llmCanGenerateInParallel(defaultModel.provider, defaultModel.model) - ) { - // let fullContent = ""; - // for await (const { content } of llmStreamChat( - // defaultModel.title, - // undefined, - // [ - // ...stateCopy.history.map((item) => item.message), - // { - // role: "user", - // content: - // "Give a maximum 40 character title to describe this conversation so far. The title should help me recall the conversation if I look for it later. DO NOT PUT QUOTES AROUND THE TITLE", - // }, - // ], - // { maxTokens: 20 } - // )) { - // fullContent += content; - // } - // title = stripImages(fullContent); - } - const sessionInfo: PersistedSessionInfo = { history: stateCopy.history, title: title, diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 92fc15fda..cd583768f 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -10,6 +10,7 @@ import { setInactive, setSelectedProfileId, setTTSActive, + setCurrentChatTitle } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; @@ -94,6 +95,10 @@ function useSetup(dispatch: Dispatch) { 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]); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index f6c61970a..6f67b639e 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -159,6 +159,9 @@ export const stateSlice = createSlice({ } // TODO }, + setCurrentChatTitle: (state, { payload }: PayloadAction) => { + state.title = payload; + }, addContextItems: (state, action: PayloadAction) => { state.contextItems = state.contextItems.concat(action.payload); }, @@ -460,6 +463,7 @@ export const { setSelectedProfileId, deleteMessage, setIsGatheringContext, + setCurrentChatTitle } = stateSlice.actions; export default stateSlice.reducer;