Allow apply system prompt changes to current chat.
This commit is contained in:
		
							parent
							
								
									189d35a5d0
								
							
						
					
					
						commit
						426adbbca5
					
				| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
  import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect } from './Profiles.svelte'
 | 
					  import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect, setSystemPrompt } from './Profiles.svelte'
 | 
				
			||||||
  import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile } from './Settings.svelte'
 | 
					  import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile } from './Settings.svelte'
 | 
				
			||||||
  import {
 | 
					  import {
 | 
				
			||||||
    saveChatStore,
 | 
					    saveChatStore,
 | 
				
			||||||
| 
						 | 
					@ -25,9 +25,8 @@
 | 
				
			||||||
    faDownload,
 | 
					    faDownload,
 | 
				
			||||||
    faUpload,
 | 
					    faUpload,
 | 
				
			||||||
    faSquarePlus,
 | 
					    faSquarePlus,
 | 
				
			||||||
 | 
					    faRotateLeft,
 | 
				
			||||||
    faRotateLeft
 | 
					    faCheckCircle
 | 
				
			||||||
 | 
					 | 
				
			||||||
  } from '@fortawesome/free-solid-svg-icons/index'
 | 
					  } from '@fortawesome/free-solid-svg-icons/index'
 | 
				
			||||||
  import { exportProfileAsJSON } from './Export.svelte'
 | 
					  import { exportProfileAsJSON } from './Export.svelte'
 | 
				
			||||||
  import { onMount, afterUpdate } from 'svelte'
 | 
					  import { onMount, afterUpdate } from 'svelte'
 | 
				
			||||||
| 
						 | 
					@ -271,6 +270,12 @@
 | 
				
			||||||
    chatSettings.isDirty = !deepEqual(profile, chatSettings)
 | 
					    chatSettings.isDirty = !deepEqual(profile, chatSettings)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const applyToChat = () => {
 | 
				
			||||||
 | 
					    if (chatSettings.useSystemPrompt) {
 | 
				
			||||||
 | 
					      setSystemPrompt(chatId)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
 | 
					<!-- svelte-ignore a11y-click-events-have-key-events -->
 | 
				
			||||||
| 
						 | 
					@ -322,6 +327,9 @@
 | 
				
			||||||
                <a href={'#'} class="dropdown-item" on:click|preventDefault={startNewChat}>
 | 
					                <a href={'#'} class="dropdown-item" on:click|preventDefault={startNewChat}>
 | 
				
			||||||
                  <span class="menu-icon"><Fa icon={faSquarePlus}/></span> Start New Chat Using Profile
 | 
					                  <span class="menu-icon"><Fa icon={faSquarePlus}/></span> Start New Chat Using Profile
 | 
				
			||||||
                </a>
 | 
					                </a>
 | 
				
			||||||
 | 
					                <a href={'#'} class="dropdown-item" on:click|preventDefault={applyToChat}>
 | 
				
			||||||
 | 
					                  <span class="menu-icon"><Fa icon={faCheckCircle}/></span> Apply Prompts to Current Chat
 | 
				
			||||||
 | 
					                </a>
 | 
				
			||||||
                <hr class="dropdown-divider">
 | 
					                <hr class="dropdown-divider">
 | 
				
			||||||
                <a href={'#'} 
 | 
					                <a href={'#'} 
 | 
				
			||||||
                  class="dropdown-item"
 | 
					                  class="dropdown-item"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
  import { getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
 | 
					  import { getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
 | 
				
			||||||
  import { get, writable } from 'svelte/store'
 | 
					  import { get, writable } from 'svelte/store'
 | 
				
			||||||
  // Profile definitions
 | 
					  // Profile definitions
 | 
				
			||||||
  import { addMessage, clearMessages, getChat, getChatSettings, getCustomProfiles, getGlobalSettings, newName, resetChatSettings, saveChatStore, setGlobalSettingValueByKey, updateProfile } from './Storage.svelte'
 | 
					  import { addMessage, clearMessages, deleteMessage, getChat, getChatSettings, getCustomProfiles, getGlobalSettings, newName, resetChatSettings, saveChatStore, setGlobalSettingValueByKey, updateProfile } from './Storage.svelte'
 | 
				
			||||||
  import type { Message, SelectOption, ChatSettings } from './Types.svelte'
 | 
					  import type { Message, SelectOption, ChatSettings } from './Types.svelte'
 | 
				
			||||||
  import { v4 as uuidv4 } from 'uuid'
 | 
					  import { v4 as uuidv4 } from 'uuid'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,6 +89,18 @@ export const prepareSummaryPrompt = (chatId:number, maxTokens:number) => {
 | 
				
			||||||
    return mergeProfileFields(settings, currentSummaryPrompt, Math.floor(maxTokens * 0.75)).trim()
 | 
					    return mergeProfileFields(settings, currentSummaryPrompt, Math.floor(maxTokens * 0.75)).trim()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setSystemPrompt = (chatId: number) => {
 | 
				
			||||||
 | 
					    const chat = getChat(chatId)
 | 
				
			||||||
 | 
					    const systemPromptMessage:Message = {
 | 
				
			||||||
 | 
					      role: 'system',
 | 
				
			||||||
 | 
					      content: prepareProfilePrompt(chatId),
 | 
				
			||||||
 | 
					      uuid: uuidv4()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (chat.messages[0]?.role === 'system') deleteMessage(chatId, chat.messages[0].uuid)
 | 
				
			||||||
 | 
					    chat.messages.unshift(systemPromptMessage)
 | 
				
			||||||
 | 
					    saveChatStore()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Restart currently loaded profile
 | 
					// Restart currently loaded profile
 | 
				
			||||||
export const restartProfile = (chatId:number, noApply:boolean = false) => {
 | 
					export const restartProfile = (chatId:number, noApply:boolean = false) => {
 | 
				
			||||||
    const settings = getChatSettings(chatId)
 | 
					    const settings = getChatSettings(chatId)
 | 
				
			||||||
| 
						 | 
					@ -96,12 +108,7 @@ export const restartProfile = (chatId:number, noApply:boolean = false) => {
 | 
				
			||||||
    // Clear current messages
 | 
					    // Clear current messages
 | 
				
			||||||
    clearMessages(chatId)
 | 
					    clearMessages(chatId)
 | 
				
			||||||
    // Add the system prompt
 | 
					    // Add the system prompt
 | 
				
			||||||
    const systemPromptMessage:Message = {
 | 
					    setSystemPrompt(chatId)
 | 
				
			||||||
      role: 'system',
 | 
					 | 
				
			||||||
      content: prepareProfilePrompt(chatId),
 | 
					 | 
				
			||||||
      uuid: uuidv4()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    addMessage(chatId, systemPromptMessage)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add trainingPrompts, if any
 | 
					    // Add trainingPrompts, if any
 | 
				
			||||||
    if (settings.trainingPrompts) {
 | 
					    if (settings.trainingPrompts) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue