feat: messages refac

This commit is contained in:
Timothy J. Baek 2023-12-29 23:25:40 -08:00
parent f91a6b63d1
commit b916f1b07d
3 changed files with 26 additions and 11 deletions

View file

@ -96,7 +96,17 @@
};
const confirmEditResponseMessage = async (messageId, content) => {
history.messages[messageId].originalContent = history.messages[messageId].content;
history.messages[messageId].content = content;
await tick();
await updateChatById(localStorage.token, chatId, {
messages: messages,
history: history
});
await chats.set(await getChatList(localStorage.token));
};
const rateMessage = async (messageId, rating) => {
@ -225,6 +235,7 @@
{:else}
<ResponseMessage
{message}
modelfiles={selectedModelfiles}
siblings={history.messages[message.parentId]?.childrenIds ?? []}
isLastMessage={messageIdx + 1 === messages.length}
{confirmEditResponseMessage}

View file

@ -26,8 +26,6 @@
export let copyToClipboard: Function;
export let regenerateResponse: Function;
let selectedModelfile = '';
let edit = false;
let editedContent = '';
@ -42,19 +40,14 @@
await tick();
if (tooltipInstance) {
console.log(tooltipInstance);
tooltipInstance[0].destroy();
}
console.log('rendering message');
renderLatex();
hljs.highlightAll();
createCopyCodeBlockButton();
if (message.info) {
console.log(message);
tooltipInstance = tippy(`#info-${message.id}`, {
content: `<span class="text-xs" id="tooltip-${message.id}">token/s: ${
`${
@ -214,12 +207,12 @@
</script>
<div class=" flex w-full message-{message.id}">
<ProfileImage src={selectedModelfile?.imageUrl ?? '/favicon.png'} />
<ProfileImage src={modelfiles[message.model]?.imageUrl ?? '/favicon.png'} />
<div class="w-full overflow-hidden">
<Name>
{#if selectedModelfile}
{selectedModelfile.title}
{#if message.model in modelfiles}
{modelfiles[message.model]?.title}
{:else}
Ollama <span class=" text-gray-500 text-sm font-medium"
>{message.model ? ` ${message.model}` : ''}</span

View file

@ -31,6 +31,17 @@
? $modelfiles.filter((modelfile) => modelfile.tagName === selectedModels[0])[0]
: null;
let selectedModelfiles = {};
$: selectedModelfiles = selectedModels.reduce((a, tagName, i, arr) => {
const modelfile =
$modelfiles.filter((modelfile) => modelfile.tagName === tagName)?.at(0) ?? undefined;
return {
...a,
...(modelfile && { [tagName]: modelfile })
};
}, {});
let chat = null;
let title = '';
@ -643,7 +654,7 @@
<Messages
chatId={$chatId}
{selectedModels}
{selectedModelfile}
{selectedModelfiles}
bind:history
bind:messages
bind:autoScroll