Commands.svelte 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script>
  2. import { createEventDispatcher } from 'svelte';
  3. import { toast } from 'svelte-sonner';
  4. const dispatch = createEventDispatcher();
  5. import Prompts from './Commands/Prompts.svelte';
  6. import Knowledge from './Commands/Knowledge.svelte';
  7. import Models from './Commands/Models.svelte';
  8. import { removeLastWordFromString } from '$lib/utils';
  9. import { processWeb, processYoutubeVideo } from '$lib/apis/retrieval';
  10. export let prompt = '';
  11. export let files = [];
  12. let commandElement = null;
  13. export const selectUp = () => {
  14. commandElement?.selectUp();
  15. };
  16. export const selectDown = () => {
  17. commandElement?.selectDown();
  18. };
  19. let command = '';
  20. $: command = (prompt?.trim() ?? '').split(' ')?.at(-1) ?? '';
  21. </script>
  22. {#if ['/', '#', '@'].includes(command?.charAt(0)) || '\\#' === command.slice(0, 2)}
  23. {#if command?.charAt(0) === '/'}
  24. <Prompts bind:this={commandElement} bind:prompt bind:files {command} />
  25. {:else if command?.charAt(0) === '#' || '\\#' === command.slice(0, 2)}
  26. <Knowledge
  27. bind:this={commandElement}
  28. bind:prompt
  29. command={command.includes('\\#') ? command.slice(2) : command}
  30. on:youtube={(e) => {
  31. console.log(e);
  32. dispatch('upload', {
  33. type: 'youtube',
  34. data: e.detail
  35. });
  36. }}
  37. on:url={(e) => {
  38. console.log(e);
  39. dispatch('upload', {
  40. type: 'web',
  41. data: e.detail
  42. });
  43. }}
  44. on:select={(e) => {
  45. console.log(e);
  46. files = [
  47. ...files,
  48. {
  49. ...e.detail,
  50. status: 'processed'
  51. }
  52. ];
  53. dispatch('select');
  54. }}
  55. />
  56. {:else if command?.charAt(0) === '@'}
  57. <Models
  58. bind:this={commandElement}
  59. {command}
  60. on:select={(e) => {
  61. prompt = removeLastWordFromString(prompt, command);
  62. dispatch('select', {
  63. type: 'model',
  64. data: e.detail
  65. });
  66. }}
  67. />
  68. {/if}
  69. {/if}