ResponseMessage.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <script lang="ts">
  2. import toast from 'svelte-french-toast';
  3. import dayjs from 'dayjs';
  4. import { marked } from 'marked';
  5. import { settings } from '$lib/stores';
  6. import tippy from 'tippy.js';
  7. import auto_render from 'katex/dist/contrib/auto-render.mjs';
  8. import 'katex/dist/katex.min.css';
  9. import { onMount, tick } from 'svelte';
  10. import Name from './Name.svelte';
  11. import ProfileImage from './ProfileImage.svelte';
  12. import Skeleton from './Skeleton.svelte';
  13. import CodeBlock from './CodeBlock.svelte';
  14. import { synthesizeOpenAISpeech } from '$lib/apis/openai';
  15. import { extractSentences } from '$lib/utils';
  16. export let modelfiles = [];
  17. export let message;
  18. export let siblings;
  19. export let isLastMessage = true;
  20. export let confirmEditResponseMessage: Function;
  21. export let showPreviousMessage: Function;
  22. export let showNextMessage: Function;
  23. export let rateMessage: Function;
  24. export let copyToClipboard: Function;
  25. export let continueGeneration: Function;
  26. export let regenerateResponse: Function;
  27. let edit = false;
  28. let editedContent = '';
  29. let tooltipInstance = null;
  30. let sentencesAudio = {};
  31. let speaking = null;
  32. let speakingIdx = null;
  33. let loadingSpeech = false;
  34. $: tokens = marked.lexer(message.content);
  35. const renderer = new marked.Renderer();
  36. // For code blocks with simple backticks
  37. renderer.codespan = (code) => {
  38. return `<code>${code.replaceAll('&amp;', '&')}</code>`;
  39. };
  40. const { extensions, ...defaults } = marked.getDefaults() as marked.MarkedOptions & {
  41. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  42. extensions: any;
  43. };
  44. $: if (message) {
  45. renderStyling();
  46. }
  47. const renderStyling = async () => {
  48. await tick();
  49. if (tooltipInstance) {
  50. tooltipInstance[0].destroy();
  51. }
  52. renderLatex();
  53. if (message.info) {
  54. tooltipInstance = tippy(`#info-${message.id}`, {
  55. content: `<span class="text-xs" id="tooltip-${message.id}">token/s: ${
  56. `${
  57. Math.round(
  58. ((message.info.eval_count ?? 0) / (message.info.eval_duration / 1000000000)) * 100
  59. ) / 100
  60. } tokens` ?? 'N/A'
  61. }<br/>
  62. total_duration: ${
  63. Math.round(((message.info.total_duration ?? 0) / 1000000) * 100) / 100 ??
  64. 'N/A'
  65. }ms<br/>
  66. load_duration: ${
  67. Math.round(((message.info.load_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  68. }ms<br/>
  69. prompt_eval_count: ${message.info.prompt_eval_count ?? 'N/A'}<br/>
  70. prompt_eval_duration: ${
  71. Math.round(((message.info.prompt_eval_duration ?? 0) / 1000000) * 100) /
  72. 100 ?? 'N/A'
  73. }ms<br/>
  74. eval_count: ${message.info.eval_count ?? 'N/A'}<br/>
  75. eval_duration: ${
  76. Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  77. }ms</span>`,
  78. allowHTML: true
  79. });
  80. }
  81. };
  82. const renderLatex = () => {
  83. let chatMessageElements = document.getElementsByClassName('chat-assistant');
  84. // let lastChatMessageElement = chatMessageElements[chatMessageElements.length - 1];
  85. for (const element of chatMessageElements) {
  86. auto_render(element, {
  87. // customised options
  88. // • auto-render specific keys, e.g.:
  89. delimiters: [
  90. { left: '$$', right: '$$', display: true },
  91. // { left: '$', right: '$', display: false },
  92. { left: '\\(', right: '\\)', display: true },
  93. { left: '\\[', right: '\\]', display: true }
  94. ],
  95. // • rendering keys, e.g.:
  96. throwOnError: false
  97. });
  98. }
  99. };
  100. const playAudio = (idx) => {
  101. return new Promise((res) => {
  102. speakingIdx = idx;
  103. const audio = sentencesAudio[idx];
  104. audio.play();
  105. audio.onended = async (e) => {
  106. await new Promise((r) => setTimeout(r, 300));
  107. if (Object.keys(sentencesAudio).length - 1 === idx) {
  108. speaking = null;
  109. if ($settings.conversationMode) {
  110. document.getElementById('voice-input-button')?.click();
  111. }
  112. }
  113. res(e);
  114. };
  115. });
  116. };
  117. const toggleSpeakMessage = async () => {
  118. if (speaking) {
  119. speechSynthesis.cancel();
  120. sentencesAudio[speakingIdx].pause();
  121. sentencesAudio[speakingIdx].currentTime = 0;
  122. speaking = null;
  123. speakingIdx = null;
  124. } else {
  125. speaking = true;
  126. if ($settings?.audio?.TTSEngine === 'openai') {
  127. loadingSpeech = true;
  128. const sentences = extractSentences(message.content).reduce((mergedTexts, currentText) => {
  129. const lastIndex = mergedTexts.length - 1;
  130. if (lastIndex >= 0) {
  131. const previousText = mergedTexts[lastIndex];
  132. const wordCount = previousText.split(/\s+/).length;
  133. if (wordCount < 2) {
  134. mergedTexts[lastIndex] = previousText + ' ' + currentText;
  135. } else {
  136. mergedTexts.push(currentText);
  137. }
  138. } else {
  139. mergedTexts.push(currentText);
  140. }
  141. return mergedTexts;
  142. }, []);
  143. console.log(sentences);
  144. sentencesAudio = sentences.reduce((a, e, i, arr) => {
  145. a[i] = null;
  146. return a;
  147. }, {});
  148. let lastPlayedAudioPromise = Promise.resolve(); // Initialize a promise that resolves immediately
  149. for (const [idx, sentence] of sentences.entries()) {
  150. const res = await synthesizeOpenAISpeech(
  151. localStorage.token,
  152. $settings?.audio?.speaker,
  153. sentence
  154. ).catch((error) => {
  155. toast.error(error);
  156. return null;
  157. });
  158. if (res) {
  159. const blob = await res.blob();
  160. const blobUrl = URL.createObjectURL(blob);
  161. const audio = new Audio(blobUrl);
  162. sentencesAudio[idx] = audio;
  163. loadingSpeech = false;
  164. lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
  165. }
  166. }
  167. } else {
  168. let voices = [];
  169. const getVoicesLoop = setInterval(async () => {
  170. voices = await speechSynthesis.getVoices();
  171. if (voices.length > 0) {
  172. clearInterval(getVoicesLoop);
  173. const voice =
  174. voices?.filter((v) => v.name === $settings?.audio?.speaker)?.at(0) ?? undefined;
  175. const speak = new SpeechSynthesisUtterance(message.content);
  176. speak.onend = () => {
  177. speaking = null;
  178. if ($settings.conversationMode) {
  179. document.getElementById('voice-input-button')?.click();
  180. }
  181. };
  182. speak.voice = voice;
  183. speechSynthesis.speak(speak);
  184. }
  185. }, 100);
  186. }
  187. }
  188. };
  189. const editMessageHandler = async () => {
  190. edit = true;
  191. editedContent = message.content;
  192. await tick();
  193. const editElement = document.getElementById(`message-edit-${message.id}`);
  194. editElement.style.height = '';
  195. editElement.style.height = `${editElement.scrollHeight}px`;
  196. };
  197. const editMessageConfirmHandler = async () => {
  198. confirmEditResponseMessage(message.id, editedContent);
  199. edit = false;
  200. editedContent = '';
  201. await tick();
  202. renderStyling();
  203. };
  204. const cancelEditMessage = async () => {
  205. edit = false;
  206. editedContent = '';
  207. await tick();
  208. renderStyling();
  209. };
  210. onMount(async () => {
  211. await tick();
  212. renderStyling();
  213. });
  214. </script>
  215. {#key message.id}
  216. <div class=" flex w-full message-{message.id}">
  217. <ProfileImage src={modelfiles[message.model]?.imageUrl ?? '/favicon.png'} />
  218. <div class="w-full overflow-hidden">
  219. <Name>
  220. {#if message.model in modelfiles}
  221. {modelfiles[message.model]?.title}
  222. {:else}
  223. {message.model ? ` ${message.model}` : ''}
  224. {/if}
  225. {#if message.timestamp}
  226. <span class=" invisible group-hover:visible text-gray-400 text-xs font-medium">
  227. {dayjs(message.timestamp * 1000).format('DD/MM/YYYY HH:mm')}
  228. </span>
  229. {/if}
  230. </Name>
  231. {#if message.content === ''}
  232. <Skeleton />
  233. {:else}
  234. <div
  235. class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-headings:my-0 prose-p:my-0 prose-p:-mb-4 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-img:my-0 prose-ul:-my-4 prose-ol:-my-4 prose-li:-my-3 prose-ul:-mb-6 prose-ol:-mb-6 prose-li:-mb-4 whitespace-pre-line"
  236. >
  237. <div>
  238. {#if edit === true}
  239. <div class=" w-full">
  240. <textarea
  241. id="message-edit-{message.id}"
  242. class=" bg-transparent outline-none w-full resize-none"
  243. bind:value={editedContent}
  244. on:input={(e) => {
  245. e.target.style.height = `${e.target.scrollHeight}px`;
  246. }}
  247. />
  248. <div class=" mt-2 mb-1 flex justify-center space-x-2 text-sm font-medium">
  249. <button
  250. class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded-lg"
  251. on:click={() => {
  252. editMessageConfirmHandler();
  253. }}
  254. >
  255. Save
  256. </button>
  257. <button
  258. class=" px-4 py-2 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-100 transition outline outline-1 outline-gray-200 dark:outline-gray-600 rounded-lg"
  259. on:click={() => {
  260. cancelEditMessage();
  261. }}
  262. >
  263. Cancel
  264. </button>
  265. </div>
  266. </div>
  267. {:else}
  268. <div class="w-full">
  269. {#if message?.error === true}
  270. <div
  271. class="flex mt-2 mb-4 space-x-2 border px-4 py-3 border-red-800 bg-red-800/30 font-medium rounded-lg"
  272. >
  273. <svg
  274. xmlns="http://www.w3.org/2000/svg"
  275. fill="none"
  276. viewBox="0 0 24 24"
  277. stroke-width="1.5"
  278. stroke="currentColor"
  279. class="w-5 h-5 self-center"
  280. >
  281. <path
  282. stroke-linecap="round"
  283. stroke-linejoin="round"
  284. d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
  285. />
  286. </svg>
  287. <div class=" self-center">
  288. {message.content}
  289. </div>
  290. </div>
  291. {:else}
  292. {#each tokens as token}
  293. {#if token.type === 'code'}
  294. <!-- {token.text} -->
  295. <CodeBlock lang={token.lang} code={token.text} />
  296. {:else}
  297. {@html marked.parse(token.raw, {
  298. ...defaults,
  299. gfm: true,
  300. breaks: true,
  301. renderer
  302. })}
  303. {/if}
  304. {/each}
  305. <!-- {@html marked(message.content.replaceAll('\\', '\\\\'))} -->
  306. {/if}
  307. {#if message.done}
  308. <div class=" flex justify-start space-x-1 -mt-2 overflow-x-auto buttons">
  309. {#if siblings.length > 1}
  310. <div class="flex self-center">
  311. <button
  312. class="self-center"
  313. on:click={() => {
  314. showPreviousMessage(message);
  315. }}
  316. >
  317. <svg
  318. xmlns="http://www.w3.org/2000/svg"
  319. viewBox="0 0 20 20"
  320. fill="currentColor"
  321. class="w-4 h-4"
  322. >
  323. <path
  324. fill-rule="evenodd"
  325. d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z"
  326. clip-rule="evenodd"
  327. />
  328. </svg>
  329. </button>
  330. <div class="text-xs font-bold self-center">
  331. {siblings.indexOf(message.id) + 1} / {siblings.length}
  332. </div>
  333. <button
  334. class="self-center"
  335. on:click={() => {
  336. showNextMessage(message);
  337. }}
  338. >
  339. <svg
  340. xmlns="http://www.w3.org/2000/svg"
  341. viewBox="0 0 20 20"
  342. fill="currentColor"
  343. class="w-4 h-4"
  344. >
  345. <path
  346. fill-rule="evenodd"
  347. d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z"
  348. clip-rule="evenodd"
  349. />
  350. </svg>
  351. </button>
  352. </div>
  353. {/if}
  354. <button
  355. class="{isLastMessage
  356. ? 'visible'
  357. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition"
  358. on:click={() => {
  359. editMessageHandler();
  360. }}
  361. >
  362. <svg
  363. xmlns="http://www.w3.org/2000/svg"
  364. fill="none"
  365. viewBox="0 0 24 24"
  366. stroke-width="1.5"
  367. stroke="currentColor"
  368. class="w-4 h-4"
  369. >
  370. <path
  371. stroke-linecap="round"
  372. stroke-linejoin="round"
  373. d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
  374. />
  375. </svg>
  376. </button>
  377. <button
  378. class="{isLastMessage
  379. ? 'visible'
  380. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition copy-response-button"
  381. on:click={() => {
  382. copyToClipboard(message.content);
  383. }}
  384. >
  385. <svg
  386. xmlns="http://www.w3.org/2000/svg"
  387. fill="none"
  388. viewBox="0 0 24 24"
  389. stroke-width="1.5"
  390. stroke="currentColor"
  391. class="w-4 h-4"
  392. >
  393. <path
  394. stroke-linecap="round"
  395. stroke-linejoin="round"
  396. d="M15.666 3.888A2.25 2.25 0 0013.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 01-.75.75H9a.75.75 0 01-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 01-2.25 2.25H6.75A2.25 2.25 0 014.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 011.927-.184"
  397. />
  398. </svg>
  399. </button>
  400. <button
  401. class="{isLastMessage
  402. ? 'visible'
  403. : 'invisible group-hover:visible'} p-1 rounded {message.rating === 1
  404. ? 'bg-gray-100 dark:bg-gray-800'
  405. : ''} transition"
  406. on:click={() => {
  407. rateMessage(message.id, 1);
  408. }}
  409. >
  410. <svg
  411. stroke="currentColor"
  412. fill="none"
  413. stroke-width="2"
  414. viewBox="0 0 24 24"
  415. stroke-linecap="round"
  416. stroke-linejoin="round"
  417. class="w-4 h-4"
  418. xmlns="http://www.w3.org/2000/svg"
  419. ><path
  420. d="M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3"
  421. /></svg
  422. >
  423. </button>
  424. <button
  425. class="{isLastMessage
  426. ? 'visible'
  427. : 'invisible group-hover:visible'} p-1 rounded {message.rating === -1
  428. ? 'bg-gray-100 dark:bg-gray-800'
  429. : ''} transition"
  430. on:click={() => {
  431. rateMessage(message.id, -1);
  432. }}
  433. >
  434. <svg
  435. stroke="currentColor"
  436. fill="none"
  437. stroke-width="2"
  438. viewBox="0 0 24 24"
  439. stroke-linecap="round"
  440. stroke-linejoin="round"
  441. class="w-4 h-4"
  442. xmlns="http://www.w3.org/2000/svg"
  443. ><path
  444. d="M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17"
  445. /></svg
  446. >
  447. </button>
  448. <button
  449. id="speak-button-{message.id}"
  450. class="{isLastMessage
  451. ? 'visible'
  452. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition"
  453. on:click={() => {
  454. if (!loadingSpeech) {
  455. toggleSpeakMessage(message);
  456. }
  457. }}
  458. >
  459. {#if loadingSpeech}
  460. <svg
  461. class=" w-4 h-4"
  462. fill="currentColor"
  463. viewBox="0 0 24 24"
  464. xmlns="http://www.w3.org/2000/svg"
  465. ><style>
  466. .spinner_S1WN {
  467. animation: spinner_MGfb 0.8s linear infinite;
  468. animation-delay: -0.8s;
  469. }
  470. .spinner_Km9P {
  471. animation-delay: -0.65s;
  472. }
  473. .spinner_JApP {
  474. animation-delay: -0.5s;
  475. }
  476. @keyframes spinner_MGfb {
  477. 93.75%,
  478. 100% {
  479. opacity: 0.2;
  480. }
  481. }
  482. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  483. class="spinner_S1WN spinner_Km9P"
  484. cx="12"
  485. cy="12"
  486. r="3"
  487. /><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
  488. >
  489. {:else if speaking}
  490. <svg
  491. xmlns="http://www.w3.org/2000/svg"
  492. fill="none"
  493. viewBox="0 0 24 24"
  494. stroke-width="1.5"
  495. stroke="currentColor"
  496. class="w-4 h-4"
  497. >
  498. <path
  499. stroke-linecap="round"
  500. stroke-linejoin="round"
  501. d="M17.25 9.75 19.5 12m0 0 2.25 2.25M19.5 12l2.25-2.25M19.5 12l-2.25 2.25m-10.5-6 4.72-4.72a.75.75 0 0 1 1.28.53v15.88a.75.75 0 0 1-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.009 9.009 0 0 1 2.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75Z"
  502. />
  503. </svg>
  504. {:else}
  505. <svg
  506. xmlns="http://www.w3.org/2000/svg"
  507. fill="none"
  508. viewBox="0 0 24 24"
  509. stroke-width="1.5"
  510. stroke="currentColor"
  511. class="w-4 h-4"
  512. >
  513. <path
  514. stroke-linecap="round"
  515. stroke-linejoin="round"
  516. d="M19.114 5.636a9 9 0 010 12.728M16.463 8.288a5.25 5.25 0 010 7.424M6.75 8.25l4.72-4.72a.75.75 0 011.28.53v15.88a.75.75 0 01-1.28.53l-4.72-4.72H4.51c-.88 0-1.704-.507-1.938-1.354A9.01 9.01 0 012.25 12c0-.83.112-1.633.322-2.396C2.806 8.756 3.63 8.25 4.51 8.25H6.75z"
  517. />
  518. </svg>
  519. {/if}
  520. </button>
  521. {#if message.info}
  522. <button
  523. class=" {isLastMessage
  524. ? 'visible'
  525. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition whitespace-pre-wrap"
  526. on:click={() => {
  527. console.log(message);
  528. }}
  529. id="info-{message.id}"
  530. >
  531. <svg
  532. xmlns="http://www.w3.org/2000/svg"
  533. fill="none"
  534. viewBox="0 0 24 24"
  535. stroke-width="1.5"
  536. stroke="currentColor"
  537. class="w-4 h-4"
  538. >
  539. <path
  540. stroke-linecap="round"
  541. stroke-linejoin="round"
  542. d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
  543. />
  544. </svg>
  545. </button>
  546. {/if}
  547. {#if isLastMessage}
  548. <button
  549. type="button"
  550. class="{isLastMessage
  551. ? 'visible'
  552. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition regenerate-response-button"
  553. on:click={() => {
  554. continueGeneration();
  555. }}
  556. >
  557. <svg
  558. xmlns="http://www.w3.org/2000/svg"
  559. fill="none"
  560. viewBox="0 0 24 24"
  561. stroke-width="1.5"
  562. stroke="currentColor"
  563. class="w-4 h-4"
  564. >
  565. <path
  566. stroke-linecap="round"
  567. stroke-linejoin="round"
  568. d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
  569. />
  570. <path
  571. stroke-linecap="round"
  572. stroke-linejoin="round"
  573. d="M15.91 11.672a.375.375 0 0 1 0 .656l-5.603 3.113a.375.375 0 0 1-.557-.328V8.887c0-.286.307-.466.557-.327l5.603 3.112Z"
  574. />
  575. </svg>
  576. </button>
  577. <button
  578. type="button"
  579. class="{isLastMessage
  580. ? 'visible'
  581. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white transition regenerate-response-button"
  582. on:click={regenerateResponse}
  583. >
  584. <svg
  585. xmlns="http://www.w3.org/2000/svg"
  586. fill="none"
  587. viewBox="0 0 24 24"
  588. stroke-width="1.5"
  589. stroke="currentColor"
  590. class="w-4 h-4"
  591. >
  592. <path
  593. stroke-linecap="round"
  594. stroke-linejoin="round"
  595. d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99"
  596. />
  597. </svg>
  598. </button>
  599. {/if}
  600. </div>
  601. {/if}
  602. </div>
  603. {/if}
  604. </div>
  605. </div>
  606. {/if}
  607. </div>
  608. </div>
  609. {/key}
  610. <style>
  611. .buttons::-webkit-scrollbar {
  612. display: none; /* for Chrome, Safari and Opera */
  613. }
  614. .buttons {
  615. -ms-overflow-style: none; /* IE and Edge */
  616. scrollbar-width: none; /* Firefox */
  617. }
  618. </style>