Card.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import Indicator from '../../../indicator'
  4. import Selector from '../selector'
  5. import type { Model, ProviderEnum } from '../declarations'
  6. import { ProviderEnum as ProviderEnumValue } from '../declarations'
  7. import Button from '@/app/components/base/button'
  8. type CardProps = {
  9. providerType: ProviderEnum
  10. models: Model[]
  11. onOpenModal: (v: Omit<Model, 'config'> & Model['config']) => void
  12. onOperate: (v: Record<string, any>) => void
  13. }
  14. const Card: FC<CardProps> = ({
  15. providerType,
  16. models,
  17. onOpenModal,
  18. onOperate,
  19. }) => {
  20. const { t } = useTranslation()
  21. const renderDesc = (model: Model) => {
  22. if (providerType === ProviderEnumValue.azure_openai)
  23. return model.config.openai_api_base
  24. if (providerType === ProviderEnumValue.replicate)
  25. return `version: ${model.config.model_version}`
  26. if (providerType === ProviderEnumValue.huggingface_hub)
  27. return model.config.huggingfacehub_endpoint_url
  28. }
  29. return (
  30. <div className='px-3 pb-3'>
  31. {
  32. models.map(model => (
  33. <div key={`${model.model_name}-${model.model_type}`} className='flex mb-1 px-3 py-2 bg-white rounded-lg shadow-xs last:mb-0'>
  34. <div className='grow'>
  35. <div className='flex items-center mb-0.5 h-[18px] text-[13px] font-medium text-gray-700'>
  36. {model.model_name}
  37. <div className='ml-2 px-1.5 rounded-md border border-[rgba(0,0,0,0.08)] text-xs text-gray-600'>{model.model_type}</div>
  38. </div>
  39. <div className='text-xs text-gray-500'>
  40. {renderDesc(model)}
  41. </div>
  42. </div>
  43. <div className='flex items-center'>
  44. <Indicator className='mr-3' />
  45. <Button
  46. className='mr-1 !px-3 !h-7 rounded-md bg-white !text-xs font-medium text-gray-700'
  47. onClick={() => onOpenModal({ model_name: model.model_name, model_type: model.model_type, ...model.config })}
  48. >
  49. {t('common.operation.edit')}
  50. </Button>
  51. <Selector
  52. hiddenOptions
  53. onOperate={v => onOperate({ ...v, value: model })}
  54. className={open => `${open && '!bg-gray-100 shadow-none'} flex justify-center items-center w-7 h-7 bg-white rounded-md border-[0.5px] border-gray-200 shadow-xs cursor-pointer hover:bg-gray-100`}
  55. deleteText={t('common.operation.remove') || ''}
  56. />
  57. </div>
  58. </div>
  59. ))
  60. }
  61. </div>
  62. )
  63. }
  64. export default Card