OpenAIConnection.svelte 3.1 KB

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