initial functionality
This commit is contained in:
parent
476d7eb40e
commit
f77d5591a9
10 changed files with 95 additions and 32 deletions
|
|
@ -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<ToCoreProtocol, FromCoreProtocol>
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
5
core/index.d.ts
vendored
5
core/index.d.ts
vendored
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -58,5 +58,6 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"refreshSubmenuItems",
|
||||
"isContinueInputFocused",
|
||||
"didChangeAvailableProfiles",
|
||||
"setCurrentChatTitle",
|
||||
"setTTSActive",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -14,4 +14,5 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
void,
|
||||
];
|
||||
setTTSActive: [boolean, void];
|
||||
setCurrentChatTitle: [string, void];
|
||||
};
|
||||
|
|
|
|||
65
core/util/chatDescriber.ts
Normal file
65
core/util/chatDescriber.ts
Normal file
|
|
@ -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<ToCoreProtocol, FromCoreProtocol>;
|
||||
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<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,6 +159,9 @@ 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);
|
||||
},
|
||||
|
|
@ -460,6 +463,7 @@ export const {
|
|||
setSelectedProfileId,
|
||||
deleteMessage,
|
||||
setIsGatheringContext,
|
||||
setCurrentChatTitle
|
||||
} = stateSlice.actions;
|
||||
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue