Advanced.svelte 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <script lang="ts">
  2. import { createEventDispatcher, onMount, getContext } from 'svelte';
  3. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  4. const i18n = getContext('i18n');
  5. const dispatch = createEventDispatcher();
  6. export let saveSettings: Function;
  7. // Advanced
  8. let requestFormat = '';
  9. let keepAlive = null;
  10. let options = {
  11. // Advanced
  12. seed: 0,
  13. temperature: '',
  14. repeat_penalty: '',
  15. repeat_last_n: '',
  16. mirostat: '',
  17. mirostat_eta: '',
  18. mirostat_tau: '',
  19. top_k: '',
  20. top_p: '',
  21. stop: '',
  22. tfs_z: '',
  23. num_ctx: '',
  24. num_predict: ''
  25. };
  26. const toggleRequestFormat = async () => {
  27. if (requestFormat === '') {
  28. requestFormat = 'json';
  29. } else {
  30. requestFormat = '';
  31. }
  32. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  33. };
  34. onMount(() => {
  35. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  36. requestFormat = settings.requestFormat ?? '';
  37. keepAlive = settings.keepAlive ?? null;
  38. options.seed = settings.seed ?? 0;
  39. options.temperature = settings.temperature ?? '';
  40. options.repeat_penalty = settings.repeat_penalty ?? '';
  41. options.top_k = settings.top_k ?? '';
  42. options.top_p = settings.top_p ?? '';
  43. options.num_ctx = settings.num_ctx ?? '';
  44. options = { ...options, ...settings.options };
  45. options.stop = (settings?.options?.stop ?? []).join(',');
  46. });
  47. </script>
  48. <div class="flex flex-col h-full justify-between text-sm">
  49. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
  50. <div class=" text-sm font-medium">{$i18n.t('Parameters')}</div>
  51. <AdvancedParams bind:options />
  52. <hr class=" dark:border-gray-700" />
  53. <div class=" py-1 w-full justify-between">
  54. <div class="flex w-full justify-between">
  55. <div class=" self-center text-xs font-medium">{$i18n.t('Keep Alive')}</div>
  56. <button
  57. class="p-1 px-3 text-xs flex rounded transition"
  58. type="button"
  59. on:click={() => {
  60. keepAlive = keepAlive === null ? '5m' : null;
  61. }}
  62. >
  63. {#if keepAlive === null}
  64. <span class="ml-2 self-center">{$i18n.t('Default')}</span>
  65. {:else}
  66. <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
  67. {/if}
  68. </button>
  69. </div>
  70. {#if keepAlive !== null}
  71. <div class="flex mt-1 space-x-2">
  72. <input
  73. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  74. type="text"
  75. placeholder={$i18n.t("e.g. '30s','10m'. Valid time units are 's', 'm', 'h'.")}
  76. bind:value={keepAlive}
  77. />
  78. </div>
  79. {/if}
  80. </div>
  81. <div>
  82. <div class=" py-1 flex w-full justify-between">
  83. <div class=" self-center text-sm font-medium">{$i18n.t('Request Mode')}</div>
  84. <button
  85. class="p-1 px-3 text-xs flex rounded transition"
  86. on:click={() => {
  87. toggleRequestFormat();
  88. }}
  89. >
  90. {#if requestFormat === ''}
  91. <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
  92. {:else if requestFormat === 'json'}
  93. <!-- <svg
  94. xmlns="http://www.w3.org/2000/svg"
  95. viewBox="0 0 20 20"
  96. fill="currentColor"
  97. class="w-4 h-4 self-center"
  98. >
  99. <path
  100. d="M10 2a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 0110 2zM10 15a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 0110 15zM10 7a3 3 0 100 6 3 3 0 000-6zM15.657 5.404a.75.75 0 10-1.06-1.06l-1.061 1.06a.75.75 0 001.06 1.06l1.06-1.06zM6.464 14.596a.75.75 0 10-1.06-1.06l-1.06 1.06a.75.75 0 001.06 1.06l1.06-1.06zM18 10a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 0118 10zM5 10a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 015 10zM14.596 15.657a.75.75 0 001.06-1.06l-1.06-1.061a.75.75 0 10-1.06 1.06l1.06 1.06zM5.404 6.464a.75.75 0 001.06-1.06l-1.06-1.06a.75.75 0 10-1.061 1.06l1.06 1.06z"
  101. />
  102. </svg> -->
  103. <span class="ml-2 self-center">{$i18n.t('JSON')}</span>
  104. {/if}
  105. </button>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="flex justify-end pt-3 text-sm font-medium">
  110. <button
  111. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  112. on:click={() => {
  113. saveSettings({
  114. options: {
  115. seed: (options.seed !== 0 ? options.seed : undefined) ?? undefined,
  116. stop: options.stop !== '' ? options.stop.split(',').filter((e) => e) : undefined,
  117. temperature: options.temperature !== '' ? options.temperature : undefined,
  118. repeat_penalty: options.repeat_penalty !== '' ? options.repeat_penalty : undefined,
  119. repeat_last_n: options.repeat_last_n !== '' ? options.repeat_last_n : undefined,
  120. mirostat: options.mirostat !== '' ? options.mirostat : undefined,
  121. mirostat_eta: options.mirostat_eta !== '' ? options.mirostat_eta : undefined,
  122. mirostat_tau: options.mirostat_tau !== '' ? options.mirostat_tau : undefined,
  123. top_k: options.top_k !== '' ? options.top_k : undefined,
  124. top_p: options.top_p !== '' ? options.top_p : undefined,
  125. tfs_z: options.tfs_z !== '' ? options.tfs_z : undefined,
  126. num_ctx: options.num_ctx !== '' ? options.num_ctx : undefined,
  127. num_predict: options.num_predict !== '' ? options.num_predict : undefined
  128. },
  129. keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined
  130. });
  131. dispatch('save');
  132. }}
  133. >
  134. {$i18n.t('Save')}
  135. </button>
  136. </div>
  137. </div>