Simplify profile change
This commit is contained in:
parent
8ce869c717
commit
6ce0355eec
|
@ -122,7 +122,7 @@
|
||||||
}
|
}
|
||||||
if (!chat.settings.profile) {
|
if (!chat.settings.profile) {
|
||||||
const profile = getProfile('') // get default profile
|
const profile = getProfile('') // get default profile
|
||||||
applyProfile(chatId, profile.profile as any, true)
|
applyProfile(chatId, profile.profile as any)
|
||||||
if (getChatSettingValueByKey(chatId, 'startSession')) {
|
if (getChatSettingValueByKey(chatId, 'startSession')) {
|
||||||
setChatSettingValueByKey(chatId, 'startSession', false)
|
setChatSettingValueByKey(chatId, 'startSession', false)
|
||||||
setTimeout(() => { submitForm(false, true) }, 0)
|
setTimeout(() => { submitForm(false, true) }, 0)
|
||||||
|
@ -536,21 +536,23 @@
|
||||||
default:
|
default:
|
||||||
setChatSettingValue(chatId, setting, el.value)
|
setChatSettingValue(chatId, setting, el.value)
|
||||||
}
|
}
|
||||||
(typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting) && showSettingsModal++
|
(typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting)
|
||||||
|
&& showSettingsModal && showSettingsModal++
|
||||||
}
|
}
|
||||||
if (setting.key === 'profile' && checkSessionActivity(chatId)) {
|
if (setting.key === 'profile' && checkSessionActivity(chatId)
|
||||||
if (window.confirm('Switching profiles will clear your current chat session. Are you sure you want to continue?')) {
|
&& (getProfile(el.value).characterName !== getChatSettingValueByKey(chatId,'characterName'))) {
|
||||||
// Switch profiles
|
const val = getChatSettingValue(chatId, setting)
|
||||||
() => { doSet() }
|
if (window.confirm('Personality change will not correctly apply to existing chat session.\n Continue?')) {
|
||||||
|
doSet()
|
||||||
} else {
|
} else {
|
||||||
// Roll-back
|
// roll-back
|
||||||
() => { el.value = getChatSettingValue(chatId, setting) }
|
setChatSettingValue(chatId, setting, val)
|
||||||
|
// refresh setting modal, if open
|
||||||
|
showSettingsModal && showSettingsModal++
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
debounce[setting.key] = setTimeout(doSet, 250)
|
|
||||||
}
|
}
|
||||||
|
debounce[setting.key] = setTimeout(doSet, 250)
|
||||||
}
|
}
|
||||||
|
|
||||||
const autoGrowInputOnEvent = (event: Event) => {
|
const autoGrowInputOnEvent = (event: Event) => {
|
||||||
// Resize the textarea to fit the content - auto is important to reset the height after deleting content
|
// Resize the textarea to fit the content - auto is important to reset the height after deleting content
|
||||||
if (event.target === null) return
|
if (event.target === null) return
|
||||||
|
@ -567,7 +569,7 @@
|
||||||
try {
|
try {
|
||||||
saveCustomProfile(chat.settings)
|
saveCustomProfile(chat.settings)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Error saving profile: ' + e.message)
|
alert('Error saving profile: \n' + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +599,7 @@
|
||||||
updateProfileSelectOptions()
|
updateProfileSelectOptions()
|
||||||
showSettingsModal && showSettingsModal++
|
showSettingsModal && showSettingsModal++
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Error cloning profile: ' + e.message)
|
alert('Error cloning profile: \n' + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,11 +610,11 @@
|
||||||
chat.settings.profile = globalStore.defaultProfile
|
chat.settings.profile = globalStore.defaultProfile
|
||||||
saveChatStore()
|
saveChatStore()
|
||||||
setGlobalSettingValueByKey('lastProfile', chat.settings.profile)
|
setGlobalSettingValueByKey('lastProfile', chat.settings.profile)
|
||||||
applyProfile(chatId, chat.settings.profile as any, true)
|
applyProfile(chatId, chat.settings.profile as any)
|
||||||
updateProfileSelectOptions()
|
updateProfileSelectOptions()
|
||||||
showSettings()
|
showSettings()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Error deleting profile: ' + e.message)
|
alert('Error deleting profile: \n' + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,7 +637,7 @@
|
||||||
updateProfileSelectOptions()
|
updateProfileSelectOptions()
|
||||||
showSettingsModal && showSettingsModal++
|
showSettingsModal && showSettingsModal++
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Unable to import profile: ' + e.message)
|
alert('Unable to import profile: \n' + e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,6 +658,9 @@
|
||||||
|
|
||||||
<div class="level-right">
|
<div class="level-right">
|
||||||
<p class="level-item">
|
<p class="level-item">
|
||||||
|
{#if chat.settings.autoStartSession && chat.settings.systemPrompt && chat.settings.useSystemPrompt}
|
||||||
|
|
||||||
|
{/if}
|
||||||
<button class="button is-warning" on:click={() => { clearMessages(chatId); window.location.reload() }}><span class="greyscale mr-2"><Fa icon={faTrash} /></span> Clear messages</button>
|
<button class="button is-warning" on:click={() => { clearMessages(chatId); window.location.reload() }}><span class="greyscale mr-2"><Fa icon={faTrash} /></span> Clear messages</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -80,20 +80,20 @@ export const checkSessionActivity = (chatId:number):boolean => {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applyProfile = (chatId:number, key:string, keepMessages?:boolean) => {
|
export const applyProfile = (chatId:number, key:string, resetChat:boolean = false) => {
|
||||||
const profile = getProfile(key)
|
const profile = getProfile(key)
|
||||||
Object.entries(profile).forEach(([k, v]) => {
|
Object.entries(profile).forEach(([k, v]) => {
|
||||||
const setting = getChatSettingByKey(k as any)
|
const setting = getChatSettingByKey(k as any)
|
||||||
if (setting) setChatSettingValue(chatId, setting as any, v)
|
if (setting) setChatSettingValue(chatId, setting as any, v)
|
||||||
})
|
})
|
||||||
const messages = getMessages(chatId)
|
if (!resetChat && getMessages(chatId).length) {
|
||||||
if (keepMessages && messages.length) {
|
// If there are any messages, just apply settings, don't apply chat messages
|
||||||
setChatSettingValueByKey(chatId, 'startSession', false)
|
setChatSettingValueByKey(chatId, 'startSession', false)
|
||||||
setGlobalSettingValueByKey('lastProfile', key)
|
setGlobalSettingValueByKey('lastProfile', key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Clear current messages
|
||||||
clearMessages(chatId)
|
clearMessages(chatId)
|
||||||
|
|
||||||
// Add the system prompt
|
// Add the system prompt
|
||||||
const systemPromptMessage:Message = {
|
const systemPromptMessage:Message = {
|
||||||
role: 'system',
|
role: 'system',
|
||||||
|
|
Loading…
Reference in New Issue