Connection.svelte 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Cog6 from '$lib/components/icons/Cog6.svelte';
  7. import AddConnectionModal from '$lib/components/AddConnectionModal.svelte';
  8. export let onDelete = () => {};
  9. export let onSubmit = () => {};
  10. export let pipeline = false;
  11. export let url = '';
  12. export let key = '';
  13. export let config = {};
  14. let showConfigModal = false;
  15. </script>
  16. <AddConnectionModal
  17. edit
  18. bind:show={showConfigModal}
  19. connection={{
  20. url,
  21. key,
  22. config
  23. }}
  24. {onDelete}
  25. onSubmit={(connection) => {
  26. url = connection.url;
  27. key = connection.key;
  28. config = connection.config;
  29. onSubmit(connection);
  30. }}
  31. />
  32. <div class="flex w-full gap-2 items-center">
  33. <Tooltip
  34. className="w-full relative"
  35. content={$i18n.t(`WebUI will make requests to "{{url}}/chat/completions"`, {
  36. url
  37. })}
  38. placement="top-start"
  39. >
  40. {#if !(config?.enable ?? true)}
  41. <div
  42. class="absolute top-0 bottom-0 left-0 right-0 opacity-60 bg-white dark:bg-gray-900 z-10"
  43. ></div>
  44. {/if}
  45. <div class="flex w-full">
  46. <div class="flex-1 relative">
  47. <input
  48. class=" outline-none w-full bg-transparent {pipeline ? 'pr-8' : ''}"
  49. placeholder={$i18n.t('API Base URL')}
  50. bind:value={url}
  51. autocomplete="off"
  52. />
  53. </div>
  54. <SensitiveInput
  55. inputClassName=" outline-none bg-transparent w-full"
  56. placeholder={$i18n.t('API Key')}
  57. bind:value={key}
  58. />
  59. </div>
  60. </Tooltip>
  61. <div class="flex gap-1">
  62. <Tooltip content={$i18n.t('Configure')} className="self-start">
  63. <button
  64. class="self-center p-1 bg-transparent hover:bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
  65. on:click={() => {
  66. showConfigModal = true;
  67. }}
  68. type="button"
  69. >
  70. <Cog6 />
  71. </button>
  72. </Tooltip>
  73. </div>
  74. </div>