Controls.svelte 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script lang="ts">
  2. import { createEventDispatcher, getContext } from 'svelte';
  3. const dispatch = createEventDispatcher();
  4. const i18n = getContext('i18n');
  5. import XMark from '$lib/components/icons/XMark.svelte';
  6. import AdvancedParams from '../Settings/Advanced/AdvancedParams.svelte';
  7. import Valves from '$lib/components/chat/Controls/Valves.svelte';
  8. import FileItem from '$lib/components/common/FileItem.svelte';
  9. import Collapsible from '$lib/components/common/Collapsible.svelte';
  10. import { user } from '$lib/stores';
  11. export let models = [];
  12. export let chatFiles = [];
  13. export let params = {};
  14. let showValves = false;
  15. </script>
  16. <div class=" dark:text-white">
  17. <div class=" flex items-center justify-between dark:text-gray-100 mb-2">
  18. <div class=" text-lg font-medium self-center font-primary">{$i18n.t('Chat Controls')}</div>
  19. <button
  20. class="self-center"
  21. on:click={() => {
  22. dispatch('close');
  23. }}
  24. >
  25. <XMark className="size-3.5" />
  26. </button>
  27. </div>
  28. {#if $user.role === 'admin' || $user?.permissions.chat?.controls}
  29. <div class=" dark:text-gray-200 text-sm font-primary py-0.5 px-0.5">
  30. {#if chatFiles.length > 0}
  31. <Collapsible title={$i18n.t('Files')} open={true} buttonClassName="w-full">
  32. <div class="flex flex-col gap-1 mt-1.5" slot="content">
  33. {#each chatFiles as file, fileIdx}
  34. <FileItem
  35. className="w-full"
  36. item={file}
  37. edit={true}
  38. url={file?.url ? file.url : null}
  39. name={file.name}
  40. type={file.type}
  41. size={file?.size}
  42. dismissible={true}
  43. on:dismiss={() => {
  44. // Remove the file from the chatFiles array
  45. chatFiles.splice(fileIdx, 1);
  46. chatFiles = chatFiles;
  47. }}
  48. on:click={() => {
  49. console.log(file);
  50. }}
  51. />
  52. {/each}
  53. </div>
  54. </Collapsible>
  55. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  56. {/if}
  57. <Collapsible bind:open={showValves} title={$i18n.t('Valves')} buttonClassName="w-full">
  58. <div class="text-sm" slot="content">
  59. <Valves show={showValves} />
  60. </div>
  61. </Collapsible>
  62. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  63. <Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">
  64. <div class="" slot="content">
  65. <textarea
  66. bind:value={params.system}
  67. class="w-full text-xs py-1.5 bg-transparent outline-hidden resize-none"
  68. rows="4"
  69. placeholder={$i18n.t('Enter system prompt')}
  70. />
  71. </div>
  72. </Collapsible>
  73. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  74. <Collapsible title={$i18n.t('Advanced Params')} open={true} buttonClassName="w-full">
  75. <div class="text-sm mt-1.5" slot="content">
  76. <div>
  77. <AdvancedParams admin={$user?.role === 'admin'} bind:params />
  78. </div>
  79. </div>
  80. </Collapsible>
  81. </div>
  82. {:else}
  83. <div class="text-sm dark:text-gray-300 text-center py-2 px-10">
  84. {$i18n.t('You do not have permission to access this feature.')}
  85. </div>
  86. {/if}
  87. </div>