ResponseMessage.svelte 27 KB

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