open-webui/src/lib/components/chat/Suggestions.svelte

54 lines
1.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
2024-05-02 13:55:42 +08:00
import Bolt from '$lib/components/icons/Bolt.svelte';
2024-10-05 18:07:56 +08:00
import { onMount, getContext, createEventDispatcher } from 'svelte';
2024-05-07 14:43:25 +08:00
const i18n = getContext('i18n');
2024-10-05 18:07:56 +08:00
const dispatch = createEventDispatcher();
2024-05-02 13:55:42 +08:00
export let suggestionPrompts = [];
2024-10-07 02:52:19 +08:00
export let className = '';
2024-02-08 10:51:45 +08:00
let prompts = [];
2024-09-12 22:56:16 +08:00
$: prompts = (suggestionPrompts ?? [])
2024-05-01 08:07:03 +08:00
.reduce((acc, current) => [...acc, ...[current]], [])
.sort(() => Math.random() - 0.5);
</script>
2024-05-02 13:55:42 +08:00
{#if prompts.length > 0}
2024-10-06 04:26:52 +08:00
<div class="mb-1 flex gap-1 text-sm font-medium items-center text-gray-400 dark:text-gray-600">
2024-05-02 13:55:42 +08:00
<Bolt />
2024-05-07 14:43:25 +08:00
{$i18n.t('Suggested')}
2024-05-02 13:55:42 +08:00
</div>
{/if}
2024-10-07 02:52:19 +08:00
<div class=" h-40 max-h-full overflow-auto scrollbar-none {className}">
2024-10-05 18:07:56 +08:00
{#each prompts as prompt, promptIdx}
<button
class="flex flex-col flex-1 shrink-0 w-full justify-between px-3 py-2 rounded-xl bg-transparent hover:bg-black/5 dark:hover:bg-white/5 transition group"
on:click={() => {
dispatch('select', prompt.content);
}}
>
<div class="flex flex-col text-left">
{#if prompt.title && prompt.title[0] !== ''}
<div
class=" font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition line-clamp-1"
>
{prompt.title[0]}
2024-02-26 04:31:31 +08:00
</div>
2024-10-05 18:07:56 +08:00
<div class="text-xs text-gray-500 font-normal line-clamp-1">{prompt.title[1]}</div>
{:else}
<div
class=" font-medium dark:text-gray-300 dark:group-hover:text-gray-200 transition line-clamp-1"
>
{prompt.content}
2024-02-26 04:31:31 +08:00
</div>
2024-05-02 14:01:00 +08:00
2024-10-05 18:07:56 +08:00
<div class="text-xs text-gray-500 font-normal line-clamp-1">Prompt</div>
{/if}
</div>
</button>
{/each}
</div>