index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { useState } from 'react'
  2. import useSWR from 'swr'
  3. import { fetchProviders } from '@/service/common'
  4. import ProviderItem from './provider-item'
  5. import OpenaiHostedProvider from './openai-hosted-provider'
  6. import type { ProviderHosted } from '@/models/common'
  7. import { LockClosedIcon } from '@heroicons/react/24/solid'
  8. import { useTranslation } from 'react-i18next'
  9. import Link from 'next/link'
  10. import { IS_CE_EDITION } from '@/config'
  11. const providersMap: {[k: string]: any} = {
  12. 'openai-custom': {
  13. icon: 'openai',
  14. name: 'OpenAI',
  15. },
  16. 'azure_openai-custom': {
  17. icon: 'azure',
  18. name: 'Azure OpenAI Service',
  19. }
  20. }
  21. // const providersList = [
  22. // {
  23. // id: 'openai',
  24. // name: 'OpenAI',
  25. // providerKey: '1',
  26. // status: '',
  27. // child: <OpenaiProvider />
  28. // },
  29. // {
  30. // id: 'azure',
  31. // name: 'Azure OpenAI Service',
  32. // providerKey: '1',
  33. // status: 'error',
  34. // child: <AzureProvider />
  35. // },
  36. // {
  37. // id: 'anthropic',
  38. // name: 'Anthropic',
  39. // providerKey: '',
  40. // status: '',
  41. // child: <div>placeholder</div>
  42. // },
  43. // {
  44. // id: 'hugging-face',
  45. // name: 'Hugging Face Hub',
  46. // providerKey: '',
  47. // comingSoon: true,
  48. // status: '',
  49. // child: <div>placeholder</div>
  50. // }
  51. // ]
  52. const ProviderPage = () => {
  53. const { t } = useTranslation()
  54. const [activeProviderId, setActiveProviderId] = useState('')
  55. const { data, mutate } = useSWR({ url: '/workspaces/current/providers' }, fetchProviders)
  56. const providers = data?.filter(provider => providersMap[`${provider.provider_name}-${provider.provider_type}`])?.map(provider => {
  57. const providerKey = `${provider.provider_name}-${provider.provider_type}`
  58. return {
  59. provider,
  60. icon: providersMap[providerKey].icon,
  61. name: providersMap[providerKey].name,
  62. }
  63. })
  64. const providerHosted = data?.filter(provider => provider.provider_name === 'openai' && provider.provider_type === 'system')?.[0]
  65. return (
  66. <div className='pb-7'>
  67. {
  68. providerHosted && !IS_CE_EDITION && (
  69. <>
  70. <div>
  71. <OpenaiHostedProvider provider={providerHosted as ProviderHosted} />
  72. </div>
  73. <div className='my-5 w-full h-0 border-[0.5px] border-gray-100' />
  74. </>
  75. )
  76. }
  77. <div>
  78. {
  79. providers?.map(providerItem => (
  80. <ProviderItem
  81. key={`${providerItem.provider.provider_name}-${providerItem.provider.provider_type}`}
  82. icon={providerItem.icon}
  83. name={providerItem.name}
  84. provider={providerItem.provider}
  85. activeId={activeProviderId}
  86. onActive={aid => setActiveProviderId(aid)}
  87. onSave={() => mutate()}
  88. />
  89. ))
  90. }
  91. </div>
  92. <div className='absolute bottom-0 w-full h-[42px] flex items-center bg-white text-xs text-gray-500'>
  93. <LockClosedIcon className='w-3 h-3 mr-1' />
  94. {t('common.provider.encrypted.front')}
  95. <Link
  96. className='text-primary-600 mx-1'
  97. target={'_blank'}
  98. href='https://pycryptodome.readthedocs.io/en/latest/src/cipher/oaep.html'
  99. >
  100. PKCS1_OAEP
  101. </Link>
  102. {t('common.provider.encrypted.back')}
  103. </div>
  104. </div>
  105. )
  106. }
  107. export default ProviderPage