This commit is contained in:
Webifi 2023-05-28 01:21:06 -05:00
parent b201f03b67
commit b1acf6806a
4 changed files with 53 additions and 53 deletions

View File

@ -17,7 +17,7 @@
updateChatSettings,
resetChatSettings,
setChatSettingValue,
addChatFromJSON,
addChatFromJSON
} from './Storage.svelte'
import { getChatSettingObjectByKey, getChatSettingList, getRequestSettingList } from './Settings.svelte'
import {
@ -29,8 +29,7 @@
type SettingSelect,
type Chat,
type SelectOption,
supportedModels,
type ChatSettings
supportedModels
} from './Types.svelte'
import Prompts from './Prompts.svelte'
import Messages from './Messages.svelte'
@ -54,7 +53,7 @@
faDownload,
faUpload,
faEraser,
faRotateRight,
faRotateRight
} from '@fortawesome/free-solid-svg-icons/index'
import { encode } from 'gpt-tokenizer'
import { v4 as uuidv4 } from 'uuid'
@ -532,10 +531,10 @@
const el = (event.target as HTMLInputElement)
const doSet = () => {
try {
(typeof setting.beforeChange === 'function') && setting.beforeChange(chatId, setting, el.checked || el.value)
&& refreshSettings()
(typeof setting.beforeChange === 'function') && setting.beforeChange(chatId, setting, el.checked || el.value) &&
refreshSettings()
} catch (e) {
alert('Unable to change:\n' + e.message)
window.alert('Unable to change:\n' + e.message)
}
switch (setting.type) {
case 'boolean':
@ -546,15 +545,15 @@
setChatSettingValue(chatId, setting, el.value)
}
try {
(typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting, chatSettings[setting.key])
&& refreshSettings()
(typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting, chatSettings[setting.key]) &&
refreshSettings()
} catch (e) {
setChatSettingValue(chatId, setting, val)
alert('Unable to change:\n' + e.message)
window.alert('Unable to change:\n' + e.message)
}
}
if (setting.key === 'profile' && chatSettings.sessionStarted
&& (getProfile(el.value).characterName !== chatSettings.characterName)) {
if (setting.key === 'profile' && chatSettings.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?')) {
doSet()
@ -584,7 +583,7 @@
saveCustomProfile(chat.settings)
refreshSettings()
} catch (e) {
alert('Error saving profile: \n' + e.message)
window.alert('Error saving profile: \n' + e.message)
}
}
@ -614,7 +613,7 @@
updateProfileSelectOptions()
showSettingsModal && showSettingsModal++
} catch (e) {
alert('Error cloning profile: \n' + e.message)
window.alert('Error cloning profile: \n' + e.message)
}
}
@ -629,7 +628,7 @@
updateProfileSelectOptions()
showSettings()
} catch (e) {
alert('Error deleting profile: \n' + e.message)
window.alert('Error deleting profile: \n' + e.message)
}
}
@ -652,7 +651,7 @@
updateProfileSelectOptions()
showSettingsModal && showSettingsModal++
} catch (e) {
alert('Unable to import profile: \n' + e.message)
window.alert('Unable to import profile: \n' + e.message)
}
}
}

View File

@ -1,8 +1,7 @@
<script context="module" lang="ts">
import copy from 'copy-to-clipboard';
import { getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
// Profile definitions
import { addMessage, clearMessages, getChatSettings, getCustomProfiles, getGlobalSettings, getMessages, resetChatSettings, setChatSettingValue, setChatSettingValueByKey, setGlobalSettingValueByKey } from './Storage.svelte'
import { addMessage, clearMessages, getChatSettings, getCustomProfiles, getGlobalSettings, resetChatSettings, setChatSettingValueByKey, setGlobalSettingValueByKey } from './Storage.svelte'
import type { Message, SelectOption, ChatSettings } from './Types.svelte'
import { v4 as uuidv4 } from 'uuid'

View File

@ -1,6 +1,6 @@
<script context="module" lang="ts">
import { applyProfile } from './Profiles.svelte'
import { getChatSettings } from './Storage.svelte';
import { getChatSettings } from './Storage.svelte'
import { encode } from 'gpt-tokenizer'
// Setting definitions
@ -59,7 +59,7 @@ const gptDefaults: Request = Object.freeze({
presence_penalty: 0,
frequency_penalty: 0,
logit_bias: null,
user: undefined,
user: undefined
})
// Core set of defaults
@ -82,14 +82,14 @@ const defaults:ChatSettings = Object.freeze({
// 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)
sessionStarted: false // Has the session started (user made a first request)
})
const excludeFromProfile = {
messages: true,
startSession: true,
sessionStarted: true,
user: true,
user: true
}
const profileSetting: ChatSetting & SettingSelect = {
@ -103,7 +103,7 @@ const profileSetting: ChatSetting & SettingSelect = {
afterChange: (chatId, setting) => {
applyProfile(chatId, '', !getChatSettings(chatId).sessionStarted)
return true // Signal we should refresh the setting modal
},
}
}
// Settings that will not be part of the API request
@ -113,14 +113,14 @@ const nonRequestSettings: ChatSetting[] = [
key: 'profileName',
name: 'Profile Name',
title: 'How this profile is displayed in the select list.',
type: 'text',
type: 'text'
// hide: (chatId) => { return !getChatSettingValueByKey(chatId, 'useSystemPrompt') }
},
{
key: 'profileDescription',
name: 'Description',
title: 'How this profile is displayed in the select list.',
type: 'textarea',
type: 'textarea'
// hide: (chatId) => { return !getChatSettingValueByKey(chatId, 'useSystemPrompt') }
},
{
@ -129,14 +129,14 @@ const nonRequestSettings: ChatSetting[] = [
title: 'Send a "System" prompt as the first prompt.',
header: 'System Prompt',
headerClass: 'is-info',
type: 'boolean',
type: 'boolean'
},
{
key: 'characterName',
name: 'Character Name',
title: 'What the personality of this profile will be called.',
type: 'text',
hide: (chatId) => !getChatSettings(chatId).useSystemPrompt,
hide: (chatId) => !getChatSettings(chatId).useSystemPrompt
},
{
key: 'systemPrompt',
@ -173,7 +173,7 @@ const nonRequestSettings: ChatSetting[] = [
header: 'Continuous Chat - Summarization',
headerClass: 'is-info',
title: 'When out of token space, summarize past tokens and keep going.',
type: 'boolean',
type: 'boolean'
},
{
key: 'summaryThreshold',
@ -235,7 +235,7 @@ const modelSetting: ChatSetting & SettingSelect = {
headerClass: 'is-warning',
options: [],
type: 'select',
forceApi: true, // Need to make sure we send this
forceApi: true // Need to make sure we send this
}
const chatSettingsList: ChatSetting[] = [
@ -307,7 +307,7 @@ const chatSettingsList: ChatSetting[] = [
key: 'logit_bias',
name: 'Logit Bias',
title: 'Allows you to adjust bias of tokens used in completion.',
header: `Logit Bias. See <a target="_blank" href="https://help.openai.com/en/articles/5247780-using-logit-bias-to-define-token-probability">this article</a> for more details.`,
header: 'Logit Bias. See <a target="_blank" href="https://help.openai.com/en/articles/5247780-using-logit-bias-to-define-token-probability">this article</a> for more details.',
type: 'other',
hide: () => true,
// transform to JSON for request, first converting word->weight pairs to token(s)->weight.
@ -324,7 +324,7 @@ const chatSettingsList: ChatSetting[] = [
return a
}, {} as Record<number, number>)
return tokenized
},
}
},
// Enable?
{
@ -332,7 +332,7 @@ const chatSettingsList: ChatSetting[] = [
name: 'User?',
title: 'Name of user?',
type: 'text',
hide: () => true,
hide: () => true
}
]

View File

@ -211,11 +211,13 @@
if (setting) return setChatSettingValue(chatId, setting, value)
if (!(key in chatDefaults)) throw new Error('Invalid chat setting: ' + key)
const d = chatDefaults[key]
if (d === null || d === undefined) throw new Error('Unable to determine setting type for "'
+ key +' from default of "' + d + '"')
if (d === null || d === undefined) {
throw new Error('Unable to determine setting type for "' +
key + ' from default of "' + d + '"')
}
const chats = get(chatsStorage)
const chat = chats.find((chat) => chat.id === chatId) as Chat
let settings = chat.settings as any
const settings = chat.settings as any
settings[key] = cleanSettingValue(typeof d, value)
}