OpenAIConnection.svelte 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 './AddConnectionModal.svelte';
  8. import { connect } from 'socket.io-client';
  9. export let onDelete = () => {};
  10. export let onSubmit = () => {};
  11. export let pipeline = false;
  12. export let url = '';
  13. export let key = '';
  14. export let config = {};
  15. let showConfigModal = false;
  16. </script>
  17. <AddConnectionModal
  18. edit
  19. bind:show={showConfigModal}
  20. connection={{
  21. url,
  22. key,
  23. config
  24. }}
  25. {onDelete}
  26. onSubmit={(connection) => {
  27. url = connection.url;
  28. key = connection.key;
  29. config = connection.config;
  30. onSubmit(connection);
  31. }}
  32. />
  33. <div class="flex w-full gap-2 items-center">
  34. <Tooltip
  35. className="w-full relative"
  36. content={$i18n.t(`WebUI will make requests to "{{url}}/chat/completions"`, {
  37. url
  38. })}
  39. placement="top-start"
  40. >
  41. {#if !(config?.enable ?? true)}
  42. <div
  43. class="absolute top-0 bottom-0 left-0 right-0 opacity-60 bg-white dark:bg-gray-900 z-10"
  44. ></div>
  45. {/if}
  46. <div class="flex w-full">
  47. <div class="flex-1 relative">
  48. <input
  49. class=" outline-none w-full bg-transparent {pipeline ? 'pr-8' : ''}"
  50. placeholder={$i18n.t('API Base URL')}
  51. bind:value={url}
  52. autocomplete="off"
  53. />
  54. {#if pipeline}
  55. <div class=" absolute top-0.5 right-2.5">
  56. <Tooltip content="Pipelines">
  57. <svg
  58. xmlns="http://www.w3.org/2000/svg"
  59. viewBox="0 0 24 24"
  60. fill="currentColor"
  61. class="size-4"
  62. >
  63. <path
  64. d="M11.644 1.59a.75.75 0 0 1 .712 0l9.75 5.25a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.712 0l-9.75-5.25a.75.75 0 0 1 0-1.32l9.75-5.25Z"
  65. />
  66. <path
  67. d="m3.265 10.602 7.668 4.129a2.25 2.25 0 0 0 2.134 0l7.668-4.13 1.37.739a.75.75 0 0 1 0 1.32l-9.75 5.25a.75.75 0 0 1-.71 0l-9.75-5.25a.75.75 0 0 1 0-1.32l1.37-.738Z"
  68. />
  69. <path
  70. d="m10.933 19.231-7.668-4.13-1.37.739a.75.75 0 0 0 0 1.32l9.75 5.25c.221.12.489.12.71 0l9.75-5.25a.75.75 0 0 0 0-1.32l-1.37-.738-7.668 4.13a2.25 2.25 0 0 1-2.134-.001Z"
  71. />
  72. </svg>
  73. </Tooltip>
  74. </div>
  75. {/if}
  76. </div>
  77. <SensitiveInput
  78. inputClassName=" outline-none bg-transparent w-full"
  79. placeholder={$i18n.t('API Key')}
  80. bind:value={key}
  81. />
  82. </div>
  83. </Tooltip>
  84. <div class="flex gap-1">
  85. <Tooltip content={$i18n.t('Configure')} className="self-start">
  86. <button
  87. class="self-center p-1 bg-transparent hover:bg-gray-100 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
  88. on:click={() => {
  89. showConfigModal = true;
  90. }}
  91. type="button"
  92. >
  93. <Cog6 />
  94. </button>
  95. </Tooltip>
  96. </div>
  97. </div>