ResponseMessage.svelte 27 KB

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