Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
c869652e
Unverified
Commit
c869652e
authored
Aug 07, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Aug 07, 2024
Browse files
Merge pull request #4322 from open-webui/dev
0.3.12
parents
d3146d20
240a3014
Changes
86
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1045 additions
and
706 deletions
+1045
-706
requirements.lock
requirements.lock
+9
-8
src/app.css
src/app.css
+9
-0
src/lib/apis/chats/index.ts
src/lib/apis/chats/index.ts
+7
-2
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+28
-18
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+1
-1
src/lib/components/chat/MessageInput/Models.svelte
src/lib/components/chat/MessageInput/Models.svelte
+9
-4
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+17
-12
src/lib/components/chat/Messages/CodeBlock.svelte
src/lib/components/chat/Messages/CodeBlock.svelte
+1
-1
src/lib/components/chat/Messages/CompareMessages.svelte
src/lib/components/chat/Messages/CompareMessages.svelte
+30
-30
src/lib/components/chat/Messages/HTMLRenderer.svelte
src/lib/components/chat/Messages/HTMLRenderer.svelte
+30
-0
src/lib/components/chat/Messages/MarkdownInlineTokens.svelte
src/lib/components/chat/Messages/MarkdownInlineTokens.svelte
+38
-0
src/lib/components/chat/Messages/MarkdownTokens.svelte
src/lib/components/chat/Messages/MarkdownTokens.svelte
+137
-0
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+563
-598
src/lib/components/chat/Settings/Chats.svelte
src/lib/components/chat/Settings/Chats.svelte
+12
-4
src/lib/components/chat/Settings/Interface.svelte
src/lib/components/chat/Settings/Interface.svelte
+29
-0
src/lib/components/chat/Tags.svelte
src/lib/components/chat/Tags.svelte
+11
-6
src/lib/components/common/Image.svelte
src/lib/components/common/Image.svelte
+6
-4
src/lib/components/common/ImagePreview.svelte
src/lib/components/common/ImagePreview.svelte
+14
-11
src/lib/components/common/Loader.svelte
src/lib/components/common/Loader.svelte
+30
-0
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+64
-7
No files found.
requirements.lock
View file @
c869652e
...
@@ -57,13 +57,13 @@ beautifulsoup4==4.12.3
...
@@ -57,13 +57,13 @@ beautifulsoup4==4.12.3
# via unstructured
# via unstructured
bidict==0.23.1
bidict==0.23.1
# via python-socketio
# via python-socketio
black==24.
4.2
black==24.
8.0
# via open-webui
# via open-webui
blinker==1.8.2
blinker==1.8.2
# via flask
# via flask
boto3==1.34.1
10
boto3==1.34.1
53
# via open-webui
# via open-webui
botocore==1.34.1
10
botocore==1.34.1
55
# via boto3
# via boto3
# via s3transfer
# via s3transfer
build==1.2.1
build==1.2.1
...
@@ -179,7 +179,7 @@ frozenlist==1.4.1
...
@@ -179,7 +179,7 @@ frozenlist==1.4.1
fsspec==2024.3.1
fsspec==2024.3.1
# via huggingface-hub
# via huggingface-hub
# via torch
# via torch
google-ai-generativelanguage==0.6.
4
google-ai-generativelanguage==0.6.
6
# via google-generativeai
# via google-generativeai
google-api-core==2.19.0
google-api-core==2.19.0
# via google-ai-generativelanguage
# via google-ai-generativelanguage
...
@@ -196,7 +196,7 @@ google-auth==2.29.0
...
@@ -196,7 +196,7 @@ google-auth==2.29.0
# via kubernetes
# via kubernetes
google-auth-httplib2==0.2.0
google-auth-httplib2==0.2.0
# via google-api-python-client
# via google-api-python-client
google-generativeai==0.
5.4
google-generativeai==0.
7.2
# via open-webui
# via open-webui
googleapis-common-protos==1.63.0
googleapis-common-protos==1.63.0
# via google-api-core
# via google-api-core
...
@@ -502,7 +502,7 @@ pypandoc==1.13
...
@@ -502,7 +502,7 @@ pypandoc==1.13
pyparsing==2.4.7
pyparsing==2.4.7
# via httplib2
# via httplib2
# via oletools
# via oletools
pypdf==4.
2.0
pypdf==4.
3.1
# via open-webui
# via open-webui
# via unstructured-client
# via unstructured-client
pypika==0.48.9
pypika==0.48.9
...
@@ -533,7 +533,7 @@ python-magic==0.4.27
...
@@ -533,7 +533,7 @@ python-magic==0.4.27
python-multipart==0.0.9
python-multipart==0.0.9
# via fastapi
# via fastapi
# via open-webui
# via open-webui
python-pptx==
0.6.23
python-pptx==
1.0.0
# via open-webui
# via open-webui
python-socketio==5.11.3
python-socketio==5.11.3
# via open-webui
# via open-webui
...
@@ -684,6 +684,7 @@ typing-extensions==4.11.0
...
@@ -684,6 +684,7 @@ typing-extensions==4.11.0
# via opentelemetry-sdk
# via opentelemetry-sdk
# via pydantic
# via pydantic
# via pydantic-core
# via pydantic-core
# via python-pptx
# via sqlalchemy
# via sqlalchemy
# via torch
# via torch
# via typer
# via typer
...
@@ -718,7 +719,7 @@ uvicorn==0.22.0
...
@@ -718,7 +719,7 @@ uvicorn==0.22.0
# via open-webui
# via open-webui
uvloop==0.19.0
uvloop==0.19.0
# via uvicorn
# via uvicorn
validators==0.
28.1
validators==0.
33.0
# via open-webui
# via open-webui
watchfiles==0.21.0
watchfiles==0.21.0
# via uvicorn
# via uvicorn
...
...
src/app.css
View file @
c869652e
...
@@ -158,3 +158,12 @@ input[type='number'] {
...
@@ -158,3 +158,12 @@ input[type='number'] {
.password
{
.password
{
-webkit-text-security
:
disc
;
-webkit-text-security
:
disc
;
}
}
.codespan
{
color
:
#eb5757
;
border-width
:
0px
;
padding
:
3px
8px
;
font-size
:
0.8em
;
font-weight
:
600
;
@apply
rounded-md
dark
:
bg-gray-800
bg-gray-100
mx-0
.5
;
}
src/lib/apis/chats/index.ts
View file @
c869652e
...
@@ -32,10 +32,15 @@ export const createNewChat = async (token: string, chat: object) => {
...
@@ -32,10 +32,15 @@ export const createNewChat = async (token: string, chat: object) => {
return
res
;
return
res
;
};
};
export
const
getChatList
=
async
(
token
:
string
=
''
)
=>
{
export
const
getChatList
=
async
(
token
:
string
=
''
,
page
:
number
|
null
=
null
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
searchParams
=
new
URLSearchParams
();
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/chats/`
,
{
if
(
page
!==
null
)
{
searchParams
.
append
(
'
page
'
,
`
${
page
}
`
);
}
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/chats/?
${
searchParams
.
toString
()}
`
,
{
method
:
'
GET
'
,
method
:
'
GET
'
,
headers
:
{
headers
:
{
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
...
...
src/lib/components/chat/Chat.svelte
View file @
c869652e
...
@@ -25,7 +25,8 @@
...
@@ -25,7 +25,8 @@
user,
user,
socket,
socket,
showCallOverlay,
showCallOverlay,
tools
tools,
currentChatPage
} from '$lib/stores';
} from '$lib/stores';
import {
import {
convertMessagesToHistory,
convertMessagesToHistory,
...
@@ -421,7 +422,9 @@
...
@@ -421,7 +422,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
}
}
};
};
...
@@ -467,7 +470,9 @@
...
@@ -467,7 +470,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
}
}
};
};
...
@@ -627,7 +632,9 @@
...
@@ -627,7 +632,9 @@
tags: [],
tags: [],
timestamp: Date.now()
timestamp: Date.now()
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await chatId.set(chat.id);
await chatId.set(chat.id);
} else {
} else {
await chatId.set('local');
await chatId.set('local');
...
@@ -703,7 +710,9 @@
...
@@ -703,7 +710,9 @@
})
})
);
);
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
return _responses;
return _responses;
};
};
...
@@ -803,8 +812,8 @@
...
@@ -803,8 +812,8 @@
...(params ?? $settings.params ?? {}),
...(params ?? $settings.params ?? {}),
stop:
stop:
params?.stop ?? $settings?.params?.stop ?? undefined
params?.stop ?? $settings?.params?.stop ?? undefined
? (params?.stop ?? $settings.params.stop).map(
(str) =>
? (params?.stop
.split(',').map((token) => token.trim())
?? $settings.params.stop).map(
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
(str) =>
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
)
)
: undefined,
: undefined,
num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
...
@@ -949,7 +958,9 @@
...
@@ -949,7 +958,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
}
}
} else {
} else {
...
@@ -1103,8 +1114,8 @@
...
@@ -1103,8 +1114,8 @@
seed: params?.seed ?? $settings?.params?.seed ?? undefined,
seed: params?.seed ?? $settings?.params?.seed ?? undefined,
stop:
stop:
params?.stop ?? $settings?.params?.stop ?? undefined
params?.stop ?? $settings?.params?.stop ?? undefined
? (params?.stop ?? $settings.params.stop).map(
(str) =>
? (params?.stop
.split(',').map((token) => token.trim())
?? $settings.params.stop).map(
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
(str) =>
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
)
)
: undefined,
: undefined,
temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined,
temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined,
...
@@ -1128,7 +1139,6 @@
...
@@ -1128,7 +1139,6 @@
if (res && res.ok && res.body) {
if (res && res.ok && res.body) {
const textStream = await createOpenAITextStream(res.body, $settings.splitLargeChunks);
const textStream = await createOpenAITextStream(res.body, $settings.splitLargeChunks);
let lastUsage = null;
for await (const update of textStream) {
for await (const update of textStream) {
const { value, done, citations, error, usage } = update;
const { value, done, citations, error, usage } = update;
...
@@ -1154,7 +1164,7 @@
...
@@ -1154,7 +1164,7 @@
}
}
if (usage) {
if (usage) {
lastUsage = usage
;
responseMessage.info = { ...usage, openai: true }
;
}
}
if (citations) {
if (citations) {
...
@@ -1208,10 +1218,6 @@
...
@@ -1208,10 +1218,6 @@
document.getElementById(`speak-button-${responseMessage.id}`)?.click();
document.getElementById(`speak-button-${responseMessage.id}`)?.click();
}
}
if (lastUsage) {
responseMessage.info = { ...lastUsage, openai: true };
}
if ($chatId == _chatId) {
if ($chatId == _chatId) {
if ($settings.saveChatHistory ?? true) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, {
chat = await updateChatById(localStorage.token, _chatId, {
...
@@ -1221,7 +1227,9 @@
...
@@ -1221,7 +1227,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
}
}
} else {
} else {
...
@@ -1386,7 +1394,9 @@
...
@@ -1386,7 +1394,9 @@
if ($settings.saveChatHistory ?? true) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
};
};
...
...
src/lib/components/chat/MessageInput.svelte
View file @
c869652e
...
@@ -384,7 +384,7 @@
...
@@ -384,7 +384,7 @@
{#if atSelectedModel !== undefined}
{#if atSelectedModel !== undefined}
<div
<div
class="px-3 py-2.5 text-left w-full flex justify-between items-center absolute bottom-0 left-0 right-0 bg-gradient-to-t from-50% from-white dark:from-gray-900"
class="px-3 py-2.5 text-left w-full flex justify-between items-center absolute bottom-0 left-0 right-0 bg-gradient-to-t from-50% from-white dark:from-gray-900
z-50
"
>
>
<div class="flex items-center gap-2 text-sm dark:text-gray-500">
<div class="flex items-center gap-2 text-sm dark:text-gray-500">
<img
<img
...
...
src/lib/components/chat/MessageInput/Models.svelte
View file @
c869652e
...
@@ -147,8 +147,8 @@
...
@@ -147,8 +147,8 @@
<div class="m-1 overflow-y-auto p-1 rounded-r-lg space-y-0.5 scrollbar-hidden">
<div class="m-1 overflow-y-auto p-1 rounded-r-lg space-y-0.5 scrollbar-hidden">
{#each filteredModels as model, modelIdx}
{#each filteredModels as model, modelIdx}
<button
<button
class="
px-3 py-1.5 rounded-xl w-full text-left {modelIdx === selectedIdx
class="px-3 py-1.5 rounded-xl w-full text-left {modelIdx === selectedIdx
? '
bg-gray-50 dark:bg-gray-850
selected-command-option-button'
? 'bg-gray-50 dark:bg-gray-850 selected-command-option-button'
: ''}"
: ''}"
type="button"
type="button"
on:click={() => {
on:click={() => {
...
@@ -159,13 +159,18 @@
...
@@ -159,13 +159,18 @@
}}
}}
on:focus={() => {}}
on:focus={() => {}}
>
>
<div class=" font-medium text-black dark:text-gray-100 line-clamp-1">
<div class="flex font-medium text-black dark:text-gray-100 line-clamp-1">
<img
src={model?.info?.meta?.profile_image_url ?? '/static/favicon.png'}
alt={model?.name ?? model.id}
class="rounded-full size-6 items-center mr-2"
/>
{model.name}
{model.name}
</div>
</div>
<!-- <div class=" text-xs text-gray-600 line-clamp-1">
<!-- <div class=" text-xs text-gray-600 line-clamp-1">
{doc.title}
{doc.title}
</div> -->
</div> -->
</button>
</button>
{/each}
{/each}
</div>
</div>
...
...
src/lib/components/chat/Messages.svelte
View file @
c869652e
<script lang="ts">
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { chats, config, settings, user as _user, mobile } from '$lib/stores';
import { chats, config, settings, user as _user, mobile
, currentChatPage
} from '$lib/stores';
import { tick, getContext, onMount } from 'svelte';
import { tick, getContext, onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
...
@@ -90,7 +90,8 @@
...
@@ -90,7 +90,8 @@
history: history
history: history
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
};
};
const confirmEditResponseMessage = async (messageId, content) => {
const confirmEditResponseMessage = async (messageId, content) => {
...
@@ -146,12 +147,14 @@
...
@@ -146,12 +147,14 @@
await tick();
await tick();
const element = document.getElementById('messages-container');
if ($settings?.scrollOnBranchChange ?? true) {
autoScroll = element.scrollHeight - element.scrollTop <= element.clientHeight + 50;
const element = document.getElementById('messages-container');
autoScroll = element.scrollHeight - element.scrollTop <= element.clientHeight + 50;
setTimeout(() => {
setTimeout(() => {
scrollToBottom();
scrollToBottom();
}, 100);
}, 100);
}
};
};
const showNextMessage = async (message) => {
const showNextMessage = async (message) => {
...
@@ -195,12 +198,14 @@
...
@@ -195,12 +198,14 @@
await tick();
await tick();
const element = document.getElementById('messages-container');
if ($settings?.scrollOnBranchChange ?? true) {
autoScroll = element.scrollHeight - element.scrollTop <= element.clientHeight + 50;
const element = document.getElementById('messages-container');
autoScroll = element.scrollHeight - element.scrollTop <= element.clientHeight + 50;
setTimeout(() => {
setTimeout(() => {
scrollToBottom();
scrollToBottom();
}, 100);
}, 100);
}
};
};
const deleteMessageHandler = async (messageId) => {
const deleteMessageHandler = async (messageId) => {
...
...
src/lib/components/chat/Messages/CodeBlock.svelte
View file @
c869652e
...
@@ -218,7 +218,7 @@ __builtins__.input = input`);
...
@@ -218,7 +218,7 @@ __builtins__.input = input`);
}
}
</script>
</script>
<div class="m
b-4
" dir="ltr">
<div class="m
y-2
" dir="ltr">
<div
<div
class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
>
>
...
...
src/lib/components/chat/Messages/CompareMessages.svelte
View file @
c869652e
...
@@ -118,47 +118,47 @@
...
@@ -118,47 +118,47 @@
currentMessageId = message.id;
currentMessageId = message.id;
let messageId = message.id;
let messageId = message.id;
console.log(messageId);
console.log(messageId);
//
//
let messageChildrenIds = history.messages[messageId].childrenIds;
let messageChildrenIds = history.messages[messageId].childrenIds;
while (messageChildrenIds.length !== 0) {
while (messageChildrenIds.length !== 0) {
messageId = messageChildrenIds.at(-1);
messageId = messageChildrenIds.at(-1);
messageChildrenIds = history.messages[messageId].childrenIds;
messageChildrenIds = history.messages[messageId].childrenIds;
}
}
history.currentId = messageId;
history.currentId = messageId;
dispatch('change');
dispatch('change');
}
}
}}
}}
>
>
<ResponseMessage
{#key history.currentId}
message={groupedMessages[model].messages[groupedMessagesIdx[model]]}
<ResponseMessage
siblings={groupedMessages[model].messages.map((m) => m.id)}
message={groupedMessages[model].messages[groupedMessagesIdx[model]]}
isLastMessage={true}
siblings={groupedMessages[model].messages.map((m) => m.id)}
{updateChatMessages}
isLastMessage={true}
{confirmEditResponseMessage}
{updateChatMessages}
showPreviousMessage={() => showPreviousMessage(model)}
{confirmEditResponseMessage}
showNextMessage={() => showNextMessage(model)}
showPreviousMessage={() => showPreviousMessage(model)}
{readOnly}
showNextMessage={() => showNextMessage(model)}
{rateMessage}
{readOnly}
{copyToClipboard}
{rateMessage}
{continueGeneration}
{copyToClipboard}
regenerateResponse={async (message) => {
{continueGeneration}
regenerateResponse(message);
regenerateResponse={async (message) => {
await tick();
regenerateResponse(message);
groupedMessagesIdx[model] = groupedMessages[model].messages.length - 1;
await tick();
}}
groupedMessagesIdx[model] = groupedMessages[model].messages.length - 1;
on:save={async (e) => {
}}
console.log('save', e);
on:save={async (e) => {
console.log('save', e);
const message = e.detail;
history.messages[message.id] = message;
const message = e.detail;
await updateChatById(localStorage.token, chatId, {
history.messages[message.id] = message;
messages: messages,
await updateChatById(localStorage.token, chatId, {
history: history
messages: messages,
});
history: history
}}
});
/>
}}
/>
{/key}
</div>
</div>
{/if}
{/if}
{/each}
{/each}
...
...
src/lib/components/chat/Messages/HTMLRenderer.svelte
0 → 100644
View file @
c869652e
<script lang="ts">
import Image from '$lib/components/common/Image.svelte';
import CodeBlock from './CodeBlock.svelte';
/* The html content of the tag */
export let html; //: string;
let parsedHTML = [html];
export let images;
export let codes;
// all images are in {{IMAGE_0}}, {{IMAGE_1}}.... format
// all codes are in {{CODE_0}}, {{CODE_1}}.... format
const rules = [];
rules.forEach((rule) => {
parsedHTML = parsedHTML.map((substr) => substr.split(rule.regex)).flat();
});
</script>
{#each parsedHTML as part}
{@const match = rules.find((rule) => rule.regex.test(part))}
{#if match}
<svelte:component this={match.component} {...match.props}>
{@html part}
</svelte:component>
{:else}
{@html part}
{/if}
{/each}
src/lib/components/chat/Messages/MarkdownInlineTokens.svelte
0 → 100644
View file @
c869652e
<script lang="ts">
import type { Token } from 'marked';
import { unescapeHtml } from '$lib/utils';
import Image from '$lib/components/common/Image.svelte';
export let id: string;
export let tokens: Token[];
</script>
{#each tokens as token}
{#if token.type === 'escape'}
{unescapeHtml(token.text)}
{:else if token.type === 'html'}
{@html token.text}
{:else if token.type === 'link'}
<a href={token.href} target="_blank" rel="nofollow" title={token.title}>{token.text}</a>
{:else if token.type === 'image'}
<Image src={token.href} alt={token.text} />
{:else if token.type === 'strong'}
<strong>
<svelte:self id={`${id}-strong`} tokens={token.tokens} />
</strong>
{:else if token.type === 'em'}
<em>
<svelte:self id={`${id}-em`} tokens={token.tokens} />
</em>
{:else if token.type === 'codespan'}
<code class="codespan">{unescapeHtml(token.text.replaceAll('&', '&'))}</code>
{:else if token.type === 'br'}
<br />
{:else if token.type === 'del'}
<del>
<svelte:self id={`${id}-del`} tokens={token.tokens} />
</del>
{:else if token.type === 'text'}
{unescapeHtml(token.text)}
{/if}
{/each}
src/lib/components/chat/Messages/MarkdownTokens.svelte
0 → 100644
View file @
c869652e
<script lang="ts">
import { marked } from 'marked';
import type { Token } from 'marked';
import { revertSanitizedResponseContent, unescapeHtml } from '$lib/utils';
import { onMount } from 'svelte';
import Image from '$lib/components/common/Image.svelte';
import CodeBlock from '$lib/components/chat/Messages/CodeBlock.svelte';
import MarkdownInlineTokens from '$lib/components/chat/Messages/MarkdownInlineTokens.svelte';
export let id: string;
export let tokens: Token[];
export let top = true;
let containerElement;
const headerComponent = (depth: number) => {
return 'h' + depth;
};
const renderer = new marked.Renderer();
// For code blocks with simple backticks
renderer.codespan = (code) => {
return `<code class="codespan">${code.replaceAll('&', '&')}</code>`;
};
let codes = [];
renderer.code = (code, lang) => {
codes.push({
code: code,
lang: lang
});
codes = codes;
const codeId = `${id}-${codes.length}`;
const interval = setInterval(() => {
const codeElement = document.getElementById(`code-${codeId}`);
if (codeElement) {
clearInterval(interval);
// If the code is already loaded, don't load it again
if (codeElement.innerHTML) {
return;
}
new CodeBlock({
target: codeElement,
props: {
id: `${id}-${codes.length}`,
lang: lang,
code: revertSanitizedResponseContent(code)
},
hydrate: true,
$$inline: true
});
}
}, 10);
return `<div id="code-${id}-${codes.length}"></div>`;
};
let images = [];
renderer.image = (href, title, text) => {
images.push({
href: href,
title: title,
text: text
});
images = images;
const imageId = `${id}-${images.length}`;
const interval = setInterval(() => {
const imageElement = document.getElementById(`image-${imageId}`);
if (imageElement) {
clearInterval(interval);
// If the image is already loaded, don't load it again
if (imageElement.innerHTML) {
return;
}
console.log('image', href, text);
new Image({
target: imageElement,
props: {
src: href,
alt: text
},
$$inline: true
});
}
}, 10);
return `<div id="image-${id}-${images.length}"></div>`;
};
// Open all links in a new tab/window (from https://github.com/markedjs/marked/issues/655#issuecomment-383226346)
const origLinkRenderer = renderer.link;
renderer.link = (href, title, text) => {
const html = origLinkRenderer.call(renderer, href, title, text);
return html.replace(/^<a /, '<a target="_blank" rel="nofollow" ');
};
const { extensions, ...defaults } = marked.getDefaults() as marked.MarkedOptions & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extensions: any;
};
$: if (tokens) {
images = [];
codes = [];
}
</script>
<div bind:this={containerElement} class="flex flex-col">
{#each tokens as token, tokenIdx (`${id}-${tokenIdx}`)}
{#if token.type === 'code'}
{#if token.lang === 'mermaid'}
<pre class="mermaid">{revertSanitizedResponseContent(token.text)}</pre>
{:else}
<CodeBlock
id={`${id}-${tokenIdx}`}
lang={token?.lang ?? ''}
code={revertSanitizedResponseContent(token?.text ?? '')}
/>
{/if}
{:else}
{@html marked.parse(token.raw, {
...defaults,
gfm: true,
breaks: true,
renderer
})}
{/if}
{/each}
</div>
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
c869652e
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
import Spinner from '$lib/components/common/Spinner.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import WebSearchResults from './ResponseMessage/WebSearchResults.svelte';
import WebSearchResults from './ResponseMessage/WebSearchResults.svelte';
import Sparkles from '$lib/components/icons/Sparkles.svelte';
import Sparkles from '$lib/components/icons/Sparkles.svelte';
import MarkdownTokens from './MarkdownTokens.svelte';
export let message;
export let message;
export let siblings;
export let siblings;
...
@@ -55,7 +56,6 @@
...
@@ -55,7 +56,6 @@
export let copyToClipboard: Function;
export let copyToClipboard: Function;
export let continueGeneration: Function;
export let continueGeneration: Function;
export let regenerateResponse: Function;
export let regenerateResponse: Function;
export let chatActionHandler: Function;
let model = null;
let model = null;
$: model = $models.find((m) => m.id === message.model);
$: model = $models.find((m) => m.id === message.model);
...
@@ -77,28 +77,16 @@
...
@@ -77,28 +77,16 @@
let selectedCitation = null;
let selectedCitation = null;
$: tokens = marked.lexer(
let tokens;
replaceTokens(sanitizeResponseContent(message?.content), model?.name, $user?.name)
);
const renderer = new marked.Renderer();
$: (async () => {
if (message?.content) {
// For code blocks with simple backticks
tokens = marked.lexer(
renderer.codespan = (code) => {
replaceTokens(sanitizeResponseContent(message?.content), model?.name, $user?.name)
return `<code>${code.replaceAll('&', '&')}</code>`;
);
};
// console.log(message?.content, tokens);
}
// Open all links in a new tab/window (from https://github.com/markedjs/marked/issues/655#issuecomment-383226346)
})();
const origLinkRenderer = renderer.link;
renderer.link = (href, title, text) => {
const html = origLinkRenderer.call(renderer, href, title, text);
return html.replace(/^<a /, '<a target="_blank" rel="nofollow" ');
};
const { extensions, ...defaults } = marked.getDefaults() as marked.MarkedOptions & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extensions: any;
};
$: if (message) {
$: if (message) {
renderStyling();
renderStyling();
...
@@ -418,294 +406,581 @@
...
@@ -418,294 +406,581 @@
{/if}
{/if}
</Name>
</Name>
{#if (message?.files ?? []).filter((f) => f.type === 'image').length > 0}
<div>
<div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
{#if (message?.files ?? []).filter((f) => f.type === 'image').length > 0}
{#each message.files as file}
<div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
<div>
{#each message.files as file}
{#if file.type === 'image'}
<div>
<Image src={file.url} />
{#if file.type === 'image'}
{/if}
<Image src={file.url} />
</div>
{/if}
{/each}
</div>
</div>
{/each}
{/if}
</div>
{/if}
<div
class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-headings:my-0 prose-headings:-mb-4 prose-p:m-0 prose-p:-mb-6 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-img:my-0 prose-ul:-my-4 prose-ol:-my-4 prose-li:-my-3 prose-ul:-mb-6 prose-ol:-mb-8 prose-ol:p-0 prose-li:-mb-4 whitespace-pre-line"
<div
>
class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-p:my-0 prose-img:my-1 prose-headings:my-1 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-ul:-my-2 prose-ol:-my-2 prose-li:-my-3 whitespace-pre-line"
<div>
>
{#if (message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]).length > 0}
<div>
{@const status = (
{#if (message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]).length > 0}
message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]
{@const status = (
).at(-1)}
message?.statusHistory ?? [...(message?.status ? [message?.status] : [])]
<div class="flex items-center gap-2 pt-0.5 pb-1">
).at(-1)}
{#if status.done === false}
<div class="flex items-center gap-2 pt-0.5 pb-1">
<div class="">
{#if status.done === false}
<Spinner className="size-4" />
<div class="">
</div>
<Spinner className="size-4" />
{/if}
</div>
{/if}
{#if status?.action === 'web_search' && status?.urls}
{#if status?.action === 'web_search' && status?.urls}
<WebSearchResults {status}>
<WebSearchResults {status}>
<div class="flex flex-col justify-center -space-y-0.5">
<div class="text-base line-clamp-1 text-wrap">
{status?.description}
</div>
</div>
</WebSearchResults>
{:else}
<div class="flex flex-col justify-center -space-y-0.5">
<div class="flex flex-col justify-center -space-y-0.5">
<div class="text-base line-clamp-1 text-wrap">
<div class="
text-gray-500 dark:text-gray-500
text-base line-clamp-1 text-wrap">
{status?.description}
{status?.description}
</div>
</div>
</div>
</div>
</WebSearchResults>
{/if}
{:else}
</div>
<div class="flex flex-col justify-center -space-y-0.5">
{/if}
<div class=" text-gray-500 dark:text-gray-500 text-base line-clamp-1 text-wrap">
{status?.description}
{#if edit === true}
</div>
<div class="w-full bg-gray-50 dark:bg-gray-800 rounded-3xl px-5 py-3 my-2">
</div>
<textarea
{/if}
id="message-edit-{message.id}"
</div>
bind:this={editTextAreaElement}
{/if}
class=" bg-transparent outline-none w-full resize-none"
bind:value={editedContent}
{#if edit === true}
on:input={(e) => {
<div class="w-full bg-gray-50 dark:bg-gray-800 rounded-3xl px-5 py-3 my-2">
e.target.style.height = '';
<textarea
e.target.style.height = `${e.target.scrollHeight}px`;
id="message-edit-{message.id}"
bind:this={editTextAreaElement}
class=" bg-transparent outline-none w-full resize-none"
bind:value={editedContent}
on:input={(e) => {
e.target.style.height = '';
e.target.style.height = `${e.target.scrollHeight}px`;
}}
on:keydown={(e) => {
if (e.key === 'Escape') {
document.getElementById('close-edit-message-button')?.click();
}
const isCmdOrCtrlPressed = e.metaKey || e.ctrlKey;
const isEnterPressed = e.key === 'Enter';
if (isCmdOrCtrlPressed && isEnterPressed) {
document.getElementById('save-edit-message-button')?.click();
}
}}
/>
<div class=" mt-2 mb-1 flex justify-end space-x-1.5 text-sm font-medium">
<button
id="close-edit-message-button"
class="px-4 py-2 bg-white hover:bg-gray-100 text-gray-800 transition rounded-3xl"
on:click={() => {
cancelEditMessage();
}}
}}
>
on:keydown={(e) => {
{$i18n.t('Cancel')}
if (e.key === 'Escape') {
</button>
document.getElementById('close-edit-message-button')?.click();
}
<button
id="save-edit-message-button"
const isCmdOrCtrlPressed = e.metaKey || e.ctrlKey;
class=" px-4 py-2 bg-gray-900 hover:bg-gray-850 text-gray-100 transition rounded-3xl"
const isEnterPressed = e.key === 'Enter';
on:click={() => {
editMessageConfirmHandler();
if (isCmdOrCtrlPressed && isEnterPressed) {
document.getElementById('save-edit-message-button')?.click();
}
}}
}}
>
/>
{$i18n.t('Save')}
</button>
</div>
</div>
{:else}
<div class="w-full">
{#if message.content === '' && !message.error}
<Skeleton />
{:else if message.content && message.error !== true}
<!-- always show message contents even if there's an error -->
<!-- unless message.error === true which is legacy error handling, where the error message is stored in message.content -->
{#each tokens as token, tokenIdx}
{#if token.type === 'code'}
{#if token.lang === 'mermaid'}
<pre class="mermaid">{revertSanitizedResponseContent(token.text)}</pre>
{:else}
<CodeBlock
id={`${message.id}-${tokenIdx}`}
lang={token?.lang ?? ''}
code={revertSanitizedResponseContent(token?.text ?? '')}
/>
{/if}
{:else}
{@html marked.parse(token.raw, {
...defaults,
gfm: true,
breaks: true,
renderer
})}
{/if}
{/each}
{/if}
{#if message.error}
<div class=" mt-2 mb-1 flex justify-end space-x-1.5 text-sm font-medium">
<div
<button
class="flex mt-2 mb-4 space-x-2 border px-4 py-3 border-red-800 bg-red-800/30 font-medium rounded-lg"
id="close-edit-message-button"
>
class="px-4 py-2 bg-white hover:bg-gray-100 text-gray-800 transition rounded-3xl"
<svg
on:click={() => {
xmlns="http://www.w3.org/2000/svg"
cancelEditMessage();
fill="none"
}}
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-5 h-5 self-center"
>
>
<path
{$i18n.t('Cancel')}
stroke-linecap="round"
</button>
stroke-linejoin="round"
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
<button
/>
id="save-edit-message-button"
</svg>
class=" px-4 py-2 bg-gray-900 hover:bg-gray-850 text-gray-100 transition rounded-3xl"
on:click={() => {
<div class=" self-center">
editMessageConfirmHandler();
{message?.error?.content ?? message.content}
}}
</div>
>
{$i18n.t('Save')}
</button>
</div>
</div>
{/if}
</div>
{:else}
{#if message.citations}
<div class="w-full flex flex-col">
<div class="mt-1 mb-2 w-full flex gap-1 items-center flex-wrap">
{#if message.content === '' && !message.error}
{#each message.citations.reduce((acc, citation) => {
<Skeleton />
citation.document.forEach((document, index) => {
{:else if message.content && message.error !== true}
const metadata = citation.metadata?.[index];
<!-- always show message contents even if there's an error -->
const id = metadata?.source ?? 'N/A';
<!-- unless message.error === true which is legacy error handling, where the error message is stored in message.content -->
let source = citation?.source;
{#key message.id}
<MarkdownTokens id={message.id} {tokens} />
{/key}
{/if}
{#if message.error}
<div
class="flex mt-2 mb-4 space-x-2 border px-4 py-3 border-red-800 bg-red-800/30 font-medium rounded-lg"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-5 h-5 self-center"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
/>
</svg>
if (metadata?.name) {
<div class=" self-center">
source = { ...source, name: metadata.name };
{message?.error?.content ?? message.content}
}
</div>
</div>
{/if}
{#if message.citations}
<div class="mt-1 mb-2 w-full flex gap-1 items-center flex-wrap">
{#each message.citations.reduce((acc, citation) => {
citation.document.forEach((document, index) => {
const metadata = citation.metadata?.[index];
const id = metadata?.source ?? 'N/A';
let source = citation?.source;
if (metadata?.name) {
source = { ...source, name: metadata.name };
}
// Check if ID looks like a URL
if (id.startsWith('http://') || id.startsWith('https://')) {
source = { name: id };
}
const existingSource = acc.find((item) => item.id === id);
if (existingSource) {
existingSource.document.push(document);
existingSource.metadata.push(metadata);
} else {
acc.push( { id: id, source: source, document: [document], metadata: metadata ? [metadata] : [] } );
}
});
return acc;
}, []) as citation, idx}
<div class="flex gap-1 text-xs font-semibold">
<button
class="flex dark:text-gray-300 py-1 px-1 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-xl"
on:click={() => {
showCitationModal = true;
selectedCitation = citation;
}}
>
<div class="bg-white dark:bg-gray-700 rounded-full size-4">
{idx + 1}
</div>
<div class="flex-1 mx-2 line-clamp-1">
{citation.source.name}
</div>
</button>
</div>
{/each}
</div>
{/if}
</div>
{/if}
</div>
</div>
// Check if ID looks like a URL
{#if !edit}
if (id.startsWith('http://') || id.startsWith('https://')) {
{#if message.done || siblings.length > 1}
source = { name: id };
<div
}
class=" flex justify-start overflow-x-auto buttons text-gray-600 dark:text-gray-500"
>
{#if siblings.length > 1}
<div class="flex self-center min-w-fit" dir="ltr">
<button
class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
on:click={() => {
showPreviousMessage(message);
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2.5"
class="size-3.5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.75 19.5 8.25 12l7.5-7.5"
/>
</svg>
</button>
const existingSource = acc.find((item) => item.id === id);
<div
class="text-sm tracking-widest font-semibold self-center dark:text-gray-100 min-w-fit"
>
{siblings.indexOf(message.id) + 1}/{siblings.length}
</div>
if (existingSource) {
<button
existingSource.document.push(document);
class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
existingSource.metadata.push(metadata);
on:click={() => {
} else {
showNextMessage(message);
acc.push( { id: id, source: source, document: [document], metadata: metadata ? [metadata] : [] } );
}}
}
>
});
<svg
return acc;
xmlns="http://www.w3.org/2000/svg"
}, []) as citation, idx}
fill="none"
<div class="flex gap-1 text-xs font-semibold">
viewBox="0 0 24 24"
<button
stroke="currentColor"
class="flex dark:text-gray-300 py-1 px-1 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-xl"
stroke-width="2.5"
on:click={() => {
class="size-3.5"
showCitationModal = true;
>
selectedCitation = citation;
<path
}}
stroke-linecap="round"
>
stroke-linejoin="round"
<div class="bg-white dark:bg-gray-700 rounded-full size-4">
d="m8.25 4.5 7.5 7.5-7.5 7.5"
{idx + 1}
/>
</div>
</svg>
<div class="flex-1 mx-2 line-clamp-1">
</button>
{citation.source.name}
</div>
</button>
</div>
{/each}
</div>
</div>
{/if}
{/if}
{#if message.done || siblings.length > 1}
{#if message.done}
<div
{#if !readOnly}
class=" flex justify-start overflow-x-auto buttons text-gray-600 dark:text-gray-500"
<Tooltip content={$i18n.t('Edit')} placement="bottom">
>
<button
{#if siblings.length > 1}
class="{isLastMessage
<div class="flex self-center min-w-fit" dir="ltr">
? 'visible'
<button
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
on:click={() => {
on:click={() => {
editMessageHandler();
showPreviousMessage(message);
}}
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
/>
</svg>
</button>
</Tooltip>
{/if}
<Tooltip content={$i18n.t('Copy')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition copy-response-button"
on:click={() => {
copyToClipboard(message.content);
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184"
/>
</svg>
</button>
</Tooltip>
<Tooltip content={$i18n.t('Read Aloud')} placement="bottom">
<button
id="speak-button-{message.id}"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
on:click={() => {
if (!loadingSpeech) {
toggleSpeakMessage(message);
}
}}
>
{#if loadingSpeech}
<svg
class=" w-4 h-4"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><style>
.spinner_S1WN {
animation: spinner_MGfb 0.8s linear infinite;
animation-delay: -0.8s;
}
.spinner_Km9P {
animation-delay: -0.65s;
}
.spinner_JApP {
animation-delay: -0.5s;
}
@keyframes spinner_MGfb {
93.75%,
100% {
opacity: 0.2;
}
}
</style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
class="spinner_S1WN spinner_Km9P"
cx="12"
cy="12"
r="3"
/><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
>
{:else if speaking}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M17.25 9.75 19.5 12m0 0 2.25 2.25M19.5 12l2.25-2.25M19.5 12l-2.25 2.25m-10.5-6 4.72-4.72a.75.75 0 0 1 1.28.53v15.88a.75.75 0 0 1-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.009 9.009 0 0 1 2.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75Z"
/>
</svg>
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M19.114 5.636a9 9 0 010 12.728M16.463 8.288a5.25 5.25 0 010 7.424M6.75 8.25l4.72-4.72a.75.75 0 011.28.53v15.88a.75.75 0 01-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.01 9.01 0 012.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75z"
/>
</svg>
{/if}
</button>
</Tooltip>
{#if $config?.features.enable_image_generation && !readOnly}
<Tooltip content={$i18n.t('Generate Image')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
on:click={() => {
if (!generatingImage) {
generateImage(message);
}
}}
>
{#if generatingImage}
<svg
class=" w-4 h-4"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><style>
.spinner_S1WN {
animation: spinner_MGfb 0.8s linear infinite;
animation-delay: -0.8s;
}
.spinner_Km9P {
animation-delay: -0.65s;
}
.spinner_JApP {
animation-delay: -0.5s;
}
@keyframes spinner_MGfb {
93.75%,
100% {
opacity: 0.2;
}
}
</style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
class="spinner_S1WN spinner_Km9P"
cx="12"
cy="12"
r="3"
/><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
>
{:else}
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
fill="none"
fill="none"
viewBox="0 0 24 24"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
stroke="currentColor"
stroke-width="2.5"
class="w-4 h-4"
class="size-3.5"
>
>
<path
<path
stroke-linecap="round"
stroke-linecap="round"
stroke-linejoin="round"
stroke-linejoin="round"
d="
M15.75 19.5 8.25 12l7.5-7.5
"
d="
m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H3.75A1.5 1.5 0 0 0 2.25 6v12a1.5 1.5 0 0 0 1.5 1.5Zm10.5-11.25h.008v.008h-.008V8.25Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z
"
/>
/>
</svg>
</svg>
</button>
{/if}
</button>
<div
</Tooltip>
class="text-sm tracking-widest font-semibold self-center dark:text-gray-100 min-w-fit"
{/if}
{#if message.info}
<Tooltip content={$i18n.t('Generation Info')} placement="bottom">
<button
class=" {isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition whitespace-pre-wrap"
on:click={() => {
console.log(message);
}}
id="info-{message.id}"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
>
{siblings.indexOf(message.id) + 1}/{siblings.length}
<path
</div>
stroke-linecap="round"
stroke-linejoin="round"
d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
/>
</svg>
</button>
</Tooltip>
{/if}
{#if !readOnly}
<Tooltip content={$i18n.t('Good Response')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
?.annotation?.rating ?? null) === 1
? 'bg-gray-100 dark:bg-gray-800'
: ''} dark:hover:text-white hover:text-black transition"
on:click={() => {
rateMessage(message.id, 1);
showRateComment = true;
window.setTimeout(() => {
document
.getElementById(`message-feedback-${message.id}`)
?.scrollIntoView();
}, 0);
}}
>
<svg
stroke="currentColor"
fill="none"
stroke-width="2.3"
viewBox="0 0 24 24"
stroke-linecap="round"
stroke-linejoin="round"
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
><path
d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"
/></svg
>
</button>
</Tooltip>
<Tooltip content={$i18n.t('Bad Response')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
?.annotation?.rating ?? null) === -1
? 'bg-gray-100 dark:bg-gray-800'
: ''} dark:hover:text-white hover:text-black transition"
on:click={() => {
rateMessage(message.id, -1);
showRateComment = true;
window.setTimeout(() => {
document
.getElementById(`message-feedback-${message.id}`)
?.scrollIntoView();
}, 0);
}}
>
<svg
stroke="currentColor"
fill="none"
stroke-width="2.3"
viewBox="0 0 24 24"
stroke-linecap="round"
stroke-linejoin="round"
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
><path
d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"
/></svg
>
</button>
</Tooltip>
{#if isLastMessage}
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
<button
<button
class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
type="button"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
on:click={() => {
showNextMessage(message
);
continueGeneration(
);
}}
}}
>
>
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
fill="none"
fill="none"
viewBox="0 0 24 24"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
stroke="currentColor"
stroke-width="2.5"
class="w-4 h-4"
class="size-3.5"
>
>
<path
<path
stroke-linecap="round"
stroke-linecap="round"
stroke-linejoin="round"
stroke-linejoin="round"
d="m8.25 4.5 7.5 7.5-7.5 7.5"
d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.91 11.672a.375.375 0 0 1 0 .656l-5.603 3.113a.375.375 0 0 1-.557-.328V8.887c0-.286.307-.466.557-.327l5.603 3.112Z"
/>
/>
</svg>
</svg>
</button>
</button>
</div>
</Tooltip>
{/if}
{#if message.done}
{#if !readOnly}
<Tooltip content={$i18n.t('Edit')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
on:click={() => {
editMessageHandler();
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
/>
</svg>
</button>
</Tooltip>
{/if}
<Tooltip content={$i18n.t('
Copy
')} placement="bottom">
<Tooltip content={$i18n.t('
Regenerate
')} placement="bottom">
<button
<button
type="button"
class="{isLastMessage
class="{isLastMessage
? 'visible'
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition
copy
-response-button"
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition
regenerate
-response-button"
on:click={() => {
on:click={() => {
copyToClipboard(message.content);
showRateComment = false;
regenerateResponse(message);
}}
}}
>
>
<svg
<svg
...
@@ -719,365 +994,55 @@
...
@@ -719,365 +994,55 @@
<path
<path
stroke-linecap="round"
stroke-linecap="round"
stroke-linejoin="round"
stroke-linejoin="round"
d="M1
5.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2
.25
2
.25 0 0
1-2.25 2.25H6.75A2
.25
2
.25 0 01
4.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184
"
d="M1
6.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8
.25
8
.25 0 0
013.803-3.7M4.031 9.865a8
.25
8
.25 0 01
13.803-3.7l3.181 3.182m0-4.991v4.99
"
/>
/>
</svg>
</svg>
</button>
</button>
</Tooltip>
</Tooltip>
<Tooltip content={$i18n.t('Read Aloud')} placement="bottom">
{#each model?.actions ?? [] as action}
<button
<Tooltip content={action.name} placement="bottom">
id="speak-button-{message.id}"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
on:click={() => {
if (!loadingSpeech) {
toggleSpeakMessage(message);
}
}}
>
{#if loadingSpeech}
<svg
class=" w-4 h-4"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><style>
.spinner_S1WN {
animation: spinner_MGfb 0.8s linear infinite;
animation-delay: -0.8s;
}
.spinner_Km9P {
animation-delay: -0.65s;
}
.spinner_JApP {
animation-delay: -0.5s;
}
@keyframes spinner_MGfb {
93.75%,
100% {
opacity: 0.2;
}
}
</style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
class="spinner_S1WN spinner_Km9P"
cx="12"
cy="12"
r="3"
/><circle
class="spinner_S1WN spinner_JApP"
cx="20"
cy="12"
r="3"
/></svg
>
{:else if speaking}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M17.25 9.75 19.5 12m0 0 2.25 2.25M19.5 12l2.25-2.25M19.5 12l-2.25 2.25m-10.5-6 4.72-4.72a.75.75 0 0 1 1.28.53v15.88a.75.75 0 0 1-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.009 9.009 0 0 1 2.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75Z"
/>
</svg>
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M19.114 5.636a9 9 0 010 12.728M16.463 8.288a5.25 5.25 0 010 7.424M6.75 8.25l4.72-4.72a.75.75 0 011.28.53v15.88a.75.75 0 01-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.01 9.01 0 012.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75z"
/>
</svg>
{/if}
</button>
</Tooltip>
{#if $config?.features.enable_image_generation && !readOnly}
<Tooltip content={$i18n.t('Generate Image')} placement="bottom">
<button
<button
type="button"
class="{isLastMessage
class="{isLastMessage
? 'visible'
? 'visible'
: 'invisible group-hover:visible'}
p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition"
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition
regenerate-response-button
"
on:click={() => {
on:click={() => {
if (!generatingImage) {
dispatch('action', action.id);
generateImage(message);
}
}}
}}
>
>
{#if generatingImage}
{#if action.icon_url}
<svg
<img
class=" w-4 h-4"
src={action.icon_url}
fill="currentColor"
class="w-4 h-4 {action.icon_url.includes('svg')
viewBox="0 0 24 24"
? 'dark:invert-[80%]'
xmlns="http://www.w3.org/2000/svg"
: ''}"
><style>
style="fill: currentColor;"
.spinner_S1WN {
alt={action.name}
animation: spinner_MGfb 0.8s linear infinite;
/>
animation-delay: -0.8s;
}
.spinner_Km9P {
animation-delay: -0.65s;
}
.spinner_JApP {
animation-delay: -0.5s;
}
@keyframes spinner_MGfb {
93.75%,
100% {
opacity: 0.2;
}
}
</style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
class="spinner_S1WN spinner_Km9P"
cx="12"
cy="12"
r="3"
/><circle
class="spinner_S1WN spinner_JApP"
cx="20"
cy="12"
r="3"
/></svg
>
{:else}
{:else}
<svg
<Sparkles strokeWidth="2.1" className="size-4" />
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H3.75A1.5 1.5 0 0 0 2.25 6v12a1.5 1.5 0 0 0 1.5 1.5Zm10.5-11.25h.008v.008h-.008V8.25Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z"
/>
</svg>
{/if}
{/if}
</button>
</button>
</Tooltip>
</Tooltip>
{/if}
{/each}
{#if message.info}
<Tooltip content={$i18n.t('Generation Info')} placement="bottom">
<button
class=" {isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition whitespace-pre-wrap"
on:click={() => {
console.log(message);
}}
id="info-{message.id}"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
/>
</svg>
</button>
</Tooltip>
{/if}
{#if !readOnly}
<Tooltip content={$i18n.t('Good Response')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
?.annotation?.rating ?? null) === 1
? 'bg-gray-100 dark:bg-gray-800'
: ''} dark:hover:text-white hover:text-black transition"
on:click={() => {
rateMessage(message.id, 1);
showRateComment = true;
window.setTimeout(() => {
document
.getElementById(`message-feedback-${message.id}`)
?.scrollIntoView();
}, 0);
}}
>
<svg
stroke="currentColor"
fill="none"
stroke-width="2.3"
viewBox="0 0 24 24"
stroke-linecap="round"
stroke-linejoin="round"
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
><path
d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"
/></svg
>
</button>
</Tooltip>
<Tooltip content={$i18n.t('Bad Response')} placement="bottom">
<button
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg {(message
?.annotation?.rating ?? null) === -1
? 'bg-gray-100 dark:bg-gray-800'
: ''} dark:hover:text-white hover:text-black transition"
on:click={() => {
rateMessage(message.id, -1);
showRateComment = true;
window.setTimeout(() => {
document
.getElementById(`message-feedback-${message.id}`)
?.scrollIntoView();
}, 0);
}}
>
<svg
stroke="currentColor"
fill="none"
stroke-width="2.3"
viewBox="0 0 24 24"
stroke-linecap="round"
stroke-linejoin="round"
class="w-4 h-4"
xmlns="http://www.w3.org/2000/svg"
><path
d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"
/></svg
>
</button>
</Tooltip>
{#if isLastMessage}
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
<button
type="button"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
continueGeneration();
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15.91 11.672a.375.375 0 0 1 0 .656l-5.603 3.113a.375.375 0 0 1-.557-.328V8.887c0-.286.307-.466.557-.327l5.603 3.112Z"
/>
</svg>
</button>
</Tooltip>
<Tooltip content={$i18n.t('Regenerate')} placement="bottom">
<button
type="button"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
showRateComment = false;
regenerateResponse(message);
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.3"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"
/>
</svg>
</button>
</Tooltip>
{#each model?.actions ?? [] as action}
<Tooltip content={action.name} placement="bottom">
<button
type="button"
class="{isLastMessage
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
dispatch('action', action.id);
}}
>
{#if action.icon_url}
<img
src={action.icon_url}
class="w-4 h-4 {action.icon_url.includes('svg')
? 'dark:invert-[80%]'
: ''}"
style="fill: currentColor;"
alt={action.name}
/>
{:else}
<Sparkles strokeWidth="2.1" className="size-4" />
{/if}
</button>
</Tooltip>
{/each}
{/if}
{/if}
{/if}
{/if}
</div>
{/if}
{/if}
{#if message.done && showRateComment}
<RateComment
messageId={message.id}
bind:show={showRateComment}
bind:message
on:submit={() => {
updateChatMessages();
}}
/>
{/if}
{/if}
</div>
</div>
{/if}
{/if}
</div>
{#if message.done && showRateComment}
<RateComment
messageId={message.id}
bind:show={showRateComment}
bind:message
on:submit={() => {
updateChatMessages();
}}
/>
{/if}
{/if}
</div>
</div>
</div>
</div>
</div>
</div>
...
...
src/lib/components/chat/Settings/Chats.svelte
View file @
c869652e
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import fileSaver from 'file-saver';
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
const { saveAs } = fileSaver;
import { chats, user, settings } from '$lib/stores';
import { chats, user, settings
, scrollPaginationEnabled, currentChatPage
} from '$lib/stores';
import {
import {
archiveAllChats,
archiveAllChats,
...
@@ -62,7 +62,9 @@
...
@@ -62,7 +62,9 @@
}
}
}
}
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
};
const exportChats = async () => {
const exportChats = async () => {
...
@@ -77,7 +79,10 @@
...
@@ -77,7 +79,10 @@
await archiveAllChats(localStorage.token).catch((error) => {
await archiveAllChats(localStorage.token).catch((error) => {
toast.error(error);
toast.error(error);
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
};
const deleteAllChatsHandler = async () => {
const deleteAllChatsHandler = async () => {
...
@@ -85,7 +90,10 @@
...
@@ -85,7 +90,10 @@
await deleteAllChats(localStorage.token).catch((error) => {
await deleteAllChats(localStorage.token).catch((error) => {
toast.error(error);
toast.error(error);
});
});
await chats.set(await getChatList(localStorage.token));
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
scrollPaginationEnabled.set(true);
};
};
const toggleSaveChatHistory = async () => {
const toggleSaveChatHistory = async () => {
...
...
src/lib/components/chat/Settings/Interface.svelte
View file @
c869652e
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
let responseAutoCopy = false;
let responseAutoCopy = false;
let widescreenMode = false;
let widescreenMode = false;
let splitLargeChunks = false;
let splitLargeChunks = false;
let scrollOnBranchChange = true;
let userLocation = false;
let userLocation = false;
// Interface
// Interface
...
@@ -39,6 +40,11 @@
...
@@ -39,6 +40,11 @@
saveSettings({ splitLargeChunks: splitLargeChunks });
saveSettings({ splitLargeChunks: splitLargeChunks });
};
};
const togglesScrollOnBranchChange = async () => {
scrollOnBranchChange = !scrollOnBranchChange;
saveSettings({ scrollOnBranchChange: scrollOnBranchChange });
};
const togglewidescreenMode = async () => {
const togglewidescreenMode = async () => {
widescreenMode = !widescreenMode;
widescreenMode = !widescreenMode;
saveSettings({ widescreenMode: widescreenMode });
saveSettings({ widescreenMode: widescreenMode });
...
@@ -141,6 +147,7 @@
...
@@ -141,6 +147,7 @@
chatBubble = $settings.chatBubble ?? true;
chatBubble = $settings.chatBubble ?? true;
widescreenMode = $settings.widescreenMode ?? false;
widescreenMode = $settings.widescreenMode ?? false;
splitLargeChunks = $settings.splitLargeChunks ?? false;
splitLargeChunks = $settings.splitLargeChunks ?? false;
scrollOnBranchChange = $settings.scrollOnBranchChange ?? true;
chatDirection = $settings.chatDirection ?? 'LTR';
chatDirection = $settings.chatDirection ?? 'LTR';
userLocation = $settings.userLocation ?? false;
userLocation = $settings.userLocation ?? false;
...
@@ -318,6 +325,28 @@
...
@@ -318,6 +325,28 @@
</div>
</div>
</div>
</div>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">
{$i18n.t('Scroll to bottom when switching between branches')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
togglesScrollOnBranchChange();
}}
type="button"
>
{#if scrollOnBranchChange === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
<div>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">
<div class=" self-center text-xs">
...
...
src/lib/components/chat/Tags.svelte
View file @
c869652e
...
@@ -8,7 +8,13 @@
...
@@ -8,7 +8,13 @@
getTagsById,
getTagsById,
updateChatById
updateChatById
} from '$lib/apis/chats';
} from '$lib/apis/chats';
import { tags as _tags, chats, pinnedChats } from '$lib/stores';
import {
tags as _tags,
chats,
pinnedChats,
currentChatPage,
scrollPaginationEnabled
} from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
...
@@ -46,11 +52,7 @@
...
@@ -46,11 +52,7 @@
tags: tags
tags: tags
});
});
console.log($_tags);
await _tags.set(await getAllChatTags(localStorage.token));
await _tags.set(await getAllChatTags(localStorage.token));
console.log($_tags);
if ($_tags.map((t) => t.name).includes(tagName)) {
if ($_tags.map((t) => t.name).includes(tagName)) {
if (tagName === 'pinned') {
if (tagName === 'pinned') {
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
...
@@ -62,8 +64,11 @@
...
@@ -62,8 +64,11 @@
dispatch('close');
dispatch('close');
}
}
} else {
} else {
await chats.set(await getChatList(localStorage.token));
// if the tag we deleted is no longer a valid tag, return to main chat list view
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await scrollPaginationEnabled.set(true);
}
}
};
};
...
...
src/lib/components/common/Image.svelte
View file @
c869652e
...
@@ -5,19 +5,21 @@
...
@@ -5,19 +5,21 @@
export let src = '';
export let src = '';
export let alt = '';
export let alt = '';
let _src
= '';
export let className
= '';
let _src = '';
$: _src = src.startsWith('/') ? `${WEBUI_BASE_URL}${src}` : src;
$: _src = src.startsWith('/') ? `${WEBUI_BASE_URL}${src}` : src;
let showImagePreview = false;
let showImagePreview = false;
</script>
</script>
<ImagePreview bind:show={showImagePreview} src={_src} {alt} />
<button
<button
class={className}
on:click={() => {
on:click={() => {
console.log('image preview');
showImagePreview = true;
showImagePreview = true;
}}
}}
>
>
<img src={_src} {alt} class="
max-h-96
rounded-lg" draggable="false" data-cy="image" />
<img src={_src} {alt} class=" rounded-lg
cursor-pointer
" draggable="false" data-cy="image" />
</button>
</button>
<ImagePreview bind:show={showImagePreview} src={_src} {alt} />
src/lib/components/common/ImagePreview.svelte
View file @
c869652e
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
let mounted = false;
let mounted = false;
let previewElement = null;
const downloadImage = (url, filename) => {
const downloadImage = (url, filename) => {
fetch(url)
fetch(url)
.then((response) => response.blob())
.then((response) => response.blob())
...
@@ -34,14 +36,14 @@
...
@@ -34,14 +36,14 @@
mounted = true;
mounted = true;
});
});
$: if (
mounted
) {
$: if (
show && previewElement
) {
if (show) {
document.body.appendChild(previewElement);
window.addEventListener('keydown', handleKeyDown);
window.addEventListener('keydown', handleKeyDown);
document.body.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
} else {
} else
if (previewElement)
{
window.removeEventListener('keydown', handleKeyDown);
window.removeEventListener('keydown', handleKeyDown);
document.body.
style.overflow = 'unset'
;
document.body.
removeChild(previewElement)
;
}
document.body.style.overflow = 'unset';
}
}
</script>
</script>
...
@@ -49,9 +51,10 @@
...
@@ -49,9 +51,10 @@
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
<div
class="fixed top-0 right-0 left-0 bottom-0 bg-black text-white w-full min-h-screen h-screen flex justify-center z-50 overflow-hidden overscroll-contain"
bind:this={previewElement}
class="modal fixed top-0 right-0 left-0 bottom-0 bg-black text-white w-full min-h-screen h-screen flex justify-center z-[9999] overflow-hidden overscroll-contain"
>
>
<div class=" absolute left-0 w-full flex justify-between">
<div class=" absolute left-0 w-full flex justify-between
select-none
">
<div>
<div>
<button
<button
class=" p-5"
class=" p-5"
...
@@ -95,6 +98,6 @@
...
@@ -95,6 +98,6 @@
</button>
</button>
</div>
</div>
</div>
</div>
<img {src} {alt} class=" mx-auto h-full object-scale-down" />
<img {src} {alt} class=" mx-auto h-full object-scale-down
select-none" draggable="false
" />
</div>
</div>
{/if}
{/if}
src/lib/components/common/Loader.svelte
0 → 100644
View file @
c869652e
<script lang="ts">
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
let loaderElement: HTMLElement;
onMount(() => {
const observer = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
dispatch('visible');
// observer.unobserve(loaderElement); // Stop observing until content is loaded
}
});
},
{
root: null, // viewport
rootMargin: '0px',
threshold: 0.1 // When 10% of the loader is visible
}
);
observer.observe(loaderElement);
});
</script>
<div bind:this={loaderElement}>
<slot />
</div>
src/lib/components/layout/Sidebar.svelte
View file @
c869652e
...
@@ -11,7 +11,9 @@
...
@@ -11,7 +11,9 @@
showSidebar,
showSidebar,
mobile,
mobile,
showArchivedChats,
showArchivedChats,
pinnedChats
pinnedChats,
scrollPaginationEnabled,
currentChatPage
} from '$lib/stores';
} from '$lib/stores';
import { onMount, getContext, tick } from 'svelte';
import { onMount, getContext, tick } from 'svelte';
...
@@ -34,6 +36,8 @@
...
@@ -34,6 +36,8 @@
import UserMenu from './Sidebar/UserMenu.svelte';
import UserMenu from './Sidebar/UserMenu.svelte';
import ChatItem from './Sidebar/ChatItem.svelte';
import ChatItem from './Sidebar/ChatItem.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Spinner from '../common/Spinner.svelte';
import Loader from '../common/Loader.svelte';
const BREAKPOINT = 768;
const BREAKPOINT = 768;
...
@@ -50,6 +54,10 @@
...
@@ -50,6 +54,10 @@
let filteredChatList = [];
let filteredChatList = [];
// Pagination variables
let chatListLoading = false;
let allChatsLoaded = false;
$: filteredChatList = $chats.filter((chat) => {
$: filteredChatList = $chats.filter((chat) => {
if (search === '') {
if (search === '') {
return true;
return true;
...
@@ -70,6 +78,29 @@
...
@@ -70,6 +78,29 @@
}
}
});
});
const enablePagination = async () => {
// Reset pagination variables
currentChatPage.set(1);
allChatsLoaded = false;
await chats.set(await getChatList(localStorage.token, $currentChatPage));
// Enable pagination
scrollPaginationEnabled.set(true);
};
const loadMoreChats = async () => {
chatListLoading = true;
currentChatPage.set($currentChatPage + 1);
const newChatList = await getChatList(localStorage.token, $currentChatPage);
// once the bottom of the list has been reached (no results) there is no need to continue querying
allChatsLoaded = newChatList.length === 0;
await chats.set([...$chats, ...newChatList]);
chatListLoading = false;
};
onMount(async () => {
onMount(async () => {
mobile.subscribe((e) => {
mobile.subscribe((e) => {
if ($showSidebar && e) {
if ($showSidebar && e) {
...
@@ -82,9 +113,8 @@
...
@@ -82,9 +113,8 @@
});
});
showSidebar.set(window.innerWidth > BREAKPOINT);
showSidebar.set(window.innerWidth > BREAKPOINT);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await
chats.set(await getChatList(localStorage.token)
);
await
enablePagination(
);
let touchstart;
let touchstart;
let touchend;
let touchend;
...
@@ -185,7 +215,11 @@
...
@@ -185,7 +215,11 @@
await tick();
await tick();
goto('/');
goto('/');
}
}
await chats.set(await getChatList(localStorage.token));
allChatsLoaded = false;
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
}
};
};
...
@@ -410,7 +444,10 @@
...
@@ -410,7 +444,10 @@
class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm bg-transparent dark:text-gray-300 outline-none"
class="w-full rounded-r-xl py-1.5 pl-2.5 pr-4 text-sm bg-transparent dark:text-gray-300 outline-none"
placeholder={$i18n.t('Search')}
placeholder={$i18n.t('Search')}
bind:value={search}
bind:value={search}
on:focus={() => {
on:focus={async () => {
// TODO: migrate backend for more scalable search mechanism
scrollPaginationEnabled.set(false);
await chats.set(await getChatList(localStorage.token)); // when searching, load all chats
enrichChatsWithContent($chats);
enrichChatsWithContent($chats);
}}
}}
/>
/>
...
@@ -422,7 +459,7 @@
...
@@ -422,7 +459,7 @@
<button
<button
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
on:click={async () => {
on:click={async () => {
await
chats.set(await getChatList(localStorage.token)
);
await
enablePagination(
);
}}
}}
>
>
{$i18n.t('all')}
{$i18n.t('all')}
...
@@ -431,12 +468,17 @@
...
@@ -431,12 +468,17 @@
<button
<button
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
class="px-2.5 text-xs font-medium bg-gray-50 dark:bg-gray-900 dark:hover:bg-gray-800 transition rounded-full"
on:click={async () => {
on:click={async () => {
scrollPaginationEnabled.set(false);
let chatIds = await getChatListByTagName(localStorage.token, tag.name);
let chatIds = await getChatListByTagName(localStorage.token, tag.name);
if (chatIds.length === 0) {
if (chatIds.length === 0) {
await tags.set(await getAllChatTags(localStorage.token));
await tags.set(await getAllChatTags(localStorage.token));
chatIds = await getChatList(localStorage.token);
// if the tag we deleted is no longer a valid tag, return to main chat list view
await enablePagination();
}
}
await chats.set(chatIds);
await chats.set(chatIds);
chatListLoading = false;
}}
}}
>
>
{tag.name}
{tag.name}
...
@@ -527,6 +569,21 @@
...
@@ -527,6 +569,21 @@
}}
}}
/>
/>
{/each}
{/each}
{#if $scrollPaginationEnabled && !allChatsLoaded}
<Loader
on:visible={(e) => {
if (!chatListLoading) {
loadMoreChats();
}
}}
>
<div class="w-full flex justify-center py-1 text-xs animate-pulse items-center gap-2">
<Spinner className=" size-4" />
<div class=" ">Loading...</div>
</div>
</Loader>
{/if}
</div>
</div>
</div>
</div>
...
...
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment