model-list.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import type {
  4. CustomConfigrationModelFixedFields,
  5. ModelItem,
  6. ModelProvider,
  7. } from '../declarations'
  8. import {
  9. ConfigurateMethodEnum,
  10. ModelStatusEnum,
  11. } from '../declarations'
  12. import { useLanguage } from '../hooks'
  13. import ModelIcon from '../model-icon'
  14. import ModelName from '../model-name'
  15. // import Tab from './tab'
  16. import AddModelButton from './add-model-button'
  17. import Indicator from '@/app/components/header/indicator'
  18. import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
  19. import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows'
  20. import Button from '@/app/components/base/button'
  21. type ModelListProps = {
  22. provider: ModelProvider
  23. models: ModelItem[]
  24. onCollapse: () => void
  25. onConfig: (currentCustomConfigrationModelFixedFields?: CustomConfigrationModelFixedFields) => void
  26. }
  27. const ModelList: FC<ModelListProps> = ({
  28. provider,
  29. models,
  30. onCollapse,
  31. onConfig,
  32. }) => {
  33. const { t } = useTranslation()
  34. const language = useLanguage()
  35. const configurateMethods = provider.configurate_methods.filter(method => method !== ConfigurateMethodEnum.fetchFromRemote)
  36. const canCustomConfig = configurateMethods.includes(ConfigurateMethodEnum.customizableModel)
  37. // const canSystemConfig = configurateMethods.includes(ConfigurateMethodEnum.predefinedModel)
  38. return (
  39. <div className='px-2 pb-2 rounded-b-xl'>
  40. <div className='py-1 bg-white rounded-lg'>
  41. <div className='flex items-center pl-1 pr-[3px]'>
  42. <span className='group shrink-0 flex items-center mr-2'>
  43. <span className='group-hover:hidden pl-1 pr-1.5 h-6 leading-6 text-xs font-medium text-gray-500'>
  44. {t('common.modelProvider.modelsNum', { num: models.length })}
  45. </span>
  46. <span
  47. className={`
  48. hidden group-hover:inline-flex items-center pl-1 pr-1.5 h-6 bg-gray-50
  49. text-xs font-medium text-gray-500 cursor-pointer rounded-lg
  50. `}
  51. onClick={() => onCollapse()}
  52. >
  53. <ChevronDownDouble className='mr-0.5 w-3 h-3 rotate-180' />
  54. {t('common.modelProvider.collapse')}
  55. </span>
  56. </span>
  57. {/* {
  58. canCustomConfig && canSystemConfig && (
  59. <span className='flex items-center'>
  60. <Tab active='all' onSelect={() => {}} />
  61. </span>
  62. )
  63. } */}
  64. {
  65. canCustomConfig && (
  66. <div className='grow flex justify-end'>
  67. <AddModelButton onClick={() => onConfig()} />
  68. </div>
  69. )
  70. }
  71. </div>
  72. {
  73. models.map(model => (
  74. <div
  75. key={model.model}
  76. className={`
  77. group flex items-center pl-2 pr-2.5 h-8 rounded-lg
  78. ${canCustomConfig && 'hover:bg-gray-50'}
  79. ${model.deprecated && 'opacity-60'}
  80. `}
  81. >
  82. <ModelIcon
  83. className='shrink-0 mr-2'
  84. provider={provider}
  85. modelName={model.model}
  86. />
  87. <ModelName
  88. className='grow text-sm font-normal text-gray-900'
  89. modelItem={model}
  90. showModelType
  91. showMode
  92. showContextSize
  93. />
  94. <div className='shrink-0 flex items-center'>
  95. {
  96. model.fetch_from === ConfigurateMethodEnum.customizableModel && (
  97. <Button
  98. className='hidden group-hover:flex py-0 h-7 text-xs font-medium text-gray-700'
  99. onClick={() => onConfig({ __model_name: model.model, __model_type: model.model_type })}
  100. >
  101. <Settings01 className='mr-[5px] w-3.5 h-3.5' />
  102. {t('common.modelProvider.config')}
  103. </Button>
  104. )
  105. }
  106. <Indicator
  107. className='ml-2.5'
  108. color={model.status === ModelStatusEnum.active ? 'green' : 'gray'}
  109. />
  110. </div>
  111. </div>
  112. ))
  113. }
  114. </div>
  115. </div>
  116. )
  117. }
  118. export default ModelList