Interface.svelte 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <script lang="ts">
  2. import { getBackendConfig } from '$lib/apis';
  3. import { setDefaultPromptSuggestions } from '$lib/apis/configs';
  4. import { config, models, settings, user } from '$lib/stores';
  5. import { createEventDispatcher, onMount, getContext } from 'svelte';
  6. import { toast } from 'svelte-sonner';
  7. import Tooltip from '$lib/components/common/Tooltip.svelte';
  8. const dispatch = createEventDispatcher();
  9. const i18n = getContext('i18n');
  10. let taskModel = '';
  11. let taskModelExternal = '';
  12. let titleGenerationPrompt = '';
  13. let promptSuggestions = [];
  14. const updateInterfaceHandler = async () => {
  15. promptSuggestions = await setDefaultPromptSuggestions(localStorage.token, promptSuggestions);
  16. await config.set(await getBackendConfig());
  17. };
  18. onMount(async () => {
  19. taskModel = $settings?.title?.model ?? '';
  20. taskModelExternal = $settings?.title?.modelExternal ?? '';
  21. titleGenerationPrompt =
  22. $settings?.title?.prompt ??
  23. `Create a concise, 3-5 word phrase as a header for the following query, strictly adhering to the 3-5 word limit and avoiding the use of the word 'title': {{prompt}}`;
  24. promptSuggestions = $config?.default_prompt_suggestions;
  25. });
  26. </script>
  27. <form
  28. class="flex flex-col h-full justify-between space-y-3 text-sm"
  29. on:submit|preventDefault={() => {
  30. updateInterfaceHandler();
  31. dispatch('save');
  32. }}
  33. >
  34. <div class=" space-y-3 pr-1.5 overflow-y-scroll scrollbar-hidden h-full">
  35. <div>
  36. <div class=" mb-2.5 text-sm font-medium flex">
  37. <div class=" mr-1">{$i18n.t('Set Task Model')}</div>
  38. <Tooltip
  39. content={$i18n.t(
  40. 'A task model is used when performing tasks such as generating titles for chats and web search queries'
  41. )}
  42. >
  43. <svg
  44. xmlns="http://www.w3.org/2000/svg"
  45. fill="none"
  46. viewBox="0 0 24 24"
  47. stroke-width="1.5"
  48. stroke="currentColor"
  49. class="w-5 h-5"
  50. >
  51. <path
  52. stroke-linecap="round"
  53. stroke-linejoin="round"
  54. d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
  55. />
  56. </svg>
  57. </Tooltip>
  58. </div>
  59. <div class="flex w-full gap-2 pr-2">
  60. <div class="flex-1">
  61. <div class=" text-xs mb-1">{$i18n.t('Local Models')}</div>
  62. <select
  63. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  64. bind:value={taskModel}
  65. placeholder={$i18n.t('Select a model')}
  66. >
  67. <option value="" selected>{$i18n.t('Current Model')}</option>
  68. {#each $models.filter((m) => m.owned_by === 'ollama') as model}
  69. <option value={model.id} class="bg-gray-100 dark:bg-gray-700">
  70. {model.name}
  71. </option>
  72. {/each}
  73. </select>
  74. </div>
  75. <div class="flex-1">
  76. <div class=" text-xs mb-1">{$i18n.t('External Models')}</div>
  77. <select
  78. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  79. bind:value={taskModelExternal}
  80. placeholder={$i18n.t('Select a model')}
  81. >
  82. <option value="" selected>{$i18n.t('Current Model')}</option>
  83. {#each $models as model}
  84. <option value={model.id} class="bg-gray-100 dark:bg-gray-700">
  85. {model.name}
  86. </option>
  87. {/each}
  88. </select>
  89. </div>
  90. </div>
  91. <div class="mt-3 mr-2">
  92. <div class=" mb-2.5 text-sm font-medium">{$i18n.t('Title Generation Prompt')}</div>
  93. <textarea
  94. bind:value={titleGenerationPrompt}
  95. class="w-full rounded-lg p-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  96. rows="3"
  97. />
  98. </div>
  99. </div>
  100. {#if $user.role === 'admin'}
  101. <hr class=" dark:border-gray-850" />
  102. <div class=" space-y-3 pr-1.5">
  103. <div class="flex w-full justify-between mb-2">
  104. <div class=" self-center text-sm font-semibold">
  105. {$i18n.t('Default Prompt Suggestions')}
  106. </div>
  107. <button
  108. class="p-1 px-3 text-xs flex rounded transition"
  109. type="button"
  110. on:click={() => {
  111. if (promptSuggestions.length === 0 || promptSuggestions.at(-1).content !== '') {
  112. promptSuggestions = [...promptSuggestions, { content: '', title: ['', ''] }];
  113. }
  114. }}
  115. >
  116. <svg
  117. xmlns="http://www.w3.org/2000/svg"
  118. viewBox="0 0 20 20"
  119. fill="currentColor"
  120. class="w-4 h-4"
  121. >
  122. <path
  123. d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
  124. />
  125. </svg>
  126. </button>
  127. </div>
  128. <div class="flex flex-col gap-1.5">
  129. {#each promptSuggestions as prompt, promptIdx}
  130. <div class=" flex dark:bg-gray-850 rounded-xl py-1.5">
  131. <div class="flex flex-col flex-1 pl-1">
  132. <div class="flex border-b dark:border-gray-800 w-full">
  133. <input
  134. class="px-3 py-1.5 text-xs w-full bg-transparent outline-none border-r dark:border-gray-800"
  135. placeholder={$i18n.t('Title (e.g. Tell me a fun fact)')}
  136. bind:value={prompt.title[0]}
  137. />
  138. <input
  139. class="px-3 py-1.5 text-xs w-full bg-transparent outline-none border-r dark:border-gray-800"
  140. placeholder={$i18n.t('Subtitle (e.g. about the Roman Empire)')}
  141. bind:value={prompt.title[1]}
  142. />
  143. </div>
  144. <input
  145. class="px-3 py-1.5 text-xs w-full bg-transparent outline-none border-r dark:border-gray-800"
  146. placeholder={$i18n.t('Prompt (e.g. Tell me a fun fact about the Roman Empire)')}
  147. bind:value={prompt.content}
  148. />
  149. </div>
  150. <button
  151. class="px-3"
  152. type="button"
  153. on:click={() => {
  154. promptSuggestions.splice(promptIdx, 1);
  155. promptSuggestions = promptSuggestions;
  156. }}
  157. >
  158. <svg
  159. xmlns="http://www.w3.org/2000/svg"
  160. viewBox="0 0 20 20"
  161. fill="currentColor"
  162. class="w-4 h-4"
  163. >
  164. <path
  165. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  166. />
  167. </svg>
  168. </button>
  169. </div>
  170. {/each}
  171. </div>
  172. {#if promptSuggestions.length > 0}
  173. <div class="text-xs text-left w-full mt-2">
  174. {$i18n.t('Adjusting these settings will apply changes universally to all users.')}
  175. </div>
  176. {/if}
  177. </div>
  178. {/if}
  179. </div>
  180. <div class="flex justify-end text-sm font-medium">
  181. <button
  182. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  183. type="submit"
  184. >
  185. {$i18n.t('Save')}
  186. </button>
  187. </div>
  188. </form>