OllamaConnection.svelte 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script lang="ts">
  2. import { getContext, tick } from 'svelte';
  3. const i18n = getContext('i18n');
  4. import Tooltip from '$lib/components/common/Tooltip.svelte';
  5. import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
  6. import AddConnectionModal from '$lib/components/AddConnectionModal.svelte';
  7. import Cog6 from '$lib/components/icons/Cog6.svelte';
  8. import Wrench from '$lib/components/icons/Wrench.svelte';
  9. import ManageOllamaModal from './ManageOllamaModal.svelte';
  10. import ArrowDownTray from '$lib/components/icons/ArrowDownTray.svelte';
  11. export let onDelete = () => {};
  12. export let onSubmit = () => {};
  13. export let url = '';
  14. export let idx = 0;
  15. export let config = {};
  16. let showManageModal = false;
  17. let showConfigModal = false;
  18. </script>
  19. <AddConnectionModal
  20. ollama
  21. edit
  22. bind:show={showConfigModal}
  23. connection={{
  24. url,
  25. key: config?.key ?? '',
  26. config: config
  27. }}
  28. {onDelete}
  29. onSubmit={(connection) => {
  30. url = connection.url;
  31. config = { ...connection.config, key: connection.key };
  32. onSubmit(connection);
  33. }}
  34. />
  35. <ManageOllamaModal bind:show={showManageModal} urlIdx={idx} />
  36. <div class="flex gap-1.5">
  37. <Tooltip
  38. className="w-full relative"
  39. content={$i18n.t(`WebUI will make requests to "{{url}}/api/chat"`, {
  40. url
  41. })}
  42. placement="top-start"
  43. >
  44. {#if !(config?.enable ?? true)}
  45. <div
  46. class="absolute top-0 bottom-0 left-0 right-0 opacity-60 bg-white dark:bg-gray-900 z-10"
  47. ></div>
  48. {/if}
  49. <input
  50. class="w-full text-sm bg-transparent outline-none"
  51. placeholder={$i18n.t('Enter URL (e.g. http://localhost:11434)')}
  52. bind:value={url}
  53. />
  54. </Tooltip>
  55. <div class="flex gap-1">
  56. <Tooltip content={$i18n.t('Manage')} className="self-start">
  57. <button
  58. class="self-center p-1 bg-transparent hover:bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
  59. on:click={() => {
  60. showManageModal = true;
  61. }}
  62. type="button"
  63. >
  64. <ArrowDownTray />
  65. </button>
  66. </Tooltip>
  67. <Tooltip content={$i18n.t('Configure')} className="self-start">
  68. <button
  69. class="self-center p-1 bg-transparent hover:bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
  70. on:click={() => {
  71. showConfigModal = true;
  72. }}
  73. type="button"
  74. >
  75. <Cog6 />
  76. </button>
  77. </Tooltip>
  78. </div>
  79. </div>