ResponseMessage.svelte 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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 = '';
  290. e.target.style.height = `${e.target.scrollHeight}px`;
  291. }}
  292. />
  293. <div class=" mt-2 mb-1 flex justify-center space-x-2 text-sm font-medium">
  294. <button
  295. class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded-lg"
  296. on:click={() => {
  297. editMessageConfirmHandler();
  298. }}
  299. >
  300. Save
  301. </button>
  302. <button
  303. 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"
  304. on:click={() => {
  305. cancelEditMessage();
  306. }}
  307. >
  308. Cancel
  309. </button>
  310. </div>
  311. </div>
  312. {:else}
  313. <div class="w-full">
  314. {#if message?.error === true}
  315. <div
  316. 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"
  317. >
  318. <svg
  319. xmlns="http://www.w3.org/2000/svg"
  320. fill="none"
  321. viewBox="0 0 24 24"
  322. stroke-width="1.5"
  323. stroke="currentColor"
  324. class="w-5 h-5 self-center"
  325. >
  326. <path
  327. stroke-linecap="round"
  328. stroke-linejoin="round"
  329. d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
  330. />
  331. </svg>
  332. <div class=" self-center">
  333. {message.content}
  334. </div>
  335. </div>
  336. {:else}
  337. {#each tokens as token}
  338. {#if token.type === 'code'}
  339. <!-- {token.text} -->
  340. <CodeBlock lang={token.lang} code={token.text} />
  341. {:else}
  342. {@html marked.parse(token.raw, {
  343. ...defaults,
  344. gfm: true,
  345. breaks: true,
  346. renderer
  347. })}
  348. {/if}
  349. {/each}
  350. <!-- {@html marked(message.content.replaceAll('\\', '\\\\'))} -->
  351. {/if}
  352. {#if message.done}
  353. <div
  354. class=" flex justify-start space-x-1 overflow-x-auto buttons text-gray-700 dark:text-gray-500"
  355. >
  356. {#if siblings.length > 1}
  357. <div class="flex self-center min-w-fit">
  358. <button
  359. class="self-center dark:hover:text-white hover:text-black transition"
  360. on:click={() => {
  361. showPreviousMessage(message);
  362. }}
  363. >
  364. <svg
  365. xmlns="http://www.w3.org/2000/svg"
  366. viewBox="0 0 20 20"
  367. fill="currentColor"
  368. class="w-4 h-4"
  369. >
  370. <path
  371. fill-rule="evenodd"
  372. 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"
  373. clip-rule="evenodd"
  374. />
  375. </svg>
  376. </button>
  377. <div class="text-xs font-bold self-center min-w-fit dark:text-gray-100">
  378. {siblings.indexOf(message.id) + 1} / {siblings.length}
  379. </div>
  380. <button
  381. class="self-center dark:hover:text-white hover:text-black transition"
  382. on:click={() => {
  383. showNextMessage(message);
  384. }}
  385. >
  386. <svg
  387. xmlns="http://www.w3.org/2000/svg"
  388. viewBox="0 0 20 20"
  389. fill="currentColor"
  390. class="w-4 h-4"
  391. >
  392. <path
  393. fill-rule="evenodd"
  394. 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"
  395. clip-rule="evenodd"
  396. />
  397. </svg>
  398. </button>
  399. </div>
  400. {/if}
  401. <button
  402. class="{isLastMessage
  403. ? 'visible'
  404. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  405. on:click={() => {
  406. editMessageHandler();
  407. }}
  408. >
  409. <svg
  410. xmlns="http://www.w3.org/2000/svg"
  411. fill="none"
  412. viewBox="0 0 24 24"
  413. stroke-width="1.5"
  414. stroke="currentColor"
  415. class="w-4 h-4"
  416. >
  417. <path
  418. stroke-linecap="round"
  419. stroke-linejoin="round"
  420. 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"
  421. />
  422. </svg>
  423. </button>
  424. <button
  425. class="{isLastMessage
  426. ? 'visible'
  427. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition copy-response-button"
  428. on:click={() => {
  429. copyToClipboard(message.content);
  430. }}
  431. >
  432. <svg
  433. xmlns="http://www.w3.org/2000/svg"
  434. fill="none"
  435. viewBox="0 0 24 24"
  436. stroke-width="1.5"
  437. stroke="currentColor"
  438. class="w-4 h-4"
  439. >
  440. <path
  441. stroke-linecap="round"
  442. stroke-linejoin="round"
  443. 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"
  444. />
  445. </svg>
  446. </button>
  447. <button
  448. class="{isLastMessage
  449. ? 'visible'
  450. : 'invisible group-hover:visible'} p-1 rounded {message.rating === 1
  451. ? 'bg-gray-100 dark:bg-gray-800'
  452. : ''} dark:hover:text-white hover:text-black transition"
  453. on:click={() => {
  454. rateMessage(message.id, 1);
  455. }}
  456. >
  457. <svg
  458. stroke="currentColor"
  459. fill="none"
  460. stroke-width="2"
  461. viewBox="0 0 24 24"
  462. stroke-linecap="round"
  463. stroke-linejoin="round"
  464. class="w-4 h-4"
  465. xmlns="http://www.w3.org/2000/svg"
  466. ><path
  467. 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"
  468. /></svg
  469. >
  470. </button>
  471. <button
  472. class="{isLastMessage
  473. ? 'visible'
  474. : 'invisible group-hover:visible'} p-1 rounded {message.rating === -1
  475. ? 'bg-gray-100 dark:bg-gray-800'
  476. : ''} dark:hover:text-white hover:text-black transition"
  477. on:click={() => {
  478. rateMessage(message.id, -1);
  479. }}
  480. >
  481. <svg
  482. stroke="currentColor"
  483. fill="none"
  484. stroke-width="2"
  485. viewBox="0 0 24 24"
  486. stroke-linecap="round"
  487. stroke-linejoin="round"
  488. class="w-4 h-4"
  489. xmlns="http://www.w3.org/2000/svg"
  490. ><path
  491. 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"
  492. /></svg
  493. >
  494. </button>
  495. <button
  496. id="speak-button-{message.id}"
  497. class="{isLastMessage
  498. ? 'visible'
  499. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  500. on:click={() => {
  501. if (!loadingSpeech) {
  502. toggleSpeakMessage(message);
  503. }
  504. }}
  505. >
  506. {#if loadingSpeech}
  507. <svg
  508. class=" w-4 h-4"
  509. fill="currentColor"
  510. viewBox="0 0 24 24"
  511. xmlns="http://www.w3.org/2000/svg"
  512. ><style>
  513. .spinner_S1WN {
  514. animation: spinner_MGfb 0.8s linear infinite;
  515. animation-delay: -0.8s;
  516. }
  517. .spinner_Km9P {
  518. animation-delay: -0.65s;
  519. }
  520. .spinner_JApP {
  521. animation-delay: -0.5s;
  522. }
  523. @keyframes spinner_MGfb {
  524. 93.75%,
  525. 100% {
  526. opacity: 0.2;
  527. }
  528. }
  529. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  530. class="spinner_S1WN spinner_Km9P"
  531. cx="12"
  532. cy="12"
  533. r="3"
  534. /><circle class="spinner_S1WN spinner_JApP" cx="20" cy="12" r="3" /></svg
  535. >
  536. {:else if speaking}
  537. <svg
  538. xmlns="http://www.w3.org/2000/svg"
  539. fill="none"
  540. viewBox="0 0 24 24"
  541. stroke-width="1.5"
  542. stroke="currentColor"
  543. class="w-4 h-4"
  544. >
  545. <path
  546. stroke-linecap="round"
  547. stroke-linejoin="round"
  548. 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"
  549. />
  550. </svg>
  551. {:else}
  552. <svg
  553. xmlns="http://www.w3.org/2000/svg"
  554. fill="none"
  555. viewBox="0 0 24 24"
  556. stroke-width="1.5"
  557. stroke="currentColor"
  558. class="w-4 h-4"
  559. >
  560. <path
  561. stroke-linecap="round"
  562. stroke-linejoin="round"
  563. 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"
  564. />
  565. </svg>
  566. {/if}
  567. </button>
  568. {#if $config.images}
  569. <button
  570. class="{isLastMessage
  571. ? 'visible'
  572. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition"
  573. on:click={() => {
  574. if (!generatingImage) {
  575. generateImage(message);
  576. }
  577. }}
  578. >
  579. {#if generatingImage}
  580. <svg
  581. class=" w-4 h-4"
  582. fill="currentColor"
  583. viewBox="0 0 24 24"
  584. xmlns="http://www.w3.org/2000/svg"
  585. ><style>
  586. .spinner_S1WN {
  587. animation: spinner_MGfb 0.8s linear infinite;
  588. animation-delay: -0.8s;
  589. }
  590. .spinner_Km9P {
  591. animation-delay: -0.65s;
  592. }
  593. .spinner_JApP {
  594. animation-delay: -0.5s;
  595. }
  596. @keyframes spinner_MGfb {
  597. 93.75%,
  598. 100% {
  599. opacity: 0.2;
  600. }
  601. }
  602. </style><circle class="spinner_S1WN" cx="4" cy="12" r="3" /><circle
  603. class="spinner_S1WN spinner_Km9P"
  604. cx="12"
  605. cy="12"
  606. r="3"
  607. /><circle
  608. class="spinner_S1WN spinner_JApP"
  609. cx="20"
  610. cy="12"
  611. r="3"
  612. /></svg
  613. >
  614. {:else}
  615. <svg
  616. xmlns="http://www.w3.org/2000/svg"
  617. fill="none"
  618. viewBox="0 0 24 24"
  619. stroke-width="1.5"
  620. stroke="currentColor"
  621. class="w-4 h-4"
  622. >
  623. <path
  624. stroke-linecap="round"
  625. stroke-linejoin="round"
  626. 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"
  627. />
  628. </svg>
  629. {/if}
  630. </button>
  631. {/if}
  632. {#if message.info}
  633. <button
  634. class=" {isLastMessage
  635. ? 'visible'
  636. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition whitespace-pre-wrap"
  637. on:click={() => {
  638. console.log(message);
  639. }}
  640. id="info-{message.id}"
  641. >
  642. <svg
  643. xmlns="http://www.w3.org/2000/svg"
  644. fill="none"
  645. viewBox="0 0 24 24"
  646. stroke-width="1.5"
  647. stroke="currentColor"
  648. class="w-4 h-4"
  649. >
  650. <path
  651. stroke-linecap="round"
  652. stroke-linejoin="round"
  653. 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"
  654. />
  655. </svg>
  656. </button>
  657. {/if}
  658. {#if isLastMessage}
  659. <button
  660. type="button"
  661. class="{isLastMessage
  662. ? 'visible'
  663. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  664. on:click={() => {
  665. continueGeneration();
  666. }}
  667. >
  668. <svg
  669. xmlns="http://www.w3.org/2000/svg"
  670. fill="none"
  671. viewBox="0 0 24 24"
  672. stroke-width="1.5"
  673. stroke="currentColor"
  674. class="w-4 h-4"
  675. >
  676. <path
  677. stroke-linecap="round"
  678. stroke-linejoin="round"
  679. d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
  680. />
  681. <path
  682. stroke-linecap="round"
  683. stroke-linejoin="round"
  684. 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"
  685. />
  686. </svg>
  687. </button>
  688. <button
  689. type="button"
  690. class="{isLastMessage
  691. ? 'visible'
  692. : 'invisible group-hover:visible'} p-1 rounded dark:hover:text-white hover:text-black transition regenerate-response-button"
  693. on:click={regenerateResponse}
  694. >
  695. <svg
  696. xmlns="http://www.w3.org/2000/svg"
  697. fill="none"
  698. viewBox="0 0 24 24"
  699. stroke-width="1.5"
  700. stroke="currentColor"
  701. class="w-4 h-4"
  702. >
  703. <path
  704. stroke-linecap="round"
  705. stroke-linejoin="round"
  706. 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"
  707. />
  708. </svg>
  709. </button>
  710. {/if}
  711. </div>
  712. {/if}
  713. </div>
  714. {/if}
  715. </div>
  716. </div>
  717. {/if}
  718. </div>
  719. </div>
  720. {/key}
  721. <style>
  722. .buttons::-webkit-scrollbar {
  723. display: none; /* for Chrome, Safari and Opera */
  724. }
  725. .buttons {
  726. -ms-overflow-style: none; /* IE and Edge */
  727. scrollbar-width: none; /* Firefox */
  728. }
  729. </style>