fix lint
This commit is contained in:
		
							parent
							
								
									b201f03b67
								
							
						
					
					
						commit
						b1acf6806a
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -684,7 +683,7 @@
 | 
			
		|||
  <div class="level-right">
 | 
			
		||||
    <div class="level-item">
 | 
			
		||||
      
 | 
			
		||||
      <div class="dropdown is-right" class:is-active={showChatMenu} use:clickOutside={()=>{showChatMenu=false}}>
 | 
			
		||||
      <div class="dropdown is-right" class:is-active={showChatMenu} use:clickOutside={() => { showChatMenu = false }}>
 | 
			
		||||
        <div class="dropdown-trigger">
 | 
			
		||||
          <button class="button" aria-haspopup="true" 
 | 
			
		||||
            aria-controls="dropdown-menu3" 
 | 
			
		||||
| 
						 | 
				
			
			@ -695,11 +694,11 @@
 | 
			
		|||
        </div>
 | 
			
		||||
        <div class="dropdown-menu" id="dropdown-menu3" role="menu">
 | 
			
		||||
          <div class="dropdown-content">
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false;showSettings() }}>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false; showSettings() }}>
 | 
			
		||||
              <span><Fa icon={faGear}/></span> Settings
 | 
			
		||||
            </a>
 | 
			
		||||
            <hr class="dropdown-divider">
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false;copyChat(chatId) }}>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false; copyChat(chatId) }}>
 | 
			
		||||
              <span><Fa icon={faClone}/></span> Clone Chat
 | 
			
		||||
            </a>
 | 
			
		||||
            <hr class="dropdown-divider">
 | 
			
		||||
| 
						 | 
				
			
			@ -713,14 +712,14 @@
 | 
			
		|||
              <span><Fa icon={faUpload}/></span> Load Chat
 | 
			
		||||
            </a>
 | 
			
		||||
            <hr class="dropdown-divider">
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={()=>{applyProfile(chatId, '', true);closeSettings()}}>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { applyProfile(chatId, '', true); closeSettings() }}>
 | 
			
		||||
              <span><Fa icon={faRotateRight}/></span> Restart Chat
 | 
			
		||||
            </a>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={()=>{showChatMenu = false;clearMessages(chatId)}}>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false; clearMessages(chatId) }}>
 | 
			
		||||
              <span><Fa icon={faEraser}/></span> Clear Chat Messages
 | 
			
		||||
            </a>
 | 
			
		||||
            <hr class="dropdown-divider">
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={()=>{showChatMenu = false;deleteChat()}}>
 | 
			
		||||
            <a href={'#'} class="dropdown-item" on:click|preventDefault={() => { showChatMenu = false; deleteChat() }}>
 | 
			
		||||
              <span><Fa icon={faTrash}/></span> Delete Chat
 | 
			
		||||
            </a>
 | 
			
		||||
          </div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -37,11 +36,11 @@ export const getProfileSelect = ():SelectOption[] => {
 | 
			
		|||
export const getProfile = (key:string):ChatSettings => {
 | 
			
		||||
      const allProfiles = getProfiles()
 | 
			
		||||
      const profile = allProfiles[key] ||
 | 
			
		||||
      allProfiles[getGlobalSettings().defaultProfile||''] ||
 | 
			
		||||
      allProfiles[getGlobalSettings().defaultProfile || ''] ||
 | 
			
		||||
      profiles[defaultProfile] ||
 | 
			
		||||
      profiles[Object.keys(profiles)[0]]
 | 
			
		||||
      const clone = JSON.parse(JSON.stringify(profile)) // Always return a copy
 | 
			
		||||
      Object.keys(getExcludeFromProfile()).forEach(k=>{
 | 
			
		||||
      Object.keys(getExcludeFromProfile()).forEach(k => {
 | 
			
		||||
        delete clone[k]
 | 
			
		||||
      })
 | 
			
		||||
      return clone
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			@ -318,13 +318,13 @@ const chatSettingsList: ChatSetting[] = [
 | 
			
		|||
        apiTransform: (chatId, setting, val:Record<string, number>) => {
 | 
			
		||||
          console.log('logit_bias', val, getChatSettings(chatId).logit_bias)
 | 
			
		||||
          if (!val) return null
 | 
			
		||||
          const tokenized:Record<number, number> = Object.entries(val).reduce((a,[k,v])=>{
 | 
			
		||||
          const tokenized:Record<number, number> = Object.entries(val).reduce((a, [k, v]) => {
 | 
			
		||||
            const tokens:number[] = encode(k)
 | 
			
		||||
            tokens.forEach(t => {a[t] = v})
 | 
			
		||||
            tokens.forEach(t => { a[t] = v })
 | 
			
		||||
            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
 | 
			
		||||
      }
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@
 | 
			
		|||
    })
 | 
			
		||||
    chatsStorage.set(chats)
 | 
			
		||||
    // Apply defaults and prepare it to start
 | 
			
		||||
    applyProfile(chatId,'', true)
 | 
			
		||||
    applyProfile(chatId, '', true)
 | 
			
		||||
    return chatId
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +70,7 @@
 | 
			
		|||
    if (!chat.settings) {
 | 
			
		||||
      chat.settings = {} as ChatSettings
 | 
			
		||||
    }
 | 
			
		||||
    Object.entries(getChatDefaults()).forEach(([k,v]) => {
 | 
			
		||||
    Object.entries(getChatDefaults()).forEach(([k, v]) => {
 | 
			
		||||
      const val = chat.settings[k]
 | 
			
		||||
      chat.settings[k] = (val === undefined || val === null ? v : chat.settings[k]) as any
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			@ -89,11 +89,11 @@
 | 
			
		|||
    const exclude = getExcludeFromProfile()
 | 
			
		||||
    if (resetAll) {
 | 
			
		||||
      // Reset to base defaults first, then apply profile
 | 
			
		||||
      Object.entries(getChatDefaults()).forEach(([k,v]) => {
 | 
			
		||||
      Object.entries(getChatDefaults()).forEach(([k, v]) => {
 | 
			
		||||
        chat.settings[k] = v
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
    Object.entries(profile).forEach(([k,v]) => {
 | 
			
		||||
    Object.entries(profile).forEach(([k, v]) => {
 | 
			
		||||
      if (exclude[k]) return
 | 
			
		||||
      chat.settings[k] = v
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -296,8 +298,8 @@
 | 
			
		|||
    if (!profile.characterName || profile.characterName.length < 3) {
 | 
			
		||||
      throw new Error('Your profile\'s character needs a valid name.')
 | 
			
		||||
    }
 | 
			
		||||
    const clone =JSON.parse(JSON.stringify(profile)) // Always store a copy
 | 
			
		||||
    Object.keys(getExcludeFromProfile()).forEach(k=>{
 | 
			
		||||
    const clone = JSON.parse(JSON.stringify(profile)) // Always store a copy
 | 
			
		||||
    Object.keys(getExcludeFromProfile()).forEach(k => {
 | 
			
		||||
      delete clone[k]
 | 
			
		||||
    })
 | 
			
		||||
    profiles[profile.profile as string] = clone
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue