refac
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
blobToFile,
|
||||
compressImage,
|
||||
extractInputVariables,
|
||||
getAge,
|
||||
getCurrentDateTime,
|
||||
getFormattedDate,
|
||||
getFormattedTime,
|
||||
@@ -31,6 +32,7 @@
|
||||
import FilesOverlay from '../chat/MessageInput/FilesOverlay.svelte';
|
||||
import Commands from '../chat/MessageInput/Commands.svelte';
|
||||
import InputVariablesModal from '../chat/MessageInput/InputVariablesModal.svelte';
|
||||
import { getSessionUser } from '$lib/apis/auths';
|
||||
|
||||
export let placeholder = $i18n.t('Send a Message');
|
||||
|
||||
@@ -116,11 +118,47 @@
|
||||
text = text.replaceAll('{{USER_LOCATION}}', String(location));
|
||||
}
|
||||
|
||||
const sessionUser = getSessionUser(localStorage.token);
|
||||
|
||||
if (text.includes('{{USER_NAME}}')) {
|
||||
const name = $user?.name || 'User';
|
||||
const name = sessionUser?.name || 'User';
|
||||
text = text.replaceAll('{{USER_NAME}}', name);
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIO}}')) {
|
||||
const bio = sessionUser?.bio || '';
|
||||
|
||||
if (bio) {
|
||||
text = text.replaceAll('{{USER_BIO}}', bio);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_GENDER}}')) {
|
||||
const gender = sessionUser?.gender || '';
|
||||
|
||||
if (gender) {
|
||||
text = text.replaceAll('{{USER_GENDER}}', gender);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIRTH_DATE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
text = text.replaceAll('{{USER_BIRTH_DATE}}', birthDate);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_AGE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
// calculate age using date
|
||||
const age = getAge(birthDate);
|
||||
text = text.replaceAll('{{USER_AGE}}', age);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_LANGUAGE}}')) {
|
||||
const language = localStorage.getItem('locale') || 'en-US';
|
||||
text = text.replaceAll('{{USER_LANGUAGE}}', language);
|
||||
|
||||
@@ -44,11 +44,6 @@
|
||||
copyToClipboard,
|
||||
getMessageContentParts,
|
||||
createMessagesList,
|
||||
extractSentencesForAudio,
|
||||
promptTemplate,
|
||||
splitStream,
|
||||
sleep,
|
||||
removeDetails,
|
||||
getPromptVariables,
|
||||
processDetails,
|
||||
removeAllDetails
|
||||
@@ -1655,6 +1650,14 @@
|
||||
);
|
||||
await tick();
|
||||
|
||||
let userLocation;
|
||||
if ($settings?.userLocation) {
|
||||
userLocation = await getAndUpdateUserLocation(localStorage.token).catch((err) => {
|
||||
console.error(err);
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
const stream =
|
||||
model?.info?.params?.stream_response ??
|
||||
$settings?.params?.stream_response ??
|
||||
@@ -1665,16 +1668,7 @@
|
||||
params?.system || $settings.system
|
||||
? {
|
||||
role: 'system',
|
||||
content: `${promptTemplate(
|
||||
params?.system ?? $settings?.system ?? '',
|
||||
$user?.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
|
||||
console.error(err);
|
||||
return undefined;
|
||||
})
|
||||
: undefined
|
||||
)}`
|
||||
content: `${params?.system ?? $settings?.system ?? ''}`
|
||||
}
|
||||
: undefined,
|
||||
..._messages.map((message) => ({
|
||||
@@ -1752,15 +1746,7 @@
|
||||
memory: $settings?.memory ?? false
|
||||
},
|
||||
variables: {
|
||||
...getPromptVariables(
|
||||
$user?.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
|
||||
console.error(err);
|
||||
return undefined;
|
||||
})
|
||||
: undefined
|
||||
)
|
||||
...getPromptVariables($user?.name, $settings?.userLocation ? userLocation : undefined)
|
||||
},
|
||||
model_item: $models.find((m) => m.id === model.id),
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
extractContentFromFile,
|
||||
extractCurlyBraceWords,
|
||||
extractInputVariables,
|
||||
getAge,
|
||||
getCurrentDateTime,
|
||||
getFormattedDate,
|
||||
getFormattedTime,
|
||||
@@ -73,6 +74,7 @@
|
||||
import { KokoroWorker } from '$lib/workers/KokoroWorker';
|
||||
import InputVariablesModal from './MessageInput/InputVariablesModal.svelte';
|
||||
import Voice from '../icons/Voice.svelte';
|
||||
import { getSessionUser } from '$lib/apis/auths';
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
export let onChange: Function = () => {};
|
||||
@@ -176,11 +178,47 @@
|
||||
text = text.replaceAll('{{USER_LOCATION}}', String(location));
|
||||
}
|
||||
|
||||
const sessionUser = getSessionUser(localStorage.token);
|
||||
|
||||
if (text.includes('{{USER_NAME}}')) {
|
||||
const name = $_user?.name || 'User';
|
||||
const name = sessionUser?.name || 'User';
|
||||
text = text.replaceAll('{{USER_NAME}}', name);
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIO}}')) {
|
||||
const bio = sessionUser?.bio || '';
|
||||
|
||||
if (bio) {
|
||||
text = text.replaceAll('{{USER_BIO}}', bio);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_GENDER}}')) {
|
||||
const gender = sessionUser?.gender || '';
|
||||
|
||||
if (gender) {
|
||||
text = text.replaceAll('{{USER_GENDER}}', gender);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_BIRTH_DATE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
text = text.replaceAll('{{USER_BIRTH_DATE}}', birthDate);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_AGE}}')) {
|
||||
const birthDate = sessionUser?.date_of_birth || '';
|
||||
|
||||
if (birthDate) {
|
||||
// calculate age using date
|
||||
const age = getAge(birthDate);
|
||||
text = text.replaceAll('{{USER_AGE}}', age);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.includes('{{USER_LANGUAGE}}')) {
|
||||
const language = localStorage.getItem('locale') || 'en-US';
|
||||
text = text.replaceAll('{{USER_LANGUAGE}}', language);
|
||||
@@ -872,7 +910,8 @@
|
||||
: `${WEBUI_BASE_URL}/static/favicon.png`)}
|
||||
/>
|
||||
<div class="translate-y-[0.5px]">
|
||||
{$i18n.t('Talk to model')}: <span class=" font-medium">{atSelectedModel.name}</span>
|
||||
{$i18n.t('Talk to model')}:
|
||||
<span class=" font-medium">{atSelectedModel.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user