Allow apply system prompt changes to current chat.
This commit is contained in:
parent
189d35a5d0
commit
426adbbca5
|
@ -1,5 +1,5 @@
|
|||
<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 {
|
||||
saveChatStore,
|
||||
|
@ -25,9 +25,8 @@
|
|||
faDownload,
|
||||
faUpload,
|
||||
faSquarePlus,
|
||||
|
||||
faRotateLeft
|
||||
|
||||
faRotateLeft,
|
||||
faCheckCircle
|
||||
} from '@fortawesome/free-solid-svg-icons/index'
|
||||
import { exportProfileAsJSON } from './Export.svelte'
|
||||
import { onMount, afterUpdate } from 'svelte'
|
||||
|
@ -271,6 +270,12 @@
|
|||
chatSettings.isDirty = !deepEqual(profile, chatSettings)
|
||||
}
|
||||
|
||||
const applyToChat = () => {
|
||||
if (chatSettings.useSystemPrompt) {
|
||||
setSystemPrompt(chatId)
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
|
@ -322,6 +327,9 @@
|
|||
<a href={'#'} class="dropdown-item" on:click|preventDefault={startNewChat}>
|
||||
<span class="menu-icon"><Fa icon={faSquarePlus}/></span> Start New Chat Using Profile
|
||||
</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">
|
||||
<a href={'#'}
|
||||
class="dropdown-item"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
|
||||
import { get, writable } from 'svelte/store'
|
||||
// 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 { 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()
|
||||
}
|
||||
|
||||
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
|
||||
export const restartProfile = (chatId:number, noApply:boolean = false) => {
|
||||
const settings = getChatSettings(chatId)
|
||||
|
@ -96,12 +108,7 @@ export const restartProfile = (chatId:number, noApply:boolean = false) => {
|
|||
// Clear current messages
|
||||
clearMessages(chatId)
|
||||
// Add the system prompt
|
||||
const systemPromptMessage:Message = {
|
||||
role: 'system',
|
||||
content: prepareProfilePrompt(chatId),
|
||||
uuid: uuidv4()
|
||||
}
|
||||
addMessage(chatId, systemPromptMessage)
|
||||
setSystemPrompt(chatId)
|
||||
|
||||
// Add trainingPrompts, if any
|
||||
if (settings.trainingPrompts) {
|
||||
|
|
Loading…
Reference in New Issue