Advanced.svelte 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <script lang="ts">
  2. import { createEventDispatcher, onMount } from 'svelte';
  3. const dispatch = createEventDispatcher();
  4. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  5. export let saveSettings: Function;
  6. // Advanced
  7. let requestFormat = '';
  8. let keepAlive = '';
  9. let options = {
  10. // Advanced
  11. seed: 0,
  12. temperature: '',
  13. repeat_penalty: '',
  14. repeat_last_n: '',
  15. mirostat: '',
  16. mirostat_eta: '',
  17. mirostat_tau: '',
  18. top_k: '',
  19. top_p: '',
  20. stop: '',
  21. tfs_z: '',
  22. num_ctx: '',
  23. num_predict: ''
  24. };
  25. const toggleRequestFormat = async () => {
  26. if (requestFormat === '') {
  27. requestFormat = 'json';
  28. } else {
  29. requestFormat = '';
  30. }
  31. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  32. };
  33. onMount(() => {
  34. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  35. requestFormat = settings.requestFormat ?? '';
  36. keepAlive = settings.keepAlive ?? '';
  37. options.seed = settings.seed ?? 0;
  38. options.temperature = settings.temperature ?? '';
  39. options.repeat_penalty = settings.repeat_penalty ?? '';
  40. options.top_k = settings.top_k ?? '';
  41. options.top_p = settings.top_p ?? '';
  42. options.num_ctx = settings.num_ctx ?? '';
  43. options = { ...options, ...settings.options };
  44. options.stop = (settings?.options?.stop ?? []).join(',');
  45. });
  46. </script>
  47. <div class="flex flex-col h-full justify-between text-sm">
  48. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
  49. <div class=" text-sm font-medium">Parameters</div>
  50. <AdvancedParams bind:options />
  51. <hr class=" dark:border-gray-700" />
  52. <div>
  53. <div class=" py-1 flex w-full justify-between">
  54. <div class=" self-center text-sm font-medium">Request Mode</div>
  55. <button
  56. class="p-1 px-3 text-xs flex rounded transition"
  57. on:click={() => {
  58. toggleRequestFormat();
  59. }}
  60. >
  61. {#if requestFormat === ''}
  62. <span class="ml-2 self-center"> Default </span>
  63. {:else if requestFormat === 'json'}
  64. <!-- <svg
  65. xmlns="http://www.w3.org/2000/svg"
  66. viewBox="0 0 20 20"
  67. fill="currentColor"
  68. class="w-4 h-4 self-center"
  69. >
  70. <path
  71. 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"
  72. />
  73. </svg> -->
  74. <span class="ml-2 self-center"> JSON </span>
  75. {/if}
  76. </button>
  77. </div>
  78. </div>
  79. <div class=" py-1 flex w-full justify-between">
  80. <div class=" w-20 text-xs font-medium self-center">Keep Alive</div>
  81. <div class=" flex-1 self-center">
  82. <input
  83. class="w-full rounded py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none border border-gray-100 dark:border-gray-600"
  84. type="number"
  85. placeholder="Default"
  86. bind:value={keepAlive}
  87. autocomplete="off"
  88. min="-1"
  89. />
  90. </div>
  91. </div>
  92. </div>
  93. <div class="flex justify-end pt-3 text-sm font-medium">
  94. <button
  95. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  96. on:click={() => {
  97. saveSettings({
  98. options: {
  99. seed: (options.seed !== 0 ? options.seed : undefined) ?? undefined,
  100. stop: options.stop !== '' ? options.stop.split(',').filter((e) => e) : undefined,
  101. temperature: options.temperature !== '' ? options.temperature : undefined,
  102. repeat_penalty: options.repeat_penalty !== '' ? options.repeat_penalty : undefined,
  103. repeat_last_n: options.repeat_last_n !== '' ? options.repeat_last_n : undefined,
  104. mirostat: options.mirostat !== '' ? options.mirostat : undefined,
  105. mirostat_eta: options.mirostat_eta !== '' ? options.mirostat_eta : undefined,
  106. mirostat_tau: options.mirostat_tau !== '' ? options.mirostat_tau : undefined,
  107. top_k: options.top_k !== '' ? options.top_k : undefined,
  108. top_p: options.top_p !== '' ? options.top_p : undefined,
  109. tfs_z: options.tfs_z !== '' ? options.tfs_z : undefined,
  110. num_ctx: options.num_ctx !== '' ? options.num_ctx : undefined,
  111. num_predict: options.num_predict !== '' ? options.num_predict : undefined
  112. },
  113. keepAlive: keepAlive !== '' ? keepAlive : undefined
  114. });
  115. dispatch('save');
  116. }}
  117. >
  118. Save
  119. </button>
  120. </div>
  121. </div>