index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 classNames 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
  39. className={`
  40. flex items-center truncate text-[13px] font-medium text-gray-800
  41. ${className}
  42. `}
  43. >
  44. <div
  45. className='truncate'
  46. title={modelItem.label[language] || modelItem.label.en_US}
  47. >
  48. {modelItem.label[language] || modelItem.label.en_US}
  49. </div>
  50. {
  51. showModelType && modelItem.model_type && (
  52. <ModelBadge className={classNames('ml-1', modelTypeClassName)}>
  53. {modelTypeFormat(modelItem.model_type)}
  54. </ModelBadge>
  55. )
  56. }
  57. {
  58. modelItem.model_properties.mode && showMode && (
  59. <ModelBadge className={classNames('ml-1', modeClassName)}>
  60. {(modelItem.model_properties.mode as string).toLocaleUpperCase()}
  61. </ModelBadge>
  62. )
  63. }
  64. {
  65. showFeatures && modelItem.features?.map(feature => (
  66. <FeatureIcon
  67. key={feature}
  68. feature={feature}
  69. className={featuresClassName}
  70. />
  71. ))
  72. }
  73. {
  74. showContextSize && modelItem.model_properties.context_size && (
  75. <ModelBadge className='ml-1'>
  76. {sizeFormat(modelItem.model_properties.context_size as number)}
  77. </ModelBadge>
  78. )
  79. }
  80. {children}
  81. </div>
  82. )
  83. }
  84. export default ModelName