Placeholder.svelte 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { marked } from 'marked';
  4. import { onMount, getContext, tick, createEventDispatcher } from 'svelte';
  5. import { blur, fade } from 'svelte/transition';
  6. const dispatch = createEventDispatcher();
  7. import { config, user, models as _models, temporaryChatEnabled } from '$lib/stores';
  8. import { sanitizeResponseContent, findWordIndices } from '$lib/utils';
  9. import { WEBUI_BASE_URL } from '$lib/constants';
  10. import Suggestions from './Suggestions.svelte';
  11. import Tooltip from '$lib/components/common/Tooltip.svelte';
  12. import EyeSlash from '$lib/components/icons/EyeSlash.svelte';
  13. import MessageInput from './MessageInput.svelte';
  14. const i18n = getContext('i18n');
  15. export let transparentBackground = false;
  16. export let createMessagePair: Function;
  17. export let stopResponse: Function;
  18. export let autoScroll = false;
  19. export let atSelectedModel: Model | undefined;
  20. export let selectedModels: [''];
  21. export let history;
  22. export let prompt = '';
  23. export let files = [];
  24. export let selectedToolIds = [];
  25. export let webSearchEnabled = false;
  26. let models = [];
  27. const selectSuggestionPrompt = async (p) => {
  28. let text = p;
  29. if (p.includes('{{CLIPBOARD}}')) {
  30. const clipboardText = await navigator.clipboard.readText().catch((err) => {
  31. toast.error($i18n.t('Failed to read clipboard contents'));
  32. return '{{CLIPBOARD}}';
  33. });
  34. text = p.replaceAll('{{CLIPBOARD}}', clipboardText);
  35. console.log('Clipboard text:', clipboardText, text);
  36. }
  37. prompt = text;
  38. console.log(prompt);
  39. await tick();
  40. const chatInputContainerElement = document.getElementById('chat-input-container');
  41. const chatInputElement = document.getElementById('chat-input');
  42. if (chatInputContainerElement) {
  43. chatInputContainerElement.style.height = '';
  44. chatInputContainerElement.style.height =
  45. Math.min(chatInputContainerElement.scrollHeight, 200) + 'px';
  46. }
  47. await tick();
  48. if (chatInputElement) {
  49. chatInputElement.focus();
  50. chatInputElement.dispatchEvent(new Event('input'));
  51. }
  52. await tick();
  53. };
  54. let mounted = false;
  55. let selectedModelIdx = 0;
  56. $: if (selectedModels.length > 0) {
  57. selectedModelIdx = models.length - 1;
  58. }
  59. $: models = selectedModels.map((id) => $_models.find((m) => m.id === id));
  60. onMount(() => {
  61. mounted = true;
  62. });
  63. </script>
  64. {#key mounted}
  65. <div class="m-auto w-full max-w-6xl px-2 xl:px-20 translate-y-6 py-24 text-center">
  66. {#if $temporaryChatEnabled}
  67. <Tooltip
  68. content="This chat won't appear in history and your messages will not be saved."
  69. className="w-full flex justify-center mb-0.5"
  70. placement="top"
  71. >
  72. <div class="flex items-center gap-2 text-gray-500 font-medium text-lg my-2 w-fit">
  73. <EyeSlash strokeWidth="2.5" className="size-5" /> Temporary Chat
  74. </div>
  75. </Tooltip>
  76. {/if}
  77. <div
  78. class="w-full text-3xl text-gray-800 dark:text-gray-100 font-medium text-center flex items-center gap-4 font-primary"
  79. >
  80. <div class="w-full flex flex-col justify-center items-center">
  81. <div class="flex flex-row justify-center gap-3 sm:gap-3.5 w-fit px-5">
  82. <div class="flex flex-shrink-0 justify-center">
  83. <div class="flex -space-x-4 mb-0.5" in:fade={{ duration: 100 }}>
  84. {#each models as model, modelIdx}
  85. <Tooltip
  86. content={(models[modelIdx]?.info?.meta?.tags ?? [])
  87. .map((tag) => tag.name.toUpperCase())
  88. .join(', ')}
  89. placement="top"
  90. >
  91. <button
  92. on:click={() => {
  93. selectedModelIdx = modelIdx;
  94. }}
  95. >
  96. <img
  97. crossorigin="anonymous"
  98. src={model?.info?.meta?.profile_image_url ??
  99. ($i18n.language === 'dg-DG'
  100. ? `/doge.png`
  101. : `${WEBUI_BASE_URL}/static/favicon.png`)}
  102. class=" size-9 sm:size-10 rounded-full border-[1px] border-gray-200 dark:border-none"
  103. alt="logo"
  104. draggable="false"
  105. />
  106. </button>
  107. </Tooltip>
  108. {/each}
  109. </div>
  110. </div>
  111. <div class=" text-3xl sm:text-4xl line-clamp-1" in:fade={{ duration: 100 }}>
  112. {#if models[selectedModelIdx]?.name}
  113. {models[selectedModelIdx]?.name}
  114. {:else}
  115. {$i18n.t('Hello, {{name}}', { name: $user.name })}
  116. {/if}
  117. </div>
  118. </div>
  119. <div class="flex mt-1 mb-2">
  120. <div in:fade={{ duration: 100, delay: 50 }}>
  121. {#if models[selectedModelIdx]?.info?.meta?.description ?? null}
  122. <Tooltip
  123. className=" w-fit"
  124. content={marked.parse(
  125. sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description ?? '')
  126. )}
  127. placement="top"
  128. >
  129. <div
  130. class="mt-0.5 px-2 text-sm font-normal text-gray-500 dark:text-gray-400 line-clamp-2 max-w-xl markdown"
  131. >
  132. {@html marked.parse(
  133. sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description)
  134. )}
  135. </div>
  136. </Tooltip>
  137. {#if models[selectedModelIdx]?.info?.meta?.user}
  138. <div class="mt-0.5 text-sm font-normal text-gray-400 dark:text-gray-500">
  139. By
  140. {#if models[selectedModelIdx]?.info?.meta?.user.community}
  141. <a
  142. href="https://openwebui.com/m/{models[selectedModelIdx]?.info?.meta?.user
  143. .username}"
  144. >{models[selectedModelIdx]?.info?.meta?.user.name
  145. ? models[selectedModelIdx]?.info?.meta?.user.name
  146. : `@${models[selectedModelIdx]?.info?.meta?.user.username}`}</a
  147. >
  148. {:else}
  149. {models[selectedModelIdx]?.info?.meta?.user.name}
  150. {/if}
  151. </div>
  152. {/if}
  153. {/if}
  154. </div>
  155. </div>
  156. <div
  157. class="text-base font-normal xl:translate-x-6 md:max-w-3xl w-full py-3 {atSelectedModel
  158. ? 'mt-2'
  159. : ''}"
  160. >
  161. <MessageInput
  162. {history}
  163. {selectedModels}
  164. bind:files
  165. bind:prompt
  166. bind:autoScroll
  167. bind:selectedToolIds
  168. bind:webSearchEnabled
  169. bind:atSelectedModel
  170. {transparentBackground}
  171. {stopResponse}
  172. {createMessagePair}
  173. placeholder={$i18n.t('How can I help you today?')}
  174. on:upload={(e) => {
  175. dispatch('upload', e.detail);
  176. }}
  177. on:submit={(e) => {
  178. dispatch('submit', e.detail);
  179. }}
  180. />
  181. </div>
  182. </div>
  183. </div>
  184. <div class="mx-auto max-w-2xl font-primary" in:fade={{ duration: 200, delay: 200 }}>
  185. <div class="mx-5">
  186. <Suggestions
  187. suggestionPrompts={models[selectedModelIdx]?.info?.meta?.suggestion_prompts ??
  188. $config?.default_prompt_suggestions ??
  189. []}
  190. on:select={(e) => {
  191. selectSuggestionPrompt(e.detail);
  192. }}
  193. />
  194. </div>
  195. </div>
  196. </div>
  197. {/key}