Skip to content

Commit

Permalink
feat: save /system message
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry committed Feb 29, 2024
1 parent a7fc2ea commit 1122b5e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
6 changes: 3 additions & 3 deletions webapp/components/views/Threads/PromptCommandInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ function PromptCommandInput({
if (textarea && dropdown) {
const { currentWord } = getCurrentWord(textarea);

const start = value?.text.trim().length || 0;
logger.info('isCommand selection change', currentWord, commandValue, start);
const start = textarea.value.trim().length - currentWord.length;

if (!isCommand(currentWord, start) && commandValue !== '') {
toggleDropdown(false);
}
}
}, [commandValue, value?.text]);
}, [commandValue]);

useEffect(() => {
const textarea = textareaRef.current;
Expand Down
52 changes: 47 additions & 5 deletions webapp/components/views/Threads/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,53 @@ function Thread({
return returnedMessage;
};

const clearPrompt = (conversation: Conversation | undefined, newConversations = conversations) => {
setChangedPrompt(undefined);

let updatedConversations = newConversations;
if (conversation) {
updatedConversations = updateConversation({ ...conversation, currentPrompt: undefined, temp: false }, newConversations);
updateConversations(updatedConversations);
}
return updatedConversations;
}

const handleSendMessage = async () => {
if (conversationId === undefined) {
return;
}
const action = currentPrompt.tokens.find((to) => to.type === PromptTokenType.Action);


if (action) {
let updatedConversation = selectedConversation;
let updatedConversations = conversations;
const command = commandManager.getCommand(action.value, action.type);
// logger.info('command action', command, action.value, action.type, currentPrompt.text);
if (command) {
command.execute?.(action.value);
if (command.label === 'System') {
const message = createMessage({ role: 'system', name: 'system' }, currentPrompt.text, currentPrompt.raw);
let updatedConversationId: string | undefined;
({
updatedConversationId,
updatedConversations,
} = await updateMessagesAndConversation(
[message],
getConversationMessages(conversationId),
));

updatedConversation = getConversation(
updatedConversationId,
updatedConversations,
) as Conversation;

}
}
clearPrompt(updatedConversation, updatedConversations);
return;
};

const mentions = currentPrompt.tokens.filter((to) => to.type === PromptTokenType.Mention);
const modelItem =
mentions.length === 1
Expand Down Expand Up @@ -407,12 +450,14 @@ function Thread({
conversation.name = getConversationTitle(conversation);
}

conversation.currentPrompt = undefined;
/* conversation.currentPrompt = undefined;
setChangedPrompt(undefined);
conversation.temp = false;
updatedConversations = updateConversation(conversation, updatedConversations);
updateConversations(updatedConversations);
updateConversations(updatedConversations); */
updatedConversations = clearPrompt(conversation, updatedConversations);

logger.info('onSendMessage', updatedMessages, conversation);
message = await sendMessage(message, updatedMessages, conversation, updatedConversations);

Expand Down Expand Up @@ -506,9 +551,6 @@ function Thread({

const conversation = getConversation(conversationId, conversations);
if (conversation && message.content) {
/* const { contentHistory = [] } = message;
contentHistory.push(message.content);
const newMessage = { ...message, content: newContent, contentHistory }; */
const parsedContent = parsePrompt({ text: newContent }, tokenValidator);
const newMessage = changeMessageContent(message, parsedContent.text, parsedContent.raw);
const conversationMessages = getConversationMessages(conversationId);
Expand Down
2 changes: 1 addition & 1 deletion webapp/utils/parsers/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const validator = (
state = PromptTokenState.Disabled;
}
} else if (type === PromptTokenType.Action) {
if (parsedPrompt.text.trim().length > 0 || previousToken?.type !== PromptTokenType.Text) {
if (parsedPrompt.text.trim().length > 0 || (previousToken && previousToken.type !== PromptTokenType.Text)) {
type = PromptTokenType.Text;
} else {
if (isEditing) {
Expand Down

0 comments on commit 1122b5e

Please sign in to comment.