FolderModal.svelte 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script lang="ts">
  2. import { getContext, createEventDispatcher, onMount } from 'svelte';
  3. import Spinner from '$lib/components/common/Spinner.svelte';
  4. import Modal from '$lib/components/common/Modal.svelte';
  5. import XMark from '$lib/components/icons/XMark.svelte';
  6. import { toast } from 'svelte-sonner';
  7. import { page } from '$app/stores';
  8. import { goto } from '$app/navigation';
  9. import Textarea from '$lib/components/common/Textarea.svelte';
  10. import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
  11. import { user } from '$lib/stores';
  12. const i18n = getContext('i18n');
  13. export let show = false;
  14. export let onSubmit: Function = (e) => {};
  15. export let edit = false;
  16. export let folder = null;
  17. let name = '';
  18. let data = {
  19. system_prompt: '',
  20. files: []
  21. };
  22. let loading = false;
  23. const submitHandler = async () => {
  24. loading = true;
  25. await onSubmit({
  26. name,
  27. data
  28. });
  29. show = false;
  30. loading = false;
  31. };
  32. const init = () => {
  33. name = folder.name;
  34. data = folder.data || {
  35. system_prompt: '',
  36. files: []
  37. };
  38. };
  39. $: if (folder) {
  40. init();
  41. }
  42. </script>
  43. <Modal size="md" bind:show>
  44. <div>
  45. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-1">
  46. <div class=" text-lg font-medium self-center">
  47. {#if edit}
  48. {$i18n.t('Edit Folder')}
  49. {:else}
  50. {$i18n.t('Create Folder')}
  51. {/if}
  52. </div>
  53. <button
  54. class="self-center"
  55. on:click={() => {
  56. show = false;
  57. }}
  58. >
  59. <XMark className={'size-5'} />
  60. </button>
  61. </div>
  62. <div class="flex flex-col md:flex-row w-full px-5 pb-4 md:space-x-4 dark:text-gray-200">
  63. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  64. <form
  65. class="flex flex-col w-full"
  66. on:submit|preventDefault={() => {
  67. submitHandler();
  68. }}
  69. >
  70. <div class="flex flex-col w-full mt-1">
  71. <div class=" mb-1 text-xs text-gray-500">{$i18n.t('Folder Name')}</div>
  72. <div class="flex-1">
  73. <input
  74. class="w-full text-sm bg-transparent placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-hidden"
  75. type="text"
  76. bind:value={name}
  77. placeholder={$i18n.t('Enter folder name')}
  78. autocomplete="off"
  79. />
  80. </div>
  81. </div>
  82. <hr class=" border-gray-50 dark:border-gray-850 my-2.5 w-full" />
  83. {#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
  84. <div class="my-1">
  85. <div class="mb-2 text-xs text-gray-500">{$i18n.t('System Prompt')}</div>
  86. <div>
  87. <Textarea
  88. className=" text-sm w-full bg-transparent outline-hidden "
  89. placeholder={`Write your model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
  90. maxSize={200}
  91. bind:value={data.system_prompt}
  92. />
  93. </div>
  94. </div>
  95. {/if}
  96. <div class="my-2">
  97. <Knowledge bind:selectedItems={data.files}>
  98. <div slot="label">
  99. <div class="flex w-full justify-between">
  100. <div class=" mb-2 text-xs text-gray-500">
  101. {$i18n.t('Knowledge')}
  102. </div>
  103. </div>
  104. </div>
  105. </Knowledge>
  106. </div>
  107. <div class="flex justify-end pt-3 text-sm font-medium gap-1.5">
  108. <button
  109. class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-950 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full flex flex-row space-x-1 items-center {loading
  110. ? ' cursor-not-allowed'
  111. : ''}"
  112. type="submit"
  113. disabled={loading}
  114. >
  115. {$i18n.t('Save')}
  116. {#if loading}
  117. <div class="ml-2 self-center">
  118. <Spinner />
  119. </div>
  120. {/if}
  121. </button>
  122. </div>
  123. </form>
  124. </div>
  125. </div>
  126. </div>
  127. </Modal>