model-list.tsx 3.4 KB

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