model-list.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type { FC } from 'react'
  2. import { useCallback } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import type {
  5. CustomConfigurationModelFixedFields,
  6. ModelItem,
  7. ModelProvider,
  8. } from '../declarations'
  9. import {
  10. ConfigurationMethodEnum,
  11. } from '../declarations'
  12. // import Tab from './tab'
  13. import AddModelButton from './add-model-button'
  14. import ModelListItem from './model-list-item'
  15. import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows'
  16. import { useModalContextSelector } from '@/context/modal-context'
  17. type ModelListProps = {
  18. provider: ModelProvider
  19. models: ModelItem[]
  20. onCollapse: () => void
  21. onConfig: (currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields) => void
  22. onChange?: (provider: string) => void
  23. }
  24. const ModelList: FC<ModelListProps> = ({
  25. provider,
  26. models,
  27. onCollapse,
  28. onConfig,
  29. onChange,
  30. }) => {
  31. const { t } = useTranslation()
  32. const configurativeMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
  33. const isConfigurable = configurativeMethods.includes(ConfigurationMethodEnum.customizableModel)
  34. const setShowModelLoadBalancingModal = useModalContextSelector(state => state.setShowModelLoadBalancingModal)
  35. const onModifyLoadBalancing = useCallback((model: ModelItem) => {
  36. setShowModelLoadBalancingModal({
  37. provider,
  38. model: model!,
  39. open: !!model,
  40. onClose: () => setShowModelLoadBalancingModal(null),
  41. onSave: onChange,
  42. })
  43. }, [onChange, provider, setShowModelLoadBalancingModal])
  44. return (
  45. <div className='px-2 pb-2 rounded-b-xl'>
  46. <div className='py-1 bg-white rounded-lg'>
  47. <div className='flex items-center pl-1 pr-[3px]'>
  48. <span className='group shrink-0 flex items-center mr-2'>
  49. <span className='group-hover:hidden pl-1 pr-1.5 h-6 leading-6 text-xs font-medium text-gray-500'>
  50. {t('common.modelProvider.modelsNum', { num: models.length })}
  51. </span>
  52. <span
  53. className='hidden group-hover:inline-flex items-center pl-1 pr-1.5 h-6 text-xs font-medium text-gray-500 bg-gray-50 cursor-pointer rounded-lg'
  54. onClick={() => onCollapse()}
  55. >
  56. <ChevronDownDouble className='mr-0.5 w-3 h-3 rotate-180' />
  57. {t('common.modelProvider.collapse')}
  58. </span>
  59. </span>
  60. {/* {
  61. isConfigurable && canSystemConfig && (
  62. <span className='flex items-center'>
  63. <Tab active='all' onSelect={() => {}} />
  64. </span>
  65. )
  66. } */}
  67. {
  68. isConfigurable && (
  69. <div className='grow flex justify-end'>
  70. <AddModelButton onClick={() => onConfig()} />
  71. </div>
  72. )
  73. }
  74. </div>
  75. {
  76. models.map(model => (
  77. <ModelListItem
  78. key={model.model}
  79. {...{
  80. model,
  81. provider,
  82. isConfigurable,
  83. onConfig,
  84. onModifyLoadBalancing,
  85. }}
  86. />
  87. ))
  88. }
  89. </div>
  90. </div>
  91. )
  92. }
  93. export default ModelList