MessageInput.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <script lang="ts">
  2. import toast from 'svelte-french-toast';
  3. import { onMount, tick } from 'svelte';
  4. import { settings } from '$lib/stores';
  5. import { calculateSHA256, findWordIndices } from '$lib/utils';
  6. import Prompts from './MessageInput/PromptCommands.svelte';
  7. import Suggestions from './MessageInput/Suggestions.svelte';
  8. import { uploadDocToVectorDB } from '$lib/apis/rag';
  9. import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
  10. import { SUPPORTED_FILE_TYPE } from '$lib/constants';
  11. import Documents from './MessageInput/Documents.svelte';
  12. import Models from './MessageInput/Models.svelte';
  13. export let submitPrompt: Function;
  14. export let stopResponse: Function;
  15. export let suggestionPrompts = [];
  16. export let autoScroll = true;
  17. let filesInputElement;
  18. let promptsElement;
  19. let documentsElement;
  20. let modelsElement;
  21. let inputFiles;
  22. let dragged = false;
  23. let user = null;
  24. let chatInputPlaceholder = '';
  25. export let files = [];
  26. export let fileUploadEnabled = true;
  27. export let speechRecognitionEnabled = true;
  28. export let speechRecognitionListening = false;
  29. export let prompt = '';
  30. export let messages = [];
  31. let speechRecognition;
  32. $: if (prompt) {
  33. const chatInput = document.getElementById('chat-textarea');
  34. if (chatInput) {
  35. chatInput.style.height = '';
  36. chatInput.style.height = Math.min(chatInput.scrollHeight, 200) + 'px';
  37. }
  38. }
  39. const speechRecognitionHandler = () => {
  40. // Check if SpeechRecognition is supported
  41. if (speechRecognitionListening) {
  42. speechRecognition.stop();
  43. } else {
  44. if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
  45. // Create a SpeechRecognition object
  46. speechRecognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
  47. // Set continuous to true for continuous recognition
  48. speechRecognition.continuous = true;
  49. // Set the timeout for turning off the recognition after inactivity (in milliseconds)
  50. const inactivityTimeout = 3000; // 3 seconds
  51. let timeoutId;
  52. // Start recognition
  53. speechRecognition.start();
  54. speechRecognitionListening = true;
  55. // Event triggered when speech is recognized
  56. speechRecognition.onresult = function (event) {
  57. // Clear the inactivity timeout
  58. clearTimeout(timeoutId);
  59. // Handle recognized speech
  60. console.log(event);
  61. const transcript = event.results[Object.keys(event.results).length - 1][0].transcript;
  62. prompt = `${prompt}${transcript}`;
  63. // Restart the inactivity timeout
  64. timeoutId = setTimeout(() => {
  65. console.log('Speech recognition turned off due to inactivity.');
  66. speechRecognition.stop();
  67. }, inactivityTimeout);
  68. };
  69. // Event triggered when recognition is ended
  70. speechRecognition.onend = function () {
  71. // Restart recognition after it ends
  72. console.log('recognition ended');
  73. speechRecognitionListening = false;
  74. if (prompt !== '' && $settings?.speechAutoSend === true) {
  75. submitPrompt(prompt, user);
  76. }
  77. };
  78. // Event triggered when an error occurs
  79. speechRecognition.onerror = function (event) {
  80. console.log(event);
  81. toast.error(`Speech recognition error: ${event.error}`);
  82. speechRecognitionListening = false;
  83. };
  84. } else {
  85. toast.error('SpeechRecognition API is not supported in this browser.');
  86. }
  87. }
  88. };
  89. const uploadDoc = async (file) => {
  90. console.log(file);
  91. const doc = {
  92. type: 'doc',
  93. name: file.name,
  94. collection_name: '',
  95. upload_status: false,
  96. error: ''
  97. };
  98. files = [...files, doc];
  99. const res = await uploadDocToVectorDB(localStorage.token, '', file);
  100. if (res) {
  101. doc.upload_status = true;
  102. doc.collection_name = res.collection_name;
  103. files = files;
  104. }
  105. };
  106. onMount(() => {
  107. const dropZone = document.querySelector('body');
  108. const onDragOver = (e) => {
  109. e.preventDefault();
  110. dragged = true;
  111. };
  112. const onDragLeave = () => {
  113. dragged = false;
  114. };
  115. const onDrop = async (e) => {
  116. e.preventDefault();
  117. console.log(e);
  118. if (e.dataTransfer?.files) {
  119. let reader = new FileReader();
  120. reader.onload = (event) => {
  121. files = [
  122. ...files,
  123. {
  124. type: 'image',
  125. url: `${event.target.result}`
  126. }
  127. ];
  128. };
  129. const inputFiles = e.dataTransfer?.files;
  130. if (inputFiles && inputFiles.length > 0) {
  131. const file = inputFiles[0];
  132. console.log(file, file.name.split('.').at(-1));
  133. if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
  134. reader.readAsDataURL(file);
  135. } else if (
  136. SUPPORTED_FILE_TYPE.includes(file['type']) ||
  137. ['md'].includes(file.name.split('.').at(-1))
  138. ) {
  139. uploadDoc(file);
  140. } else {
  141. toast.error(`Unsupported File Type '${file['type']}'.`);
  142. }
  143. } else {
  144. toast.error(`File not found.`);
  145. }
  146. }
  147. dragged = false;
  148. };
  149. dropZone?.addEventListener('dragover', onDragOver);
  150. dropZone?.addEventListener('drop', onDrop);
  151. dropZone?.addEventListener('dragleave', onDragLeave);
  152. return () => {
  153. dropZone?.removeEventListener('dragover', onDragOver);
  154. dropZone?.removeEventListener('drop', onDrop);
  155. dropZone?.removeEventListener('dragleave', onDragLeave);
  156. };
  157. });
  158. </script>
  159. {#if dragged}
  160. <div
  161. class="fixed w-full h-full flex z-50 touch-none pointer-events-none"
  162. id="dropzone"
  163. role="region"
  164. aria-label="Drag and Drop Container"
  165. >
  166. <div class="absolute rounded-xl w-full h-full backdrop-blur bg-gray-800/40 flex justify-center">
  167. <div class="m-auto pt-64 flex flex-col justify-center">
  168. <div class="max-w-md">
  169. <AddFilesPlaceholder />
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. {/if}
  175. <div class="fixed bottom-0 w-full">
  176. <div class="px-2.5 pt-2.5 -mb-0.5 mx-auto inset-x-0 bg-transparent flex justify-center">
  177. <div class="flex flex-col max-w-3xl w-full">
  178. <div>
  179. {#if autoScroll === false && messages.length > 0}
  180. <div class=" flex justify-center mb-4">
  181. <button
  182. class=" bg-white border border-gray-100 dark:border-none dark:bg-white/20 p-1.5 rounded-full"
  183. on:click={() => {
  184. autoScroll = true;
  185. window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
  186. }}
  187. >
  188. <svg
  189. xmlns="http://www.w3.org/2000/svg"
  190. viewBox="0 0 20 20"
  191. fill="currentColor"
  192. class="w-5 h-5"
  193. >
  194. <path
  195. fill-rule="evenodd"
  196. d="M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z"
  197. clip-rule="evenodd"
  198. />
  199. </svg>
  200. </button>
  201. </div>
  202. {/if}
  203. </div>
  204. <div class="w-full">
  205. {#if prompt.charAt(0) === '/'}
  206. <Prompts bind:this={promptsElement} bind:prompt />
  207. {:else if prompt.charAt(0) === '#'}
  208. <Documents
  209. bind:this={documentsElement}
  210. bind:prompt
  211. on:select={(e) => {
  212. console.log(e);
  213. files = [
  214. ...files,
  215. {
  216. type: 'doc',
  217. ...e.detail,
  218. upload_status: true
  219. }
  220. ];
  221. }}
  222. />
  223. {:else if prompt.charAt(0) === '@'}
  224. <Models
  225. bind:this={modelsElement}
  226. bind:prompt
  227. bind:user
  228. bind:chatInputPlaceholder
  229. {messages}
  230. />
  231. {:else if messages.length == 0 && suggestionPrompts.length !== 0}
  232. <Suggestions {suggestionPrompts} {submitPrompt} />
  233. {/if}
  234. </div>
  235. </div>
  236. </div>
  237. <div class="bg-white dark:bg-gray-800">
  238. <div class="max-w-3xl px-2.5 -mb-0.5 mx-auto inset-x-0">
  239. <div class="bg-gradient-to-t from-white dark:from-gray-800 from-40% pb-2">
  240. <input
  241. bind:this={filesInputElement}
  242. bind:files={inputFiles}
  243. type="file"
  244. hidden
  245. on:change={async () => {
  246. let reader = new FileReader();
  247. reader.onload = (event) => {
  248. files = [
  249. ...files,
  250. {
  251. type: 'image',
  252. url: `${event.target.result}`
  253. }
  254. ];
  255. inputFiles = null;
  256. filesInputElement.value = '';
  257. };
  258. if (inputFiles && inputFiles.length > 0) {
  259. const file = inputFiles[0];
  260. if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
  261. reader.readAsDataURL(file);
  262. } else if (
  263. SUPPORTED_FILE_TYPE.includes(file['type']) ||
  264. ['md'].includes(file.name.split('.').at(-1))
  265. ) {
  266. uploadDoc(file);
  267. filesInputElement.value = '';
  268. } else {
  269. toast.error(`Unsupported File Type '${file['type']}'.`);
  270. inputFiles = null;
  271. }
  272. } else {
  273. toast.error(`File not found.`);
  274. }
  275. }}
  276. />
  277. <form
  278. class=" flex flex-col relative w-full rounded-xl border dark:border-gray-600 bg-white dark:bg-gray-800 dark:text-gray-100"
  279. on:submit|preventDefault={() => {
  280. submitPrompt(prompt, user);
  281. }}
  282. >
  283. {#if files.length > 0}
  284. <div class="mx-2 mt-2 mb-1 flex flex-wrap gap-2">
  285. {#each files as file, fileIdx}
  286. <div class=" relative group">
  287. {#if file.type === 'image'}
  288. <img src={file.url} alt="input" class=" h-16 w-16 rounded-xl object-cover" />
  289. {:else if file.type === 'doc'}
  290. <div
  291. class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none"
  292. >
  293. <div class="p-2.5 bg-red-400 text-white rounded-lg">
  294. {#if file.upload_status}
  295. <svg
  296. xmlns="http://www.w3.org/2000/svg"
  297. viewBox="0 0 24 24"
  298. fill="currentColor"
  299. class="w-6 h-6"
  300. >
  301. <path
  302. fill-rule="evenodd"
  303. d="M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z"
  304. clip-rule="evenodd"
  305. />
  306. <path
  307. d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"
  308. />
  309. </svg>
  310. {:else}
  311. <svg
  312. class=" w-6 h-6 translate-y-[0.5px]"
  313. fill="currentColor"
  314. viewBox="0 0 24 24"
  315. xmlns="http://www.w3.org/2000/svg"
  316. ><style>
  317. .spinner_qM83 {
  318. animation: spinner_8HQG 1.05s infinite;
  319. }
  320. .spinner_oXPr {
  321. animation-delay: 0.1s;
  322. }
  323. .spinner_ZTLf {
  324. animation-delay: 0.2s;
  325. }
  326. @keyframes spinner_8HQG {
  327. 0%,
  328. 57.14% {
  329. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  330. transform: translate(0);
  331. }
  332. 28.57% {
  333. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  334. transform: translateY(-6px);
  335. }
  336. 100% {
  337. transform: translate(0);
  338. }
  339. }
  340. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  341. class="spinner_qM83 spinner_oXPr"
  342. cx="12"
  343. cy="12"
  344. r="2.5"
  345. /><circle
  346. class="spinner_qM83 spinner_ZTLf"
  347. cx="20"
  348. cy="12"
  349. r="2.5"
  350. /></svg
  351. >
  352. {/if}
  353. </div>
  354. <div class="flex flex-col justify-center -space-y-0.5">
  355. <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
  356. {file.name}
  357. </div>
  358. <div class=" text-gray-500 text-sm">Document</div>
  359. </div>
  360. </div>
  361. {/if}
  362. <div class=" absolute -top-1 -right-1">
  363. <button
  364. class=" bg-gray-400 text-white border border-white rounded-full group-hover:visible invisible transition"
  365. type="button"
  366. on:click={() => {
  367. files.splice(fileIdx, 1);
  368. files = files;
  369. }}
  370. >
  371. <svg
  372. xmlns="http://www.w3.org/2000/svg"
  373. viewBox="0 0 20 20"
  374. fill="currentColor"
  375. class="w-4 h-4"
  376. >
  377. <path
  378. 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"
  379. />
  380. </svg>
  381. </button>
  382. </div>
  383. </div>
  384. {/each}
  385. </div>
  386. {/if}
  387. <div class=" flex">
  388. {#if fileUploadEnabled}
  389. <div class=" self-end mb-2 ml-1.5">
  390. <button
  391. class=" text-gray-600 dark:text-gray-200 transition rounded-lg p-1 ml-1"
  392. type="button"
  393. on:click={() => {
  394. filesInputElement.click();
  395. }}
  396. >
  397. <svg
  398. xmlns="http://www.w3.org/2000/svg"
  399. viewBox="0 0 20 20"
  400. fill="currentColor"
  401. class="w-5 h-5"
  402. >
  403. <path
  404. fill-rule="evenodd"
  405. d="M15.621 4.379a3 3 0 00-4.242 0l-7 7a3 3 0 004.241 4.243h.001l.497-.5a.75.75 0 011.064 1.057l-.498.501-.002.002a4.5 4.5 0 01-6.364-6.364l7-7a4.5 4.5 0 016.368 6.36l-3.455 3.553A2.625 2.625 0 119.52 9.52l3.45-3.451a.75.75 0 111.061 1.06l-3.45 3.451a1.125 1.125 0 001.587 1.595l3.454-3.553a3 3 0 000-4.242z"
  406. clip-rule="evenodd"
  407. />
  408. </svg>
  409. </button>
  410. </div>
  411. {/if}
  412. <textarea
  413. id="chat-textarea"
  414. class=" dark:bg-gray-800 dark:text-gray-100 outline-none w-full py-3 px-2 {fileUploadEnabled
  415. ? ''
  416. : ' pl-4'} rounded-xl resize-none h-[48px]"
  417. placeholder={chatInputPlaceholder !== ''
  418. ? chatInputPlaceholder
  419. : speechRecognitionListening
  420. ? 'Listening...'
  421. : 'Send a message'}
  422. bind:value={prompt}
  423. on:keypress={(e) => {
  424. if (e.keyCode == 13 && !e.shiftKey) {
  425. e.preventDefault();
  426. }
  427. if (prompt !== '' && e.keyCode == 13 && !e.shiftKey) {
  428. submitPrompt(prompt, user);
  429. }
  430. }}
  431. on:keydown={async (e) => {
  432. const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
  433. // Check if Ctrl + R is pressed
  434. if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') {
  435. e.preventDefault();
  436. console.log('regenerate');
  437. const regenerateButton = [
  438. ...document.getElementsByClassName('regenerate-response-button')
  439. ]?.at(-1);
  440. regenerateButton?.click();
  441. }
  442. if (prompt === '' && e.key == 'ArrowUp') {
  443. e.preventDefault();
  444. const userMessageElement = [
  445. ...document.getElementsByClassName('user-message')
  446. ]?.at(-1);
  447. const editButton = [
  448. ...document.getElementsByClassName('edit-user-message-button')
  449. ]?.at(-1);
  450. console.log(userMessageElement);
  451. userMessageElement.scrollIntoView({ block: 'center' });
  452. editButton?.click();
  453. }
  454. if (['/', '#', '@'].includes(prompt.charAt(0)) && e.key === 'ArrowUp') {
  455. e.preventDefault();
  456. (promptsElement || documentsElement || modelsElement).selectUp();
  457. const commandOptionButton = [
  458. ...document.getElementsByClassName('selected-command-option-button')
  459. ]?.at(-1);
  460. commandOptionButton.scrollIntoView({ block: 'center' });
  461. }
  462. if (['/', '#', '@'].includes(prompt.charAt(0)) && e.key === 'ArrowDown') {
  463. e.preventDefault();
  464. (promptsElement || documentsElement || modelsElement).selectDown();
  465. const commandOptionButton = [
  466. ...document.getElementsByClassName('selected-command-option-button')
  467. ]?.at(-1);
  468. commandOptionButton.scrollIntoView({ block: 'center' });
  469. }
  470. if (['/', '#', '@'].includes(prompt.charAt(0)) && e.key === 'Enter') {
  471. e.preventDefault();
  472. const commandOptionButton = [
  473. ...document.getElementsByClassName('selected-command-option-button')
  474. ]?.at(-1);
  475. commandOptionButton?.click();
  476. }
  477. if (['/', '#', '@'].includes(prompt.charAt(0)) && e.key === 'Tab') {
  478. e.preventDefault();
  479. const commandOptionButton = [
  480. ...document.getElementsByClassName('selected-command-option-button')
  481. ]?.at(-1);
  482. commandOptionButton?.click();
  483. } else if (e.key === 'Tab') {
  484. const words = findWordIndices(prompt);
  485. if (words.length > 0) {
  486. const word = words.at(0);
  487. const fullPrompt = prompt;
  488. prompt = prompt.substring(0, word?.endIndex + 1);
  489. await tick();
  490. e.target.scrollTop = e.target.scrollHeight;
  491. prompt = fullPrompt;
  492. await tick();
  493. e.preventDefault();
  494. e.target.setSelectionRange(word?.startIndex, word.endIndex + 1);
  495. }
  496. }
  497. }}
  498. rows="1"
  499. on:input={(e) => {
  500. e.target.style.height = '';
  501. e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px';
  502. user = null;
  503. }}
  504. on:paste={(e) => {
  505. const clipboardData = e.clipboardData || window.clipboardData;
  506. if (clipboardData && clipboardData.items) {
  507. for (const item of clipboardData.items) {
  508. if (item.type.indexOf('image') !== -1) {
  509. const blob = item.getAsFile();
  510. const reader = new FileReader();
  511. reader.onload = function (e) {
  512. files = [
  513. ...files,
  514. {
  515. type: 'image',
  516. url: `${e.target.result}`
  517. }
  518. ];
  519. };
  520. reader.readAsDataURL(blob);
  521. }
  522. }
  523. }
  524. }}
  525. />
  526. <div class="self-end mb-2 flex space-x-0.5 mr-2">
  527. {#if messages.length == 0 || messages.at(-1).done == true}
  528. {#if speechRecognitionEnabled}
  529. <button
  530. class=" text-gray-600 dark:text-gray-300 transition rounded-lg p-1.5 mr-0.5 self-center"
  531. type="button"
  532. on:click={() => {
  533. speechRecognitionHandler();
  534. }}
  535. >
  536. {#if speechRecognitionListening}
  537. <svg
  538. class=" w-5 h-5 translate-y-[0.5px]"
  539. fill="currentColor"
  540. viewBox="0 0 24 24"
  541. xmlns="http://www.w3.org/2000/svg"
  542. ><style>
  543. .spinner_qM83 {
  544. animation: spinner_8HQG 1.05s infinite;
  545. }
  546. .spinner_oXPr {
  547. animation-delay: 0.1s;
  548. }
  549. .spinner_ZTLf {
  550. animation-delay: 0.2s;
  551. }
  552. @keyframes spinner_8HQG {
  553. 0%,
  554. 57.14% {
  555. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  556. transform: translate(0);
  557. }
  558. 28.57% {
  559. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  560. transform: translateY(-6px);
  561. }
  562. 100% {
  563. transform: translate(0);
  564. }
  565. }
  566. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  567. class="spinner_qM83 spinner_oXPr"
  568. cx="12"
  569. cy="12"
  570. r="2.5"
  571. /><circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="2.5" /></svg
  572. >
  573. {:else}
  574. <svg
  575. xmlns="http://www.w3.org/2000/svg"
  576. viewBox="0 0 20 20"
  577. fill="currentColor"
  578. class="w-5 h-5 translate-y-[0.5px]"
  579. >
  580. <path d="M7 4a3 3 0 016 0v6a3 3 0 11-6 0V4z" />
  581. <path
  582. d="M5.5 9.643a.75.75 0 00-1.5 0V10c0 3.06 2.29 5.585 5.25 5.954V17.5h-1.5a.75.75 0 000 1.5h4.5a.75.75 0 000-1.5h-1.5v-1.546A6.001 6.001 0 0016 10v-.357a.75.75 0 00-1.5 0V10a4.5 4.5 0 01-9 0v-.357z"
  583. />
  584. </svg>
  585. {/if}
  586. </button>
  587. {/if}
  588. <button
  589. class="{prompt !== ''
  590. ? 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100 '
  591. : 'text-white bg-gray-100 dark:text-gray-800 dark:bg-gray-600 disabled'} transition rounded-lg p-1 mr-0.5 w-7 h-7 self-center"
  592. type="submit"
  593. disabled={prompt === ''}
  594. >
  595. <svg
  596. xmlns="http://www.w3.org/2000/svg"
  597. viewBox="0 0 20 20"
  598. fill="currentColor"
  599. class="w-5 h-5"
  600. >
  601. <path
  602. fill-rule="evenodd"
  603. d="M10 17a.75.75 0 01-.75-.75V5.612L5.29 9.77a.75.75 0 01-1.08-1.04l5.25-5.5a.75.75 0 011.08 0l5.25 5.5a.75.75 0 11-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0110 17z"
  604. clip-rule="evenodd"
  605. />
  606. </svg>
  607. </button>
  608. {:else}
  609. <button
  610. class="bg-white hover:bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-800 transition rounded-lg p-1.5"
  611. on:click={stopResponse}
  612. >
  613. <svg
  614. xmlns="http://www.w3.org/2000/svg"
  615. viewBox="0 0 24 24"
  616. fill="currentColor"
  617. class="w-5 h-5"
  618. >
  619. <path
  620. fill-rule="evenodd"
  621. d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm6-2.438c0-.724.588-1.312 1.313-1.312h4.874c.725 0 1.313.588 1.313 1.313v4.874c0 .725-.588 1.313-1.313 1.313H9.564a1.312 1.312 0 01-1.313-1.313V9.564z"
  622. clip-rule="evenodd"
  623. />
  624. </svg>
  625. </button>
  626. {/if}
  627. </div>
  628. </div>
  629. </form>
  630. <div class="mt-1.5 text-xs text-gray-500 text-center">
  631. LLMs can make mistakes. Verify important information.
  632. </div>
  633. </div>
  634. </div>
  635. </div>
  636. </div>