diff --git a/webapp/components/views/Threads/Prompt.tsx b/webapp/components/views/Threads/Prompt.tsx index 538da7f3..18472467 100644 --- a/webapp/components/views/Threads/Prompt.tsx +++ b/webapp/components/views/Threads/Prompt.tsx @@ -43,7 +43,7 @@ export type PromptProps = { errorMessage: string; disabled: boolean; onUpdatePrompt: (prompt: ParsedPrompt) => void; - onSendMessage: () => void; + onSendMessage: (prompt?: ParsedPrompt) => void; tokenValidate: TokenValidator; }; @@ -96,16 +96,16 @@ export default function Prompt({ }; const handleKeypress = (e: KeyboardEvent) => { + const textarea = e.target as HTMLTextAreaElement; + const { caretStartIndex } = getCaretPosition(textarea); + const value = `${textarea.value} \n`; + const newPrompt = parsePrompt({ text: value, caretStartIndex }, tokenValidate); if (e.key === 'Enter' && e.shiftKey) { e.preventDefault(); - const textarea = e.target as HTMLTextAreaElement; - const { caretStartIndex } = getCaretPosition(textarea); - const value = `${textarea.value} \n`; - const newPrompt = parsePrompt({ text: value, caretStartIndex }, tokenValidate); onUpdatePrompt(newPrompt); } else if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); - onSendMessage(); + onSendMessage(newPrompt); } }; diff --git a/webapp/components/views/Threads/Thread.tsx b/webapp/components/views/Threads/Thread.tsx index 3f4b82f4..9dd48989 100644 --- a/webapp/components/views/Threads/Thread.tsx +++ b/webapp/components/views/Threads/Thread.tsx @@ -295,7 +295,7 @@ function Thread({ return updatedConversations; }; - const handleSendMessage = async () => { + const handleSendMessage = async (prompt = currentPrompt) => { if (conversationId === undefined) { return; } @@ -304,7 +304,7 @@ function Thread({ getConversationModelId(selectedConversation, assistant) || activeModel; const result = await preProcessingCommands( conversationId, - currentPrompt, + prompt, commandManager, selectedConversation as Conversation, conversations, @@ -325,11 +325,7 @@ function Thread({ setErrorMessage({ ...errorMessage, [conversationId]: '' }); setIsProcessing({ ...isProcessing, [conversationId]: true }); - const userMessage = createMessage( - { role: 'user', name: 'you' }, - currentPrompt.text, - currentPrompt.raw, - ); + const userMessage = createMessage({ role: 'user', name: 'you' }, prompt.text, prompt.raw); let message = createMessage({ role: 'assistant', name: modelName }, '...'); message.status = MessageStatus.Pending; userMessage.sibling = message.id; @@ -364,7 +360,7 @@ function Thread({ updatedMessages, updatedConversation, updatedConversations, - currentPrompt, + prompt, modelName, );