ResponseMessage.svelte 26 KB

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