Placeholder.svelte 3.48 KB
Newer Older
1
<script lang="ts">
2
	import { WEBUI_BASE_URL } from '$lib/constants';
Timothy J. Baek's avatar
Timothy J. Baek committed
3
4
	import { marked } from 'marked';

5
	import { config, user, models as _models } from '$lib/stores';
6
	import { onMount, getContext } from 'svelte';
7
8
9

	import { blur, fade } from 'svelte/transition';

Timothy J. Baek's avatar
Timothy J. Baek committed
10
	import Suggestions from '../MessageInput/Suggestions.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
11
	import { sanitizeResponseContent } from '$lib/utils';
Timothy J. Baek's avatar
Timothy J. Baek committed
12
	import Tooltip from '$lib/components/common/Tooltip.svelte';
13
14

	const i18n = getContext('i18n');
15

16
	export let modelIds = [];
17
18
	export let models = [];

Timothy J. Baek's avatar
Timothy J. Baek committed
19
20
	export let submitPrompt;

21
	let mounted = false;
22
23
	let selectedModelIdx = 0;

24
	$: if (modelIds.length > 0) {
25
26
		selectedModelIdx = models.length - 1;
	}
27

28
29
	$: models = modelIds.map((id) => $_models.find((m) => m.id === id));

30
31
32
	onMount(() => {
		mounted = true;
	});
33
34
</script>

35
{#key mounted}
Timothy J. Baek's avatar
Timothy J. Baek committed
36
	<div class="m-auto w-full max-w-6xl px-8 lg:px-16 pb-10">
Timothy J. Baek's avatar
Timothy J. Baek committed
37
		<div class="flex justify-start">
38
			<div class="flex -space-x-4 mb-1" in:fade={{ duration: 200 }}>
Timothy J. Baek's avatar
Timothy J. Baek committed
39
40
41
42
43
44
				{#each models as model, modelIdx}
					<button
						on:click={() => {
							selectedModelIdx = modelIdx;
						}}
					>
Timothy J. Baek's avatar
Timothy J. Baek committed
45
46
						<Tooltip
							content={marked.parse(
Timothy J. Baek's avatar
fix  
Timothy J. Baek committed
47
								sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description ?? '')
Timothy J. Baek's avatar
Timothy J. Baek committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
							)}
							placement="right"
						>
							<img
								crossorigin="anonymous"
								src={model?.info?.meta?.profile_image_url ??
									($i18n.language === 'dg-DG'
										? `/doge.png`
										: `${WEBUI_BASE_URL}/static/favicon.png`)}
								class=" size-[2.7rem] rounded-full border-[1px] border-gray-200 dark:border-none"
								alt="logo"
								draggable="false"
							/>
						</Tooltip>
Timothy J. Baek's avatar
Timothy J. Baek committed
62
63
64
					</button>
				{/each}
			</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
65
66
		</div>

Timothy J. Baek's avatar
Timothy J. Baek committed
67
		<div
Timothy J. Baek's avatar
Timothy J. Baek committed
68
			class=" mt-2 mb-4 text-3xl text-gray-800 dark:text-gray-100 font-semibold text-left flex items-center gap-4"
Timothy J. Baek's avatar
Timothy J. Baek committed
69
70
		>
			<div>
71
				<div class=" capitalize line-clamp-1" in:fade={{ duration: 200 }}>
72
73
					{#if models[selectedModelIdx]?.info}
						{models[selectedModelIdx]?.info?.name}
74
75
					{:else}
						{$i18n.t('Hello, {{name}}', { name: $user.name })}
Timothy J. Baek's avatar
Timothy J. Baek committed
76
					{/if}
77
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
78

79
				<div in:fade={{ duration: 200, delay: 200 }}>
Timothy J. Baek's avatar
refac  
Timothy J. Baek committed
80
					{#if models[selectedModelIdx]?.info?.meta?.description ?? null}
Timothy J. Baek's avatar
Timothy J. Baek committed
81
82
83
						<div
							class="mt-0.5 text-base font-normal text-gray-500 dark:text-gray-400 line-clamp-3 markdown"
						>
Timothy J. Baek's avatar
Timothy J. Baek committed
84
85
86
							{@html marked.parse(
								sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description)
							)}
87
						</div>
88
						{#if models[selectedModelIdx]?.info?.meta?.user}
89
							<div class="mt-0.5 text-sm font-normal text-gray-400 dark:text-gray-500">
90
91
92
93
94
95
96
97
98
99
100
101
								By
								{#if models[selectedModelIdx]?.info?.meta?.user.community}
									<a
										href="https://openwebui.com/m/{models[selectedModelIdx]?.info?.meta?.user
											.username}"
										>{models[selectedModelIdx]?.info?.meta?.user.name
											? models[selectedModelIdx]?.info?.meta?.user.name
											: `@${models[selectedModelIdx]?.info?.meta?.user.username}`}</a
									>
								{:else}
									{models[selectedModelIdx]?.info?.meta?.user.name}
								{/if}
102
103
104
							</div>
						{/if}
					{:else}
Timothy J. Baek's avatar
Timothy J. Baek committed
105
						<div class=" font-medium text-gray-400 dark:text-gray-500 line-clamp-1">
106
107
108
109
							{$i18n.t('How can I help you today?')}
						</div>
					{/if}
				</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
110
			</div>
111
		</div>
Timothy J. Baek's avatar
Timothy J. Baek committed
112

113
		<div class=" w-full" in:fade={{ duration: 200, delay: 300 }}>
114
115
116
117
118
			<Suggestions
				suggestionPrompts={models[selectedModelIdx]?.info?.meta?.suggestion_prompts ??
					$config.default_prompt_suggestions}
				{submitPrompt}
			/>
Timothy J. Baek's avatar
Timothy J. Baek committed
119
		</div>
120
	</div>
121
{/key}