Skip to content

Commit

Permalink
fix: press enter in prompt throws an error
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry authored Mar 11, 2024
2 parents cbfe3fb + 3411582 commit 1a9af65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions webapp/components/views/Threads/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type PromptProps = {
errorMessage: string;
disabled: boolean;
onUpdatePrompt: (prompt: ParsedPrompt) => void;
onSendMessage: () => void;
onSendMessage: (prompt?: ParsedPrompt) => void;
tokenValidate: TokenValidator;
};

Expand Down Expand Up @@ -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);
}
};

Expand Down
12 changes: 4 additions & 8 deletions webapp/components/views/Threads/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function Thread({
return updatedConversations;
};

const handleSendMessage = async () => {
const handleSendMessage = async (prompt = currentPrompt) => {
if (conversationId === undefined) {
return;
}
Expand All @@ -304,7 +304,7 @@ function Thread({
getConversationModelId(selectedConversation, assistant) || activeModel;
const result = await preProcessingCommands(
conversationId,
currentPrompt,
prompt,
commandManager,
selectedConversation as Conversation,
conversations,
Expand All @@ -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;
Expand Down Expand Up @@ -364,7 +360,7 @@ function Thread({
updatedMessages,
updatedConversation,
updatedConversations,
currentPrompt,
prompt,
modelName,
);

Expand Down

0 comments on commit 1a9af65

Please sign in to comment.