ResponseMessage.svelte 24 KB

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