Move chat state values out of settings
This commit is contained in:
		
							parent
							
								
									bf00f23596
								
							
						
					
					
						commit
						c436fc6299
					
				|  | @ -124,12 +124,13 @@ | |||
|     } else { | ||||
|       console.log('Speech recognition not supported') | ||||
|     } | ||||
|     if (chatSettings.startSession) { | ||||
|     if (chat.startSession) { | ||||
|       const profile = getProfile('') // get default profile | ||||
|       applyProfile(chatId, profile.profile as any) | ||||
|       if (chatSettings.startSession) { | ||||
|         setChatSettingValueByKey(chatId, 'startSession', false) | ||||
|         // Auto start the session out of band | ||||
|       if (chat.startSession) { | ||||
|         chat.startSession = false | ||||
|         saveChatStore() | ||||
|         // Auto start the session | ||||
|         setTimeout(() => { submitForm(false, true) }, 0) | ||||
|       } | ||||
|     } | ||||
|  | @ -349,7 +350,8 @@ | |||
|     if (updating) return | ||||
|    | ||||
|     if (!skipInput) { | ||||
|       setChatSettingValueByKey(chatId, 'sessionStarted', true) | ||||
|       chat.sessionStarted = true | ||||
|       saveChatStore() | ||||
|       if (input.value !== '') { | ||||
|         // Compose the input message | ||||
|         const inputMessage: Message = { role: 'user', content: input.value, uuid: uuidv4() } | ||||
|  | @ -505,8 +507,9 @@ | |||
|   const closeSettings = () => { | ||||
|     showSettingsModal = 0 | ||||
|     showProfileMenu = false | ||||
|     if (chat.settings.startSession) { | ||||
|       setChatSettingValueByKey(chatId, 'startSession', false) | ||||
|     if (chat.startSession) { | ||||
|         chat.startSession = false | ||||
|         saveChatStore() | ||||
|         submitForm(false, true) | ||||
|     } | ||||
|   } | ||||
|  | @ -556,7 +559,7 @@ | |||
|         window.alert('Unable to change:\n' + e.message) | ||||
|       } | ||||
|     } | ||||
|     if (setting.key === 'profile' && chatSettings.sessionStarted && | ||||
|     if (setting.key === 'profile' && chat.sessionStarted && | ||||
|       (getProfile(el.value).characterName !== chatSettings.characterName)) { | ||||
|       const val = chatSettings[setting.key] | ||||
|       if (window.confirm('Personality change will not correctly apply to existing chat session.\n Continue?')) { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| <script context="module" lang="ts"> | ||||
|     import { applyProfile } from './Profiles.svelte' | ||||
|     import { getChatSettings } from './Storage.svelte' | ||||
|     import { getChat, getChatSettings } from './Storage.svelte' | ||||
|     import { encode } from 'gpt-tokenizer' | ||||
| // Setting definitions | ||||
| 
 | ||||
|  | @ -79,10 +79,6 @@ const defaults:ChatSettings = { | |||
|   systemPrompt: '', | ||||
|   autoStartSession: false, | ||||
|   trainingPrompts: [], | ||||
|   // There are chat session state variables, and really don't belong here | ||||
|   // But it was easier to just put them here. | ||||
|   startSession: false, // Should the session start automatically | ||||
|   sessionStarted: false // Has the session started (user made a first request) | ||||
| } | ||||
| 
 | ||||
| const excludeFromProfile = { | ||||
|  | @ -101,7 +97,7 @@ const profileSetting: ChatSetting & SettingSelect = { | |||
|       options: [], // Set by Profiles | ||||
|       type: 'select', | ||||
|       afterChange: (chatId, setting) => { | ||||
|         applyProfile(chatId, '', !getChatSettings(chatId).sessionStarted) | ||||
|         applyProfile(chatId, '', !getChat(chatId).sessionStarted) | ||||
|         return true // Signal we should refresh the setting modal | ||||
|       } | ||||
| } | ||||
|  | @ -160,13 +156,6 @@ const nonRequestSettings: ChatSetting[] = [ | |||
|         type: 'boolean', | ||||
|         hide: (chatId) => !getChatSettings(chatId).useSystemPrompt | ||||
|       }, | ||||
|       { | ||||
|         key: 'startSession', | ||||
|         name: 'Auto-Start Trigger', | ||||
|         title: '', | ||||
|         type: 'boolean', | ||||
|         hide: (chatId) => true | ||||
|       }, | ||||
|       { | ||||
|         key: 'useSummarization', | ||||
|         name: 'Enable Auto Summarize', | ||||
|  |  | |||
|  | @ -30,7 +30,9 @@ | |||
|       name: `Chat ${chatId}`, | ||||
|       settings: {} as ChatSettings, | ||||
|       messages: [], | ||||
|       usage: {} as Record<Model, Usage> | ||||
|       usage: {} as Record<Model, Usage>, | ||||
|       startSession: false, | ||||
|       sessionStarted: false, | ||||
|     }) | ||||
|     chatsStorage.set(chats) | ||||
|     // Apply defaults and prepare it to start | ||||
|  | @ -90,6 +92,8 @@ | |||
|       const usageMap:Record<Model, Usage> = {} | ||||
|       chat.usage = usageMap | ||||
|     } | ||||
|     if (chat.startSession === undefined) chat.startSession = false | ||||
|     if (chat.sessionStarted === undefined) chat.sessionStarted = !!chat.messages.find(m => m.role === 'user') | ||||
|     chatsStorage.set(chats) | ||||
|   } | ||||
|    | ||||
|  |  | |||
|  | @ -58,8 +58,6 @@ | |||
|     useSystemPrompt: boolean; | ||||
|     systemPrompt: string; | ||||
|     autoStartSession: boolean; | ||||
|     startSession: false; | ||||
|     sessionStarted: false; | ||||
|     trainingPrompts?: Message[]; | ||||
|   } & Request; | ||||
| 
 | ||||
|  | @ -69,6 +67,8 @@ | |||
|     messages: Message[]; | ||||
|     usage: Record<Model, Usage>; | ||||
|     settings: ChatSettings; | ||||
|     startSession: boolean; | ||||
|     sessionStarted: boolean; | ||||
|   }; | ||||
| 
 | ||||
|   type ResponseOK = { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Webifi
						Webifi