From 02743ea795fc7376b3a3ed4be2c8875ba77ef5ba Mon Sep 17 00:00:00 2001 From: Kwanghyun On Date: Wed, 23 Oct 2024 14:39:11 +0900 Subject: [PATCH] Rename function and variables --- src/components/chat-view/Chat.tsx | 2 +- src/hooks/useChatHistory.ts | 4 ++-- src/types/chat.ts | 4 ++-- src/utils/promptGenerator.ts | 32 +++++++++++++++++-------------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/components/chat-view/Chat.tsx b/src/components/chat-view/Chat.tsx index 610277b..d6441a2 100644 --- a/src/components/chat-view/Chat.tsx +++ b/src/components/chat-view/Chat.tsx @@ -45,7 +45,7 @@ const getNewInputMessage = (app: App): ChatUserMessage => { return { role: 'user', content: null, - parsedContent: null, + promptContent: null, id: uuidv4(), mentionables: [ { diff --git a/src/hooks/useChatHistory.ts b/src/hooks/useChatHistory.ts index 9876286..94a5e6c 100644 --- a/src/hooks/useChatHistory.ts +++ b/src/hooks/useChatHistory.ts @@ -23,7 +23,7 @@ const serializeChatMessage = (message: ChatMessage): SerializedChatMessage => { return { role: 'user', content: message.content, - parsedContent: message.parsedContent, + promptContent: message.promptContent, id: message.id, mentionables: message.mentionables.map(serializeMentionable), } @@ -45,7 +45,7 @@ const deserializeChatMessage = ( return { role: 'user', content: message.content, - parsedContent: message.parsedContent, + promptContent: message.promptContent, id: message.id, mentionables: message.mentionables .map((m) => deserializeMentionable(m, app)) diff --git a/src/types/chat.ts b/src/types/chat.ts index 3eb65b2..acca208 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -5,7 +5,7 @@ import { Mentionable, SerializedMentionable } from './mentionable' export type ChatUserMessage = { role: 'user' content: SerializedEditorState | null - parsedContent: string | null + promptContent: string | null id: string mentionables: Mentionable[] } @@ -19,7 +19,7 @@ export type ChatMessage = ChatUserMessage | ChatAssistantMessage export type SerializedChatUserMessage = { role: 'user' content: SerializedEditorState | null - parsedContent: string | null + promptContent: string | null id: string mentionables: SerializedMentionable[] } diff --git a/src/utils/promptGenerator.ts b/src/utils/promptGenerator.ts index d5c7501..93874e1 100644 --- a/src/utils/promptGenerator.ts +++ b/src/utils/promptGenerator.ts @@ -51,27 +51,31 @@ export class PromptGenerator { throw new Error('Last message is not a user message') } - const { parsedContent, shouldUseRAG } = await this.parseUserMessage({ - message: lastUserMessage, - useVaultSearch, - onQueryProgressChange: onQueryProgressChange, - }) + const { promptContent, shouldUseRAG } = await this.compileUserMessagePrompt( + { + message: lastUserMessage, + useVaultSearch, + onQueryProgressChange: onQueryProgressChange, + }, + ) let parsedMessages = [ ...messages.slice(0, -1), { ...lastUserMessage, - parsedContent: parsedContent, + promptContent: promptContent, }, ] // Safeguard: ensure all user messages have parsed content parsedMessages = await Promise.all( parsedMessages.map(async (message) => { - if (message.role === 'user' && !message.parsedContent) { - const { parsedContent } = await this.parseUserMessage({ message }) + if (message.role === 'user' && !message.promptContent) { + const { promptContent } = await this.compileUserMessagePrompt({ + message, + }) return { ...message, - parsedContent: parsedContent, + promptContent: promptContent, } } return message @@ -94,7 +98,7 @@ export class PromptGenerator { if (message.role === 'user') { return { role: 'user', - content: message.parsedContent ?? '', + content: message.promptContent ?? '', } } else { return { @@ -112,7 +116,7 @@ export class PromptGenerator { } } - private async parseUserMessage({ + private async compileUserMessagePrompt({ message, useVaultSearch, onQueryProgressChange, @@ -121,7 +125,7 @@ export class PromptGenerator { useVaultSearch?: boolean onQueryProgressChange?: (queryProgress: QueryProgressState) => void }): Promise<{ - parsedContent: string + promptContent: string shouldUseRAG: boolean }> { if (!this.ragEngine) { @@ -129,7 +133,7 @@ export class PromptGenerator { } if (!message.content) { return { - parsedContent: '', + promptContent: '', shouldUseRAG: false, } } @@ -214,7 +218,7 @@ ${results .join('') return { - parsedContent: `${filePrompt}${blockPrompt}\n\n${query}\n\n`, + promptContent: `${filePrompt}${blockPrompt}\n\n${query}\n\n`, shouldUseRAG, } }