= getContext('i18n');
export let chatIdProp = '';
let loaded = false;
-
const eventTarget = new EventTarget();
+ let showControls = false;
let stopResponseFlag = false;
let autoScroll = true;
let processing = '';
let messagesContainerElement: HTMLDivElement;
+ let showEventConfirmation = false;
+ let eventConfirmationTitle = '';
+ let eventConfirmationMessage = '';
+ let eventCallback = null;
+
let showModelSelector = true;
let selectedModels = [''];
@@ -96,6 +103,8 @@
currentId: null
};
+ let params = {};
+
$: if (history.currentId !== null) {
let _messages = [];
@@ -126,21 +135,35 @@
})();
}
- const chatEventHandler = async (data) => {
- if (data.chat_id === $chatId) {
+ const chatEventHandler = async (event, cb) => {
+ if (event.chat_id === $chatId) {
await tick();
- console.log(data);
- let message = history.messages[data.message_id];
+ console.log(event);
+ let message = history.messages[event.message_id];
- const status = {
- done: data?.data?.done ?? null,
- description: data?.data?.status ?? null
- };
+ const type = event?.data?.type ?? null;
+ const data = event?.data?.data ?? null;
- if (message.statusHistory) {
- message.statusHistory.push(status);
+ if (type === 'status') {
+ if (message?.statusHistory) {
+ message.statusHistory.push(data);
+ } else {
+ message.statusHistory = [data];
+ }
+ } else if (type === 'citation') {
+ if (message?.citations) {
+ message.citations.push(data);
+ } else {
+ message.citations = [data];
+ }
+ } else if (type === 'confirmation') {
+ eventCallback = cb;
+ showEventConfirmation = true;
+
+ eventConfirmationTitle = data.title;
+ eventConfirmationMessage = data.message;
} else {
- message.statusHistory = [status];
+ console.log('Unknown message type', data);
}
messages = messages;
@@ -221,6 +244,7 @@
messages: {},
currentId: null
};
+ params = {};
if ($page.url.searchParams.get('models')) {
selectedModels = $page.url.searchParams.get('models')?.split(',');
@@ -290,11 +314,7 @@
await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}'));
}
- await settings.set({
- ...$settings,
- system: chatContent.system ?? $settings.system,
- params: chatContent.options ?? $settings.params
- });
+ params = chatContent?.params ?? {};
autoScroll = true;
await tick();
@@ -507,9 +527,7 @@
title: $i18n.t('New Chat'),
models: selectedModels,
system: $settings.system ?? undefined,
- options: {
- ...($settings.params ?? {})
- },
+ params: params,
messages: messages,
history: history,
tags: [],
@@ -607,11 +625,11 @@
scrollToBottom();
const messagesBody = [
- $settings.system || (responseMessage?.userContext ?? null)
+ params?.system || $settings.system || (responseMessage?.userContext ?? null)
? {
role: 'system',
content: `${promptTemplate(
- $settings?.system ?? '',
+ params?.system ?? $settings?.system ?? '',
$user.name,
$settings?.userLocation
? await getAndUpdateUserLocation(localStorage.token)
@@ -696,15 +714,16 @@
model: model.id,
messages: messagesBody,
options: {
- ...($settings.params ?? {}),
+ ...(params ?? $settings.params ?? {}),
stop:
- $settings?.params?.stop ?? undefined
- ? $settings.params.stop.map((str) =>
+ params?.stop ?? $settings?.params?.stop ?? undefined
+ ? (params?.stop ?? $settings.params.stop).map((str) =>
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
)
: undefined,
- num_predict: $settings?.params?.max_tokens ?? undefined,
- repeat_penalty: $settings?.params?.frequency_penalty ?? undefined
+ num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
+ repeat_penalty:
+ params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined
},
format: $settings.requestFormat ?? undefined,
keep_alive: $settings.keepAlive ?? undefined,
@@ -840,7 +859,8 @@
chat = await updateChatById(localStorage.token, _chatId, {
messages: messages,
history: history,
- models: selectedModels
+ models: selectedModels,
+ params: params
});
await chats.set(await getChatList(localStorage.token));
}
@@ -950,11 +970,11 @@
}
: undefined,
messages: [
- $settings.system || (responseMessage?.userContext ?? null)
+ params?.system || $settings.system || (responseMessage?.userContext ?? null)
? {
role: 'system',
content: `${promptTemplate(
- $settings?.system ?? '',
+ params?.system ?? $settings?.system ?? '',
$user.name,
$settings?.userLocation
? await getAndUpdateUserLocation(localStorage.token)
@@ -999,17 +1019,18 @@
: message?.raContent ?? message.content
})
})),
- seed: $settings?.params?.seed ?? undefined,
+ seed: params?.seed ?? $settings?.params?.seed ?? undefined,
stop:
- $settings?.params?.stop ?? undefined
- ? $settings.params.stop.map((str) =>
+ params?.stop ?? $settings?.params?.stop ?? undefined
+ ? (params?.stop ?? $settings.params.stop).map((str) =>
decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
)
: undefined,
- temperature: $settings?.params?.temperature ?? undefined,
- top_p: $settings?.params?.top_p ?? undefined,
- frequency_penalty: $settings?.params?.frequency_penalty ?? undefined,
- max_tokens: $settings?.params?.max_tokens ?? undefined,
+ temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined,
+ top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined,
+ frequency_penalty:
+ params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined,
+ max_tokens: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
files: files.length > 0 ? files : undefined,
session_id: $socket?.id,
@@ -1115,7 +1136,8 @@
chat = await updateChatById(localStorage.token, _chatId, {
models: selectedModels,
messages: messages,
- history: history
+ history: history,
+ params: params
});
await chats.set(await getChatList(localStorage.token));
}
@@ -1382,6 +1404,18 @@
+
{
+ eventCallback(true);
+ }}
+ on:cancel={() => {
+ eventCallback(false);
+ }}
+/>
+
{#if $showCallOverlay}
0}
{chat}
{initNewChat}
@@ -1425,7 +1460,7 @@
{/if}
diff --git a/src/lib/components/chat/ChatControls.svelte b/src/lib/components/chat/ChatControls.svelte
new file mode 100644
index 000000000..612af3378
--- /dev/null
+++ b/src/lib/components/chat/ChatControls.svelte
@@ -0,0 +1,63 @@
+
+
+{#if largeScreen}
+ {#if show}
+
+
+
+ {
+ show = false;
+ }}
+ bind:params
+ />
+
+
+
+ {/if}
+{:else}
+
+
+ {
+ show = false;
+ }}
+ bind:params
+ />
+
+
+{/if}
diff --git a/src/lib/components/chat/Controls/Controls.svelte b/src/lib/components/chat/Controls/Controls.svelte
new file mode 100644
index 000000000..2cb3bceeb
--- /dev/null
+++ b/src/lib/components/chat/Controls/Controls.svelte
@@ -0,0 +1,49 @@
+
+
+
+
+
{$i18n.t('Chat Controls')}
+
+
+
+
+
+
System Prompt
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte
index 2bad24dde..c64e7c318 100644
--- a/src/lib/components/chat/MessageInput.svelte
+++ b/src/lib/components/chat/MessageInput.svelte
@@ -316,7 +316,7 @@