ResponseMessage.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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}">response_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. prompt_token/s: ${
  63. Math.round(
  64. ((message.info.prompt_eval_count ?? 0) / (message.info.prompt_eval_duration / 1000000000)) * 100
  65. ) / 100 ?? 'N/A'
  66. } tokens<br/>
  67. total_duration: ${
  68. Math.round(((message.info.total_duration ?? 0) / 1000000) * 100) / 100 ??
  69. 'N/A'
  70. }ms<br/>
  71. load_duration: ${
  72. Math.round(((message.info.load_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  73. }ms<br/>
  74. prompt_eval_count: ${message.info.prompt_eval_count ?? 'N/A'}<br/>
  75. prompt_eval_duration: ${
  76. Math.round(((message.info.prompt_eval_duration ?? 0) / 1000000) * 100) /
  77. 100 ?? 'N/A'
  78. }ms<br/>
  79. eval_count: ${message.info.eval_count ?? 'N/A'}<br/>
  80. eval_duration: ${
  81. Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  82. }ms</span>`,
  83. allowHTML: true
  84. });
  85. }
  86. };
  87. const renderLatex = () => {
  88. let chatMessageElements = document.getElementsByClassName('chat-assistant');
  89. // let lastChatMessageElement = chatMessageElements[chatMessageElements.length - 1];
  90. for (const element of chatMessageElements) {
  91. auto_render(element, {
  92. // customised options
  93. // • auto-render specific keys, e.g.:
  94. delimiters: [
  95. { left: '$$', right: '$$', display: true },
  96. // { left: '$', right: '$', display: false },
  97. { left: '\\(', right: '\\)', display: true },
  98. { left: '\\[', right: '\\]', display: true }
  99. ],
  100. // • rendering keys, e.g.:
  101. throwOnError: false
  102. });
  103. }
  104. };
  105. const playAudio = (idx) => {
  106. return new Promise((res) => {
  107. speakingIdx = idx;
  108. const audio = sentencesAudio[idx];
  109. audio.play();
  110. audio.onended = async (e) => {
  111. await new Promise((r) => setTimeout(r, 300));
  112. if (Object.keys(sentencesAudio).length - 1 === idx) {
  113. speaking = null;
  114. if ($settings.conversationMode) {
  115. document.getElementById('voice-input-button')?.click();
  116. }
  117. }
  118. res(e);
  119. };
  120. });
  121. };
  122. const toggleSpeakMessage = async () => {
  123. if (speaking) {
  124. speechSynthesis.cancel();
  125. sentencesAudio[speakingIdx].pause();
  126. sentencesAudio[speakingIdx].currentTime = 0;
  127. speaking = null;
  128. speakingIdx = null;
  129. } else {
  130. speaking = true;
  131. if ($settings?.audio?.TTSEngine === 'openai') {
  132. loadingSpeech = true;
  133. const sentences = extractSentences(message.content).reduce((mergedTexts, currentText) => {
  134. const lastIndex = mergedTexts.length - 1;
  135. if (lastIndex >= 0) {
  136. const previousText = mergedTexts[lastIndex];
  137. const wordCount = previousText.split(/\s+/).length;
  138. if (wordCount < 2) {
  139. mergedTexts[lastIndex] = previousText + ' ' + currentText;
  140. } else {
  141. mergedTexts.push(currentText);
  142. }
  143. } else {
  144. mergedTexts.push(currentText);
  145. }
  146. return mergedTexts;
  147. }, []);
  148. console.log(sentences);
  149. sentencesAudio = sentences.reduce((a, e, i, arr) => {
  150. a[i] = null;
  151. return a;
  152. }, {});
  153. let lastPlayedAudioPromise = Promise.resolve(); // Initialize a promise that resolves immediately
  154. for (const [idx, sentence] of sentences.entries()) {
  155. const res = await synthesizeOpenAISpeech(
  156. localStorage.token,
  157. $settings?.audio?.speaker,
  158. sentence
  159. ).catch((error) => {
  160. toast.error(error);
  161. return null;
  162. });
  163. if (res) {
  164. const blob = await res.blob();
  165. const blobUrl = URL.createObjectURL(blob);
  166. const audio = new Audio(blobUrl);
  167. sentencesAudio[idx] = audio;
  168. loadingSpeech = false;
  169. lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
  170. }
  171. }
  172. } else {
  173. let voices = [];
  174. const getVoicesLoop = setInterval(async () => {
  175. voices = await speechSynthesis.getVoices();
  176. if (voices.length > 0) {
  177. clearInterval(getVoicesLoop);
  178. const voice =
  179. voices?.filter((v) => v.name === $settings?.audio?.speaker)?.at(0) ?? undefined;
  180. const speak = new SpeechSynthesisUtterance(message.content);
  181. speak.onend = () => {
  182. speaking = null;
  183. if ($settings.conversationMode) {
  184. document.getElementById('voice-input-button')?.click();
  185. }
  186. };
  187. speak.voice = voice;
  188. speechSynthesis.speak(speak);
  189. }
  190. }, 100);
  191. }
  192. }
  193. };
  194. const editMessageHandler = async () => {
  195. edit = true;
  196. editedContent = message.content;
  197. await tick();
  198. const editElement = document.getElementById(`message-edit-${message.id}`);
  199. editElement.style.height = '';
  200. editElement.style.height = `${editElement.scrollHeight}px`;
  201. };
  202. const editMessageConfirmHandler = async () => {
  203. if (editedContent === '') {
  204. editedContent = ' ';
  205. }
  206. confirmEditResponseMessage(message.id, editedContent);
  207. edit = false;
  208. editedContent = '';
  209. await tick();
  210. renderStyling();
  211. };
  212. const cancelEditMessage = async () => {
  213. edit = false;
  214. editedContent = '';
  215. await tick();
  216. renderStyling();
  217. };
  218. onMount(async () => {
  219. await tick();
  220. renderStyling();
  221. });
  222. </script>
  223. {#key message.id}
  224. <div class=" flex w-full message-{message.id}">
  225. <ProfileImage src={modelfiles[message.model]?.imageUrl ?? '/favicon.png'} />
  226. <div class="w-full overflow-hidden">
  227. <Name>
  228. {#if message.model in modelfiles}
  229. {modelfiles[message.model]?.title}
  230. {:else}
  231. {message.model ? ` ${message.model}` : ''}
  232. {/if}
  233. {#if message.timestamp}
  234. <span class=" invisible group-hover:visible text-gray-400 text-xs font-medium">
  235. {dayjs(message.timestamp * 1000).format('DD/MM/YYYY HH:mm')}
  236. </span>
  237. {/if}
  238. </Name>
  239. {#if message.content === ''}
  240. <Skeleton />
  241. {:else}
  242. <div
  243. class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-headings:my-0 prose-p:m-0 prose-p:-mb-6 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-8 prose-li:-mb-4 whitespace-pre-line"
  244. >
  245. <div>
  246. {#if edit === true}
  247. <div class=" w-full">
  248. <textarea
  249. id="message-edit-{message.id}"
  250. class=" bg-transparent outline-none w-full resize-none"
  251. bind:value={editedContent}
  252. on:input={(e) => {
  253. e.target.style.height = `${e.target.scrollHeight}px`;
  254. }}
  255. />
  256. <div class=" mt-2 mb-1 flex justify-center space-x-2 text-sm font-medium">
  257. <button
  258. class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded-lg"
  259. on:click={() => {
  260. editMessageConfirmHandler();
  261. }}
  262. >
  263. Save
  264. </button>
  265. <button
  266. 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"
  267. on:click={() => {
  268. cancelEditMessage();
  269. }}
  270. >
  271. Cancel
  272. </button>
  273. </div>
  274. </div>
  275. {:else}
  276. <div class="w-full">
  277. {#if message?.error === true}
  278. <div
  279. 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"
  280. >
  281. <svg
  282. xmlns="http://www.w3.org/2000/svg"
  283. fill="none"
  284. viewBox="0 0 24 24"
  285. stroke-width="1.5"
  286. stroke="currentColor"
  287. class="w-5 h-5 self-center"
  288. >
  289. <path
  290. stroke-linecap="round"
  291. stroke-linejoin="round"
  292. d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
  293. />
  294. </svg>
  295. <div class=" self-center">
  296. {message.content}
  297. </div>
  298. </div>
  299. {:else}
  300. {#each tokens as token}
  301. {#if token.type === 'code'}
  302. <!-- {token.text} -->
  303. <CodeBlock lang={token.lang} code={token.text} />
  304. {:else}
  305. {@html marked.parse(token.raw, {
  306. ...defaults,
  307. gfm: true,
  308. breaks: true,
  309. renderer
  310. })}
  311. {/if}
  312. {/each}
  313. <!-- {@html marked(message.content.replaceAll('\\', '\\\\'))} -->
  314. {/if}
  315. {#if message.done}
  316. <div
  317. class=" flex justify-start space-x-1 overflow-x-auto buttons text-gray-700 dark:text-gray-500"
  318. >
  319. {#if siblings.length > 1}
  320. <div class="flex self-center min-w-fit">
  321. <button
  322. class="self-center dark:hover:text-white hover:text-black transition"
  323. on:click={() => {
  324. showPreviousMessage(message);
  325. }}
  326. >
  327. <svg
  328. xmlns="http://www.w3.org/2000/svg"
  329. viewBox="0 0 20 20"
  330. fill="currentColor"
  331. class="w-4 h-4"
  332. >
  333. <path
  334. fill-rule="evenodd"
  335. 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"
  336. clip-rule="evenodd"
  337. />
  338. </svg>
  339. </button>
  340. <div class="text-xs font-bold self-center min-w-fit dark:text-gray-100">
  341. {siblings.indexOf(message.id) + 1} / {siblings.length}
  342. </div>
  343. <button
  344. class="self-center dark:hover:text-white hover:text-black transition"
  345. on:click={() => {
  346. showNextMessage(message);
  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. fill-rule="evenodd"
  357. 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"
  358. clip-rule="evenodd"
  359. />
  360. </svg>
  361. </button>
  362. </div>
  363. {/if}
  364. <button
  365. class="{isLastMessage
  366. ? 'visible'
  367. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  368. on:click={() => {
  369. editMessageHandler();
  370. }}
  371. >
  372. <svg
  373. xmlns="http://www.w3.org/2000/svg"
  374. fill="none"
  375. viewBox="0 0 24 24"
  376. stroke-width="1.5"
  377. stroke="currentColor"
  378. class="w-4 h-4"
  379. >
  380. <path
  381. stroke-linecap="round"
  382. stroke-linejoin="round"
  383. 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"
  384. />
  385. </svg>
  386. </button>
  387. <button
  388. class="{isLastMessage
  389. ? 'visible'
  390. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition copy-response-button"
  391. on:click={() => {
  392. copyToClipboard(message.content);
  393. }}
  394. >
  395. <svg
  396. xmlns="http://www.w3.org/2000/svg"
  397. fill="none"
  398. viewBox="0 0 24 24"
  399. stroke-width="1.5"
  400. stroke="currentColor"
  401. class="w-4 h-4"
  402. >
  403. <path
  404. stroke-linecap="round"
  405. stroke-linejoin="round"
  406. 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"
  407. />
  408. </svg>
  409. </button>
  410. <button
  411. class="{isLastMessage
  412. ? 'visible'
  413. : 'invisible group-hover:visible'} p-1 rounded {message.rating === 1
  414. ? 'bg-gray-100 dark:bg-gray-800'
  415. : ''} dark:hover:text-white hover:text-black transition"
  416. on:click={() => {
  417. rateMessage(message.id, 1);
  418. }}
  419. >
  420. <svg
  421. stroke="currentColor"
  422. fill="none"
  423. stroke-width="2"
  424. viewBox="0 0 24 24"
  425. stroke-linecap="round"
  426. stroke-linejoin="round"
  427. class="w-4 h-4"
  428. xmlns="http://www.w3.org/2000/svg"
  429. ><path
  430. 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"
  431. /></svg
  432. >
  433. </button>
  434. <button
  435. class="{isLastMessage
  436. ? 'visible'
  437. : 'invisible group-hover:visible'} p-1 rounded {message.rating === -1
  438. ? 'bg-gray-100 dark:bg-gray-800'
  439. : ''} dark:hover:text-white hover:text-black transition"
  440. on:click={() => {
  441. rateMessage(message.id, -1);
  442. }}
  443. >
  444. <svg
  445. stroke="currentColor"
  446. fill="none"
  447. stroke-width="2"
  448. viewBox="0 0 24 24"
  449. stroke-linecap="round"
  450. stroke-linejoin="round"
  451. class="w-4 h-4"
  452. xmlns="http://www.w3.org/2000/svg"
  453. ><path
  454. 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"
  455. /></svg
  456. >
  457. </button>
  458. <button
  459. id="speak-button-{message.id}"
  460. class="{isLastMessage
  461. ? 'visible'
  462. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  463. on:click={() => {
  464. if (!loadingSpeech) {
  465. toggleSpeakMessage(message);
  466. }
  467. }}
  468. >
  469. {#if loadingSpeech}
  470. <svg
  471. class=" w-4 h-4"
  472. fill="currentColor"
  473. viewBox="0 0 24 24"
  474. xmlns="http://www.w3.org/2000/svg"
  475. ><style>
  476. .spinner_S1WN {
  477. animation: spinner_MGfb 0.8s linear infinite;
  478. animation-delay: -0.8s;
  479. }
  480. .spinner_Km9P {
  481. animation-delay: -0.65s;
  482. }
  483. .spinner_JApP {
  484. animation-delay: -0.5s;
  485. }
  486. @keyframes spinner_MGfb {
  487. 93.75%,
  488. 100% {
  489. opacity: 0.2;
  490. }
  491. }
  492. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  493. class="spinner_S1WN spinner_Km9P"
  494. cx="12"
  495. cy="12"
  496. r="3"
  497. /><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
  498. >
  499. {:else if speaking}
  500. <svg
  501. xmlns="http://www.w3.org/2000/svg"
  502. fill="none"
  503. viewBox="0 0 24 24"
  504. stroke-width="1.5"
  505. stroke="currentColor"
  506. class="w-4 h-4"
  507. >
  508. <path
  509. stroke-linecap="round"
  510. stroke-linejoin="round"
  511. 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"
  512. />
  513. </svg>
  514. {:else}
  515. <svg
  516. xmlns="http://www.w3.org/2000/svg"
  517. fill="none"
  518. viewBox="0 0 24 24"
  519. stroke-width="1.5"
  520. stroke="currentColor"
  521. class="w-4 h-4"
  522. >
  523. <path
  524. stroke-linecap="round"
  525. stroke-linejoin="round"
  526. 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"
  527. />
  528. </svg>
  529. {/if}
  530. </button>
  531. {#if message.info}
  532. <button
  533. class=" {isLastMessage
  534. ? 'visible'
  535. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition whitespace-pre-wrap"
  536. on:click={() => {
  537. console.log(message);
  538. }}
  539. id="info-{message.id}"
  540. >
  541. <svg
  542. xmlns="http://www.w3.org/2000/svg"
  543. fill="none"
  544. viewBox="0 0 24 24"
  545. stroke-width="1.5"
  546. stroke="currentColor"
  547. class="w-4 h-4"
  548. >
  549. <path
  550. stroke-linecap="round"
  551. stroke-linejoin="round"
  552. 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"
  553. />
  554. </svg>
  555. </button>
  556. {/if}
  557. {#if isLastMessage}
  558. <button
  559. type="button"
  560. class="{isLastMessage
  561. ? 'visible'
  562. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  563. on:click={() => {
  564. continueGeneration();
  565. }}
  566. >
  567. <svg
  568. xmlns="http://www.w3.org/2000/svg"
  569. fill="none"
  570. viewBox="0 0 24 24"
  571. stroke-width="1.5"
  572. stroke="currentColor"
  573. class="w-4 h-4"
  574. >
  575. <path
  576. stroke-linecap="round"
  577. stroke-linejoin="round"
  578. d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
  579. />
  580. <path
  581. stroke-linecap="round"
  582. stroke-linejoin="round"
  583. 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"
  584. />
  585. </svg>
  586. </button>
  587. <button
  588. type="button"
  589. class="{isLastMessage
  590. ? 'visible'
  591. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  592. on:click={regenerateResponse}
  593. >
  594. <svg
  595. xmlns="http://www.w3.org/2000/svg"
  596. fill="none"
  597. viewBox="0 0 24 24"
  598. stroke-width="1.5"
  599. stroke="currentColor"
  600. class="w-4 h-4"
  601. >
  602. <path
  603. stroke-linecap="round"
  604. stroke-linejoin="round"
  605. 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"
  606. />
  607. </svg>
  608. </button>
  609. {/if}
  610. </div>
  611. {/if}
  612. </div>
  613. {/if}
  614. </div>
  615. </div>
  616. {/if}
  617. </div>
  618. </div>
  619. {/key}
  620. <style>
  621. .buttons::-webkit-scrollbar {
  622. display: none; /* for Chrome, Safari and Opera */
  623. }
  624. .buttons {
  625. -ms-overflow-style: none; /* IE and Edge */
  626. scrollbar-width: none; /* Firefox */
  627. }
  628. </style>