refac: explain button behaviour

This commit is contained in:
Timothy J. Baek 2024-10-05 16:50:06 -07:00
parent bbbd94f69c
commit ed1a2ab5e8
2 changed files with 59 additions and 8 deletions

View File

@ -1979,9 +1979,35 @@
{mergeResponses} {mergeResponses}
{chatActionHandler} {chatActionHandler}
bottomPadding={files.length > 0} bottomPadding={files.length > 0}
on:submit={(e) => { on:submit={async (e) => {
if (e.detail) { if (e.detail) {
submitPrompt(e.detail); // New user message
let userPrompt = e.detail.prompt;
let userMessageId = uuidv4();
let userMessage = {
id: userMessageId,
parentId: e.detail.parentId,
childrenIds: [],
role: 'user',
content: userPrompt,
models: selectedModels
};
let messageParentId = e.detail.parentId;
if (messageParentId !== null) {
history.messages[messageParentId].childrenIds = [
...history.messages[messageParentId].childrenIds,
userMessageId
];
}
history.messages[userMessageId] = userMessage;
history.currentId = userMessageId;
await tick();
await sendPrompt(userPrompt, userMessageId);
} }
}} }}
/> />
@ -2045,9 +2071,33 @@
{createMessagePair} {createMessagePair}
on:submit={async (e) => { on:submit={async (e) => {
if (e.detail) { if (e.detail) {
prompt = ''; // New user message
let userPrompt = e.detail.prompt;
let userMessageId = uuidv4();
let userMessage = {
id: userMessageId,
parentId: e.detail.parentId,
childrenIds: [],
role: 'user',
content: userPrompt,
models: selectedModels
};
let messageParentId = e.detail.parentId;
if (messageParentId !== null) {
history.messages[messageParentId].childrenIds = [
...history.messages[messageParentId].childrenIds,
userMessageId
];
}
history.messages[userMessageId] = userMessage;
history.currentId = userMessageId;
await tick(); await tick();
submitPrompt(e.detail); await sendPrompt(userPrompt, userMessageId);
} }
}} }}
/> />

View File

@ -491,13 +491,14 @@
dispatch('update'); dispatch('update');
}} }}
on:explain={(e) => { on:explain={(e) => {
dispatch( dispatch('submit', {
'submit', parentId: message.id,
`Can you explain this section to me in more detail?\n\n` + prompt:
`Can you explain this section to me in more detail?\n\n` +
'```\n' + '```\n' +
e.detail + e.detail +
'\n```' '\n```'
); });
}} }}
/> />
{/if} {/if}