ResponseMessage.svelte 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. <script lang="ts">
  2. import toast from 'svelte-french-toast';
  3. import dayjs from 'dayjs';
  4. import { marked } from 'marked';
  5. import tippy from 'tippy.js';
  6. import auto_render from 'katex/dist/contrib/auto-render.mjs';
  7. import 'katex/dist/katex.min.css';
  8. import { createEventDispatcher } from 'svelte';
  9. import { onMount, tick } from 'svelte';
  10. const dispatch = createEventDispatcher();
  11. import { config, settings } from '$lib/stores';
  12. import { synthesizeOpenAISpeech } from '$lib/apis/openai';
  13. import { imageGenerations } from '$lib/apis/images';
  14. import { extractSentences } from '$lib/utils';
  15. import Name from './Name.svelte';
  16. import ProfileImage from './ProfileImage.svelte';
  17. import Skeleton from './Skeleton.svelte';
  18. import CodeBlock from './CodeBlock.svelte';
  19. import Image from '$lib/components/common/Image.svelte';
  20. import { WEBUI_BASE_URL } from '$lib/constants';
  21. export let modelfiles = [];
  22. export let message;
  23. export let siblings;
  24. export let isLastMessage = true;
  25. export let confirmEditResponseMessage: Function;
  26. export let showPreviousMessage: Function;
  27. export let showNextMessage: Function;
  28. export let rateMessage: Function;
  29. export let copyToClipboard: Function;
  30. export let continueGeneration: Function;
  31. export let regenerateResponse: Function;
  32. let edit = false;
  33. let editedContent = '';
  34. let tooltipInstance = null;
  35. let sentencesAudio = {};
  36. let speaking = null;
  37. let speakingIdx = null;
  38. let loadingSpeech = false;
  39. let generatingImage = false;
  40. $: tokens = marked.lexer(message.content);
  41. const renderer = new marked.Renderer();
  42. // For code blocks with simple backticks
  43. renderer.codespan = (code) => {
  44. return `<code>${code.replaceAll('&amp;', '&')}</code>`;
  45. };
  46. const { extensions, ...defaults } = marked.getDefaults() as marked.MarkedOptions & {
  47. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  48. extensions: any;
  49. };
  50. $: if (message) {
  51. renderStyling();
  52. }
  53. const renderStyling = async () => {
  54. await tick();
  55. if (tooltipInstance) {
  56. tooltipInstance[0]?.destroy();
  57. }
  58. renderLatex();
  59. if (message.info) {
  60. tooltipInstance = tippy(`#info-${message.id}`, {
  61. content: `<span class="text-xs" id="tooltip-${message.id}">response_token/s: ${
  62. `${
  63. Math.round(
  64. ((message.info.eval_count ?? 0) / (message.info.eval_duration / 1000000000)) * 100
  65. ) / 100
  66. } tokens` ?? 'N/A'
  67. }<br/>
  68. prompt_token/s: ${
  69. Math.round(
  70. ((message.info.prompt_eval_count ?? 0) /
  71. (message.info.prompt_eval_duration / 1000000000)) *
  72. 100
  73. ) / 100 ?? 'N/A'
  74. } tokens<br/>
  75. total_duration: ${
  76. Math.round(((message.info.total_duration ?? 0) / 1000000) * 100) / 100 ??
  77. 'N/A'
  78. }ms<br/>
  79. load_duration: ${
  80. Math.round(((message.info.load_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  81. }ms<br/>
  82. prompt_eval_count: ${message.info.prompt_eval_count ?? 'N/A'}<br/>
  83. prompt_eval_duration: ${
  84. Math.round(((message.info.prompt_eval_duration ?? 0) / 1000000) * 100) /
  85. 100 ?? 'N/A'
  86. }ms<br/>
  87. eval_count: ${message.info.eval_count ?? 'N/A'}<br/>
  88. eval_duration: ${
  89. Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A'
  90. }ms</span>`,
  91. allowHTML: true
  92. });
  93. }
  94. };
  95. const renderLatex = () => {
  96. let chatMessageElements = document.getElementsByClassName('chat-assistant');
  97. // let lastChatMessageElement = chatMessageElements[chatMessageElements.length - 1];
  98. for (const element of chatMessageElements) {
  99. auto_render(element, {
  100. // customised options
  101. // • auto-render specific keys, e.g.:
  102. delimiters: [
  103. { left: '$$', right: '$$', display: false },
  104. { left: '$', right: '$', display: false },
  105. { left: '\\(', right: '\\)', display: false },
  106. { left: '\\[', right: '\\]', display: false },
  107. { left: '[ ', right: ' ]', display: false }
  108. ],
  109. // • rendering keys, e.g.:
  110. throwOnError: false
  111. });
  112. }
  113. };
  114. const playAudio = (idx) => {
  115. return new Promise((res) => {
  116. speakingIdx = idx;
  117. const audio = sentencesAudio[idx];
  118. audio.play();
  119. audio.onended = async (e) => {
  120. await new Promise((r) => setTimeout(r, 300));
  121. if (Object.keys(sentencesAudio).length - 1 === idx) {
  122. speaking = null;
  123. if ($settings.conversationMode) {
  124. document.getElementById('voice-input-button')?.click();
  125. }
  126. }
  127. res(e);
  128. };
  129. });
  130. };
  131. const toggleSpeakMessage = async () => {
  132. if (speaking) {
  133. speechSynthesis.cancel();
  134. sentencesAudio[speakingIdx].pause();
  135. sentencesAudio[speakingIdx].currentTime = 0;
  136. speaking = null;
  137. speakingIdx = null;
  138. } else {
  139. speaking = true;
  140. if ($settings?.audio?.TTSEngine === 'openai') {
  141. loadingSpeech = true;
  142. const sentences = extractSentences(message.content).reduce((mergedTexts, currentText) => {
  143. const lastIndex = mergedTexts.length - 1;
  144. if (lastIndex >= 0) {
  145. const previousText = mergedTexts[lastIndex];
  146. const wordCount = previousText.split(/\s+/).length;
  147. if (wordCount < 2) {
  148. mergedTexts[lastIndex] = previousText + ' ' + currentText;
  149. } else {
  150. mergedTexts.push(currentText);
  151. }
  152. } else {
  153. mergedTexts.push(currentText);
  154. }
  155. return mergedTexts;
  156. }, []);
  157. console.log(sentences);
  158. sentencesAudio = sentences.reduce((a, e, i, arr) => {
  159. a[i] = null;
  160. return a;
  161. }, {});
  162. let lastPlayedAudioPromise = Promise.resolve(); // Initialize a promise that resolves immediately
  163. for (const [idx, sentence] of sentences.entries()) {
  164. const res = await synthesizeOpenAISpeech(
  165. localStorage.token,
  166. $settings?.audio?.speaker,
  167. sentence
  168. ).catch((error) => {
  169. toast.error(error);
  170. return null;
  171. });
  172. if (res) {
  173. const blob = await res.blob();
  174. const blobUrl = URL.createObjectURL(blob);
  175. const audio = new Audio(blobUrl);
  176. sentencesAudio[idx] = audio;
  177. loadingSpeech = false;
  178. lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
  179. }
  180. }
  181. } else {
  182. let voices = [];
  183. const getVoicesLoop = setInterval(async () => {
  184. voices = await speechSynthesis.getVoices();
  185. if (voices.length > 0) {
  186. clearInterval(getVoicesLoop);
  187. const voice =
  188. voices?.filter((v) => v.name === $settings?.audio?.speaker)?.at(0) ?? undefined;
  189. const speak = new SpeechSynthesisUtterance(message.content);
  190. speak.onend = () => {
  191. speaking = null;
  192. if ($settings.conversationMode) {
  193. document.getElementById('voice-input-button')?.click();
  194. }
  195. };
  196. speak.voice = voice;
  197. speechSynthesis.speak(speak);
  198. }
  199. }, 100);
  200. }
  201. }
  202. };
  203. const editMessageHandler = async () => {
  204. edit = true;
  205. editedContent = message.content;
  206. await tick();
  207. const editElement = document.getElementById(`message-edit-${message.id}`);
  208. editElement.style.height = '';
  209. editElement.style.height = `${editElement.scrollHeight}px`;
  210. };
  211. const editMessageConfirmHandler = async () => {
  212. if (editedContent === '') {
  213. editedContent = ' ';
  214. }
  215. confirmEditResponseMessage(message.id, editedContent);
  216. edit = false;
  217. editedContent = '';
  218. await tick();
  219. renderStyling();
  220. };
  221. const cancelEditMessage = async () => {
  222. edit = false;
  223. editedContent = '';
  224. await tick();
  225. renderStyling();
  226. };
  227. const generateImage = async (message) => {
  228. generatingImage = true;
  229. const res = await imageGenerations(localStorage.token, message.content);
  230. console.log(res);
  231. if (res) {
  232. message.files = res.images.map((image) => ({
  233. type: 'image',
  234. url: `data:image/png;base64,${image}`
  235. }));
  236. dispatch('save', message);
  237. }
  238. generatingImage = false;
  239. };
  240. onMount(async () => {
  241. await tick();
  242. renderStyling();
  243. });
  244. </script>
  245. {#key message.id}
  246. <div class=" flex w-full message-{message.id}">
  247. <ProfileImage
  248. src={modelfiles[message.model]?.imageUrl ?? `${WEBUI_BASE_URL}/static/favicon.png`}
  249. />
  250. <div class="w-full overflow-hidden">
  251. <Name>
  252. {#if message.model in modelfiles}
  253. {modelfiles[message.model]?.title}
  254. {:else}
  255. {message.model ? ` ${message.model}` : ''}
  256. {/if}
  257. {#if message.timestamp}
  258. <span class=" invisible group-hover:visible text-gray-400 text-xs font-medium">
  259. {dayjs(message.timestamp * 1000).format('DD/MM/YYYY HH:mm')}
  260. </span>
  261. {/if}
  262. </Name>
  263. {#if message.content === ''}
  264. <Skeleton />
  265. {:else}
  266. {#if message.files}
  267. <div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
  268. {#each message.files as file}
  269. <div>
  270. {#if file.type === 'image'}
  271. <Image src={file.url} />
  272. {/if}
  273. </div>
  274. {/each}
  275. </div>
  276. {/if}
  277. <div
  278. 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"
  279. >
  280. <div>
  281. {#if edit === true}
  282. <div class=" w-full">
  283. <textarea
  284. id="message-edit-{message.id}"
  285. class=" bg-transparent outline-none w-full resize-none"
  286. bind:value={editedContent}
  287. on:input={(e) => {
  288. e.target.style.height = `${e.target.scrollHeight}px`;
  289. }}
  290. />
  291. <div class=" mt-2 mb-1 flex justify-center space-x-2 text-sm font-medium">
  292. <button
  293. class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded-lg"
  294. on:click={() => {
  295. editMessageConfirmHandler();
  296. }}
  297. >
  298. Save
  299. </button>
  300. <button
  301. 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"
  302. on:click={() => {
  303. cancelEditMessage();
  304. }}
  305. >
  306. Cancel
  307. </button>
  308. </div>
  309. </div>
  310. {:else}
  311. <div class="w-full">
  312. {#if message?.error === true}
  313. <div
  314. 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"
  315. >
  316. <svg
  317. xmlns="http://www.w3.org/2000/svg"
  318. fill="none"
  319. viewBox="0 0 24 24"
  320. stroke-width="1.5"
  321. stroke="currentColor"
  322. class="w-5 h-5 self-center"
  323. >
  324. <path
  325. stroke-linecap="round"
  326. stroke-linejoin="round"
  327. d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
  328. />
  329. </svg>
  330. <div class=" self-center">
  331. {message.content}
  332. </div>
  333. </div>
  334. {:else}
  335. {#each tokens as token}
  336. {#if token.type === 'code'}
  337. <!-- {token.text} -->
  338. <CodeBlock lang={token.lang} code={token.text} />
  339. {:else}
  340. {@html marked.parse(token.raw, {
  341. ...defaults,
  342. gfm: true,
  343. breaks: true,
  344. renderer
  345. })}
  346. {/if}
  347. {/each}
  348. <!-- {@html marked(message.content.replaceAll('\\', '\\\\'))} -->
  349. {/if}
  350. {#if message.done}
  351. <div
  352. class=" flex justify-start space-x-1 overflow-x-auto buttons text-gray-700 dark:text-gray-500"
  353. >
  354. {#if siblings.length > 1}
  355. <div class="flex self-center min-w-fit">
  356. <button
  357. class="self-center dark:hover:text-white hover:text-black transition"
  358. on:click={() => {
  359. showPreviousMessage(message);
  360. }}
  361. >
  362. <svg
  363. xmlns="http://www.w3.org/2000/svg"
  364. viewBox="0 0 20 20"
  365. fill="currentColor"
  366. class="w-4 h-4"
  367. >
  368. <path
  369. fill-rule="evenodd"
  370. 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"
  371. clip-rule="evenodd"
  372. />
  373. </svg>
  374. </button>
  375. <div class="text-xs font-bold self-center min-w-fit dark:text-gray-100">
  376. {siblings.indexOf(message.id) + 1} / {siblings.length}
  377. </div>
  378. <button
  379. class="self-center dark:hover:text-white hover:text-black transition"
  380. on:click={() => {
  381. showNextMessage(message);
  382. }}
  383. >
  384. <svg
  385. xmlns="http://www.w3.org/2000/svg"
  386. viewBox="0 0 20 20"
  387. fill="currentColor"
  388. class="w-4 h-4"
  389. >
  390. <path
  391. fill-rule="evenodd"
  392. 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"
  393. clip-rule="evenodd"
  394. />
  395. </svg>
  396. </button>
  397. </div>
  398. {/if}
  399. <button
  400. class="{isLastMessage
  401. ? 'visible'
  402. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  403. on:click={() => {
  404. editMessageHandler();
  405. }}
  406. >
  407. <svg
  408. xmlns="http://www.w3.org/2000/svg"
  409. fill="none"
  410. viewBox="0 0 24 24"
  411. stroke-width="1.5"
  412. stroke="currentColor"
  413. class="w-4 h-4"
  414. >
  415. <path
  416. stroke-linecap="round"
  417. stroke-linejoin="round"
  418. 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"
  419. />
  420. </svg>
  421. </button>
  422. <button
  423. class="{isLastMessage
  424. ? 'visible'
  425. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition copy-response-button"
  426. on:click={() => {
  427. copyToClipboard(message.content);
  428. }}
  429. >
  430. <svg
  431. xmlns="http://www.w3.org/2000/svg"
  432. fill="none"
  433. viewBox="0 0 24 24"
  434. stroke-width="1.5"
  435. stroke="currentColor"
  436. class="w-4 h-4"
  437. >
  438. <path
  439. stroke-linecap="round"
  440. stroke-linejoin="round"
  441. 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"
  442. />
  443. </svg>
  444. </button>
  445. <button
  446. class="{isLastMessage
  447. ? 'visible'
  448. : 'invisible group-hover:visible'} p-1 rounded {message.rating === 1
  449. ? 'bg-gray-100 dark:bg-gray-800'
  450. : ''} dark:hover:text-white hover:text-black transition"
  451. on:click={() => {
  452. rateMessage(message.id, 1);
  453. }}
  454. >
  455. <svg
  456. stroke="currentColor"
  457. fill="none"
  458. stroke-width="2"
  459. viewBox="0 0 24 24"
  460. stroke-linecap="round"
  461. stroke-linejoin="round"
  462. class="w-4 h-4"
  463. xmlns="http://www.w3.org/2000/svg"
  464. ><path
  465. 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"
  466. /></svg
  467. >
  468. </button>
  469. <button
  470. class="{isLastMessage
  471. ? 'visible'
  472. : 'invisible group-hover:visible'} p-1 rounded {message.rating === -1
  473. ? 'bg-gray-100 dark:bg-gray-800'
  474. : ''} dark:hover:text-white hover:text-black transition"
  475. on:click={() => {
  476. rateMessage(message.id, -1);
  477. }}
  478. >
  479. <svg
  480. stroke="currentColor"
  481. fill="none"
  482. stroke-width="2"
  483. viewBox="0 0 24 24"
  484. stroke-linecap="round"
  485. stroke-linejoin="round"
  486. class="w-4 h-4"
  487. xmlns="http://www.w3.org/2000/svg"
  488. ><path
  489. 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"
  490. /></svg
  491. >
  492. </button>
  493. <button
  494. id="speak-button-{message.id}"
  495. class="{isLastMessage
  496. ? 'visible'
  497. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  498. on:click={() => {
  499. if (!loadingSpeech) {
  500. toggleSpeakMessage(message);
  501. }
  502. }}
  503. >
  504. {#if loadingSpeech}
  505. <svg
  506. class=" w-4 h-4"
  507. fill="currentColor"
  508. viewBox="0 0 24 24"
  509. xmlns="http://www.w3.org/2000/svg"
  510. ><style>
  511. .spinner_S1WN {
  512. animation: spinner_MGfb 0.8s linear infinite;
  513. animation-delay: -0.8s;
  514. }
  515. .spinner_Km9P {
  516. animation-delay: -0.65s;
  517. }
  518. .spinner_JApP {
  519. animation-delay: -0.5s;
  520. }
  521. @keyframes spinner_MGfb {
  522. 93.75%,
  523. 100% {
  524. opacity: 0.2;
  525. }
  526. }
  527. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  528. class="spinner_S1WN spinner_Km9P"
  529. cx="12"
  530. cy="12"
  531. r="3"
  532. /><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
  533. >
  534. {:else if speaking}
  535. <svg
  536. xmlns="http://www.w3.org/2000/svg"
  537. fill="none"
  538. viewBox="0 0 24 24"
  539. stroke-width="1.5"
  540. stroke="currentColor"
  541. class="w-4 h-4"
  542. >
  543. <path
  544. stroke-linecap="round"
  545. stroke-linejoin="round"
  546. 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"
  547. />
  548. </svg>
  549. {:else}
  550. <svg
  551. xmlns="http://www.w3.org/2000/svg"
  552. fill="none"
  553. viewBox="0 0 24 24"
  554. stroke-width="1.5"
  555. stroke="currentColor"
  556. class="w-4 h-4"
  557. >
  558. <path
  559. stroke-linecap="round"
  560. stroke-linejoin="round"
  561. 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"
  562. />
  563. </svg>
  564. {/if}
  565. </button>
  566. {#if $config.images}
  567. <button
  568. class="{isLastMessage
  569. ? 'visible'
  570. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  571. on:click={() => {
  572. if (!generatingImage) {
  573. generateImage(message);
  574. }
  575. }}
  576. >
  577. {#if generatingImage}
  578. <svg
  579. class=" w-4 h-4"
  580. fill="currentColor"
  581. viewBox="0 0 24 24"
  582. xmlns="http://www.w3.org/2000/svg"
  583. ><style>
  584. .spinner_S1WN {
  585. animation: spinner_MGfb 0.8s linear infinite;
  586. animation-delay: -0.8s;
  587. }
  588. .spinner_Km9P {
  589. animation-delay: -0.65s;
  590. }
  591. .spinner_JApP {
  592. animation-delay: -0.5s;
  593. }
  594. @keyframes spinner_MGfb {
  595. 93.75%,
  596. 100% {
  597. opacity: 0.2;
  598. }
  599. }
  600. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  601. class="spinner_S1WN spinner_Km9P"
  602. cx="12"
  603. cy="12"
  604. r="3"
  605. /><circle
  606. class="spinner_S1WN spinner_JApP"
  607. cx="20"
  608. cy="12"
  609. r="3"
  610. /></svg
  611. >
  612. {:else}
  613. <svg
  614. xmlns="http://www.w3.org/2000/svg"
  615. fill="none"
  616. viewBox="0 0 24 24"
  617. stroke-width="1.5"
  618. stroke="currentColor"
  619. class="w-4 h-4"
  620. >
  621. <path
  622. stroke-linecap="round"
  623. stroke-linejoin="round"
  624. d="m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H3.75A1.5 1.5 0 0 0 2.25 6v12a1.5 1.5 0 0 0 1.5 1.5Zm10.5-11.25h.008v.008h-.008V8.25Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z"
  625. />
  626. </svg>
  627. {/if}
  628. </button>
  629. {/if}
  630. {#if message.info}
  631. <button
  632. class=" {isLastMessage
  633. ? 'visible'
  634. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition whitespace-pre-wrap"
  635. on:click={() => {
  636. console.log(message);
  637. }}
  638. id="info-{message.id}"
  639. >
  640. <svg
  641. xmlns="http://www.w3.org/2000/svg"
  642. fill="none"
  643. viewBox="0 0 24 24"
  644. stroke-width="1.5"
  645. stroke="currentColor"
  646. class="w-4 h-4"
  647. >
  648. <path
  649. stroke-linecap="round"
  650. stroke-linejoin="round"
  651. 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"
  652. />
  653. </svg>
  654. </button>
  655. {/if}
  656. {#if isLastMessage}
  657. <button
  658. type="button"
  659. class="{isLastMessage
  660. ? 'visible'
  661. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  662. on:click={() => {
  663. continueGeneration();
  664. }}
  665. >
  666. <svg
  667. xmlns="http://www.w3.org/2000/svg"
  668. fill="none"
  669. viewBox="0 0 24 24"
  670. stroke-width="1.5"
  671. stroke="currentColor"
  672. class="w-4 h-4"
  673. >
  674. <path
  675. stroke-linecap="round"
  676. stroke-linejoin="round"
  677. d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
  678. />
  679. <path
  680. stroke-linecap="round"
  681. stroke-linejoin="round"
  682. 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"
  683. />
  684. </svg>
  685. </button>
  686. <button
  687. type="button"
  688. class="{isLastMessage
  689. ? 'visible'
  690. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  691. on:click={regenerateResponse}
  692. >
  693. <svg
  694. xmlns="http://www.w3.org/2000/svg"
  695. fill="none"
  696. viewBox="0 0 24 24"
  697. stroke-width="1.5"
  698. stroke="currentColor"
  699. class="w-4 h-4"
  700. >
  701. <path
  702. stroke-linecap="round"
  703. stroke-linejoin="round"
  704. 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"
  705. />
  706. </svg>
  707. </button>
  708. {/if}
  709. </div>
  710. {/if}
  711. </div>
  712. {/if}
  713. </div>
  714. </div>
  715. {/if}
  716. </div>
  717. </div>
  718. {/key}
  719. <style>
  720. .buttons::-webkit-scrollbar {
  721. display: none; /* for Chrome, Safari and Opera */
  722. }
  723. .buttons {
  724. -ms-overflow-style: none; /* IE and Edge */
  725. scrollbar-width: none; /* Firefox */
  726. }
  727. </style>