Controls.svelte 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. <div class=" dark:text-gray-200 text-sm font-primary py-0.5 px-0.5">
  29. {#if chatFiles.length > 0}
  30. <Collapsible title={$i18n.t('Files')} open={true} buttonClassName="w-full">
  31. <div class="flex flex-col gap-1 mt-1.5" slot="content">
  32. {#each chatFiles as file, fileIdx}
  33. <FileItem
  34. className="w-full"
  35. item={file}
  36. edit={true}
  37. url={file?.url ? file.url : null}
  38. name={file.name}
  39. type={file.type}
  40. size={file?.size}
  41. dismissible={true}
  42. on:dismiss={() => {
  43. // Remove the file from the chatFiles array
  44. chatFiles.splice(fileIdx, 1);
  45. chatFiles = chatFiles;
  46. }}
  47. on:click={() => {
  48. console.log(file);
  49. }}
  50. />
  51. {/each}
  52. </div>
  53. </Collapsible>
  54. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  55. {/if}
  56. <Collapsible bind:open={showValves} title={$i18n.t('Valves')} buttonClassName="w-full">
  57. <div class="text-sm" slot="content">
  58. <Valves show={showValves} />
  59. </div>
  60. </Collapsible>
  61. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  62. <Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">
  63. <div class="" slot="content">
  64. <textarea
  65. bind:value={params.system}
  66. class="w-full text-xs py-1.5 bg-transparent outline-none resize-none"
  67. rows="4"
  68. placeholder={$i18n.t('Enter system prompt')}
  69. />
  70. </div>
  71. </Collapsible>
  72. <hr class="my-2 border-gray-50 dark:border-gray-700/10" />
  73. <Collapsible title={$i18n.t('Advanced Params')} open={true} buttonClassName="w-full">
  74. <div class="text-sm mt-1.5" slot="content">
  75. <div>
  76. <AdvancedParams admin={$user?.role === 'admin'} bind:params />
  77. </div>
  78. </div>
  79. </Collapsible>
  80. </div>
  81. </div>