MessageInput.svelte 22 KB

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