ResponseMessage.svelte 21 KB

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