open-webui/src/lib/components/chat/MessageInput/Commands.svelte

81 lines
1.7 KiB
Svelte
Raw Normal View History

2024-08-23 12:31:39 +00:00
<script>
import { createEventDispatcher } from 'svelte';
import { toast } from 'svelte-sonner';
const dispatch = createEventDispatcher();
import Prompts from './Commands/Prompts.svelte';
2024-10-02 05:45:04 +00:00
import Knowledge from './Commands/Knowledge.svelte';
2024-08-23 12:31:39 +00:00
import Models from './Commands/Models.svelte';
import { removeLastWordFromString } from '$lib/utils';
2024-09-28 00:23:09 +00:00
import { processWeb, processYoutubeVideo } from '$lib/apis/retrieval';
2024-08-23 12:31:39 +00:00
export let prompt = '';
export let files = [];
let commandElement = null;
export const selectUp = () => {
commandElement?.selectUp();
};
export const selectDown = () => {
commandElement?.selectDown();
};
let command = '';
$: command = (prompt?.trim() ?? '').split(' ')?.at(-1) ?? '';
</script>
{#if ['/', '#', '@'].includes(command?.charAt(0))}
{#if command?.charAt(0) === '/'}
<Prompts bind:this={commandElement} bind:prompt bind:files {command} />
{:else if command?.charAt(0) === '#'}
2024-10-02 05:45:04 +00:00
<Knowledge
2024-08-23 12:31:39 +00:00
bind:this={commandElement}
bind:prompt
{command}
on:youtube={(e) => {
console.log(e);
2024-10-08 01:19:13 +00:00
dispatch('upload', {
type: 'youtube',
data: e.detail
});
2024-08-23 12:31:39 +00:00
}}
on:url={(e) => {
console.log(e);
2024-10-08 01:19:13 +00:00
dispatch('upload', {
type: 'web',
data: e.detail
});
2024-08-23 12:31:39 +00:00
}}
on:select={(e) => {
console.log(e);
files = [
...files,
{
...e.detail,
status: 'processed'
}
];
dispatch('select');
}}
/>
{:else if command?.charAt(0) === '@'}
<Models
bind:this={commandElement}
{command}
on:select={(e) => {
prompt = removeLastWordFromString(prompt, command);
dispatch('select', {
type: 'model',
data: e.detail
});
}}
/>
{/if}
{/if}