quota-panel.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import type { ModelProvider } from '../declarations'
  4. import {
  5. CustomConfigurationStatusEnum,
  6. PreferredProviderTypeEnum,
  7. QuotaUnitEnum,
  8. } from '../declarations'
  9. import {
  10. MODEL_PROVIDER_QUOTA_GET_PAID,
  11. } from '../utils'
  12. import PriorityUseTip from './priority-use-tip'
  13. import Tooltip from '@/app/components/base/tooltip'
  14. import { formatNumber } from '@/utils/format'
  15. type QuotaPanelProps = {
  16. provider: ModelProvider
  17. }
  18. const QuotaPanel: FC<QuotaPanelProps> = ({
  19. provider,
  20. }) => {
  21. const { t } = useTranslation()
  22. const customConfig = provider.custom_configuration
  23. const priorityUseType = provider.preferred_provider_type
  24. const systemConfig = provider.system_configuration
  25. const currentQuota = systemConfig.enabled && systemConfig.quota_configurations.find(item => item.quota_type === systemConfig.current_quota_type)
  26. const openaiOrAnthropic = MODEL_PROVIDER_QUOTA_GET_PAID.includes(provider.provider)
  27. return (
  28. <div className='group relative shrink-0 min-w-[112px] px-3 py-2 rounded-lg bg-white/[0.3] border-[0.5px] border-black/5'>
  29. <div className='flex items-center mb-2 h-4 text-xs font-medium text-gray-500'>
  30. {t('common.modelProvider.quota')}
  31. <Tooltip popupContent={
  32. openaiOrAnthropic
  33. ? t('common.modelProvider.card.tip')
  34. : t('common.modelProvider.quotaTip')
  35. }
  36. />
  37. </div>
  38. {
  39. currentQuota && (
  40. <div className='flex items-center h-4 text-xs text-gray-500'>
  41. <span className='mr-0.5 text-sm font-semibold text-gray-700'>{formatNumber((currentQuota?.quota_limit || 0) - (currentQuota?.quota_used || 0))}</span>
  42. {
  43. currentQuota?.quota_unit === QuotaUnitEnum.tokens && 'Tokens'
  44. }
  45. {
  46. currentQuota?.quota_unit === QuotaUnitEnum.times && t('common.modelProvider.callTimes')
  47. }
  48. {
  49. currentQuota?.quota_unit === QuotaUnitEnum.credits && t('common.modelProvider.credits')
  50. }
  51. </div>
  52. )
  53. }
  54. {
  55. priorityUseType === PreferredProviderTypeEnum.system && customConfig.status === CustomConfigurationStatusEnum.active && (
  56. <PriorityUseTip />
  57. )
  58. }
  59. </div>
  60. )
  61. }
  62. export default QuotaPanel