1
0

ManageModelsModal.svelte 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <script>
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher, getContext, onMount } from 'svelte';
  4. const i18n = getContext('i18n');
  5. const dispatch = createEventDispatcher();
  6. import { user } from '$lib/stores';
  7. import Modal from '$lib/components/common/Modal.svelte';
  8. import ManageOllama from './Manage/ManageOllama.svelte';
  9. import { getOllamaConfig } from '$lib/apis/ollama';
  10. import Spinner from '$lib/components/common/Spinner.svelte';
  11. import ManageMultipleOllama from './Manage/ManageMultipleOllama.svelte';
  12. export let show = false;
  13. let selected = null;
  14. let ollamaConfig = null;
  15. onMount(async () => {
  16. if ($user.role === 'admin') {
  17. await Promise.all([
  18. (async () => {
  19. ollamaConfig = await getOllamaConfig(localStorage.token);
  20. })()
  21. ]);
  22. if (ollamaConfig) {
  23. selected = 'ollama';
  24. return;
  25. }
  26. selected = '';
  27. }
  28. });
  29. </script>
  30. <Modal size="sm" bind:show>
  31. <div>
  32. <div class=" flex justify-between dark:text-gray-100 px-5 pt-4">
  33. <div class=" text-lg font-medium self-center font-primary">
  34. {$i18n.t('Manage Models')}
  35. </div>
  36. <button
  37. class="self-center"
  38. on:click={() => {
  39. show = false;
  40. }}
  41. >
  42. <svg
  43. xmlns="http://www.w3.org/2000/svg"
  44. viewBox="0 0 20 20"
  45. fill="currentColor"
  46. class="w-5 h-5"
  47. >
  48. <path
  49. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  50. />
  51. </svg>
  52. </button>
  53. </div>
  54. <div class="flex flex-col md:flex-row w-full px-3 pb-4 md:space-x-4 dark:text-gray-200">
  55. <div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
  56. {#if selected === ''}
  57. <div class=" py-5 text-gray-400 text-xs">
  58. <div>
  59. {$i18n.t('No inference engine with management support found')}
  60. </div>
  61. </div>
  62. {:else if selected !== null}
  63. <div class=" flex w-full flex-col">
  64. <div
  65. class="flex gap-1 scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-full bg-transparent dark:text-gray-200"
  66. >
  67. <button
  68. class="min-w-fit rounded-full p-1.5 {selected === 'ollama'
  69. ? ''
  70. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
  71. on:click={() => {
  72. selected = 'ollama';
  73. }}>{$i18n.t('Ollama')}</button
  74. >
  75. <!-- <button
  76. class="min-w-fit rounded-full p-1.5 {selected === 'llamacpp'
  77. ? ''
  78. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
  79. on:click={() => {
  80. selected = 'llamacpp';
  81. }}>{$i18n.t('Llama.cpp')}</button
  82. > -->
  83. </div>
  84. <div class=" px-1.5 py-1">
  85. {#if selected === 'ollama'}
  86. <ManageMultipleOllama {ollamaConfig} />
  87. {/if}
  88. </div>
  89. </div>
  90. {:else}
  91. <div class=" py-5">
  92. <Spinner />
  93. </div>
  94. {/if}
  95. </div>
  96. </div>
  97. </div>
  98. </Modal>