index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import type { FC, PropsWithChildren } from 'react'
  2. import {
  3. modelTypeFormat,
  4. sizeFormat,
  5. } from '../utils'
  6. import { useLanguage } from '../hooks'
  7. import type { ModelItem } from '../declarations'
  8. import ModelBadge from '../model-badge'
  9. import FeatureIcon from '../model-selector/feature-icon'
  10. import cn from '@/utils/classnames'
  11. type ModelNameProps = PropsWithChildren<{
  12. modelItem: ModelItem
  13. className?: string
  14. showModelType?: boolean
  15. modelTypeClassName?: string
  16. showMode?: boolean
  17. modeClassName?: string
  18. showFeatures?: boolean
  19. featuresClassName?: string
  20. showContextSize?: boolean
  21. }>
  22. const ModelName: FC<ModelNameProps> = ({
  23. modelItem,
  24. className,
  25. showModelType,
  26. modelTypeClassName,
  27. showMode,
  28. modeClassName,
  29. showFeatures,
  30. featuresClassName,
  31. showContextSize,
  32. children,
  33. }) => {
  34. const language = useLanguage()
  35. if (!modelItem)
  36. return null
  37. return (
  38. <div className={cn('flex gap-0.5 items-center overflow-hidden text-ellipsis truncate text-components-input-text-filled system-sm-regular', className)}>
  39. <div
  40. className='truncate'
  41. title={modelItem.label[language] || modelItem.label.en_US}
  42. >
  43. {modelItem.label[language] || modelItem.label.en_US}
  44. </div>
  45. <div className='flex items-center gap-0.5'>
  46. {
  47. showModelType && modelItem.model_type && (
  48. <ModelBadge className={modelTypeClassName}>
  49. {modelTypeFormat(modelItem.model_type)}
  50. </ModelBadge>
  51. )
  52. }
  53. {
  54. modelItem.model_properties.mode && showMode && (
  55. <ModelBadge className={modeClassName}>
  56. {(modelItem.model_properties.mode as string).toLocaleUpperCase()}
  57. </ModelBadge>
  58. )
  59. }
  60. {
  61. showFeatures && modelItem.features?.map(feature => (
  62. <FeatureIcon
  63. key={feature}
  64. feature={feature}
  65. className={featuresClassName}
  66. />
  67. ))
  68. }
  69. {
  70. showContextSize && modelItem.model_properties.context_size && (
  71. <ModelBadge>
  72. {sizeFormat(modelItem.model_properties.context_size as number)}
  73. </ModelBadge>
  74. )
  75. }
  76. </div>
  77. {children}
  78. </div>
  79. )
  80. }
  81. export default ModelName