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

54 lines
1.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
2024-05-02 05:55:42 +00:00
import Bolt from '$lib/components/icons/Bolt.svelte';
2024-10-05 10:07:56 +00:00
import { onMount, getContext, createEventDispatcher } from 'svelte';
2024-05-07 06:43:25 +00:00
const i18n = getContext('i18n');
2024-10-05 10:07:56 +00:00
const dispatch = createEventDispatcher();
2024-05-02 05:55:42 +00:00
export let suggestionPrompts = [];
2024-10-06 18:52:19 +00:00
export let className = '';
2024-02-08 02:51:45 +00:00
let prompts = [];
2024-09-12 14:56:16 +00:00
$: prompts = (suggestionPrompts ?? [])
2024-05-01 00:07:03 +00:00
.reduce((acc, current) => [...acc, ...[current]], [])
.sort(() => Math.random() - 0.5);
</script>
2024-05-02 05:55:42 +00:00
{#if prompts.length > 0}
2024-10-05 20:26:52 +00:00
<div class="mb-1 flex gap-1 text-sm font-medium items-center text-gray-400 dark:text-gray-600">
2024-05-02 05:55:42 +00:00
<Bolt />
2024-05-07 06:43:25 +00:00
{$i18n.t('Suggested')}
2024-05-02 05:55:42 +00:00
</div>
{/if}
2024-10-06 18:52:19 +00:00
<div class=" h-40 max-h-full overflow-auto scrollbar-none {className}">
2024-10-05 10:07:56 +00: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-25 20:31:31 +00:00
</div>
2024-10-05 10:07:56 +00: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-25 20:31:31 +00:00
</div>
2024-05-02 06:01:00 +00:00
2024-10-05 10:07:56 +00:00
<div class="text-xs text-gray-500 font-normal line-clamp-1">Prompt</div>
{/if}
</div>
</button>
{/each}
</div>