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

View File

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

View File

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