Fix improper resetting of setting values

This commit is contained in:
Webifi 2023-06-01 22:53:48 -05:00
parent 3dc30ad186
commit 9e2b354b0a
4 changed files with 22 additions and 17 deletions

View File

@ -22,7 +22,7 @@
} from './Types.svelte'
import Prompts from './Prompts.svelte'
import Messages from './Messages.svelte'
import { applyProfile, getProfile, prepareSummaryPrompt } from './Profiles.svelte'
import { prepareSummaryPrompt, restartProfile } from './Profiles.svelte'
import { afterUpdate, onMount } from 'svelte'
import Fa from 'svelte-fa/src/fa.svelte'
@ -64,8 +64,7 @@
clearTimeout(scDelay)
setTimeout(() => {
if (chat.startSession) {
const profile = getProfile('') // get default profile
applyProfile(chatId, profile.profile as any)
restartProfile(chatId)
if (chat.startSession) {
chat.startSession = false
saveChatStore()
@ -120,8 +119,7 @@
console.log('Speech recognition not supported')
}
if (chat.startSession) {
const profile = getProfile('') // get default profile
applyProfile(chatId, profile.profile as any)
restartProfile(chatId)
if (chat.startSession) {
chat.startSession = false
saveChatStore()

View File

@ -19,7 +19,7 @@
} from '@fortawesome/free-solid-svg-icons/index'
import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu } from './Storage.svelte'
import { exportAsMarkdown, exportChatAsJSON } from './Export.svelte'
import { applyProfile } from './Profiles.svelte'
import { restartProfile } from './Profiles.svelte'
import { replace } from 'svelte-spa-router'
import { clickOutside } from 'svelte-use-click-outside'
@ -66,7 +66,7 @@
const restartChatSession = () => {
close()
applyProfile(chatId, '', true)
restartProfile(chatId)
$checkStateChange++ // signal chat page to start profile
}

View File

@ -71,12 +71,10 @@ export const prepareSummaryPrompt = (chatId:number, promptsSize:number, maxToken
.replaceAll('[[MAX_WORDS]]', Math.floor(maxTokens * 0.75).toString()) // ~.75 words per token. May need to reduce
}
// Apply currently selected profile
export const applyProfile = (chatId:number, key:string = '', resetChat:boolean = false) => {
// Restart currently loaded profile
export const restartProfile = (chatId:number, noApply:boolean=false) => {
const settings = getChatSettings(chatId)
const profile = getProfile(key || settings.profile)
resetChatSettings(chatId, resetChat) // Fully reset
if (!resetChat) return
if (!settings.profile && !noApply) return applyProfile(chatId, '', true)
// Clear current messages
clearMessages(chatId)
// Add the system prompt
@ -88,8 +86,8 @@ export const applyProfile = (chatId:number, key:string = '', resetChat:boolean =
addMessage(chatId, systemPromptMessage)
// Add trainingPrompts, if any
if (profile.trainingPrompts) {
profile.trainingPrompts.forEach(tp => {
if (settings.trainingPrompts) {
settings.trainingPrompts.forEach(tp => {
addMessage(chatId, tp)
})
}
@ -97,7 +95,16 @@ export const applyProfile = (chatId:number, key:string = '', resetChat:boolean =
getChat(chatId).startSession = settings.autoStartSession
saveChatStore()
// Mark mark this as last used
setGlobalSettingValueByKey('lastProfile', key)
setGlobalSettingValueByKey('lastProfile', settings.profile)
}
// Apply currently selected profile
export const applyProfile = (chatId:number, key:string = '', resetChat:boolean = false) => {
const settings = getChatSettings(chatId)
const profile = getProfile(key || settings.profile)
resetChatSettings(chatId, resetChat) // Fully reset
if (!resetChat) return
return restartProfile(chatId, true)
}
const summaryPrompts = {

View File

@ -4,7 +4,7 @@
import type { Chat, ChatSettings, GlobalSettings, Message, ChatSetting, GlobalSetting, Usage, Model } from './Types.svelte'
import { getChatSettingObjectByKey, getGlobalSettingObjectByKey, getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
import { v4 as uuidv4 } from 'uuid'
import { applyProfile, getProfile, isStaticProfile } from './Profiles.svelte'
import { getProfile, isStaticProfile, restartProfile } from './Profiles.svelte'
export const chatsStorage = persisted('chats', [] as Chat[])
export const globalStorage = persisted('global', {} as GlobalSettings)
@ -40,7 +40,7 @@
})
chatsStorage.set(chats)
// Apply defaults and prepare it to start
applyProfile(chatId, '', true)
restartProfile(chatId)
return chatId
}