MessageInput.svelte 21 KB

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