index.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 items-center 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. {
  46. showModelType && modelItem.model_type && (
  47. <ModelBadge className={cn('ml-1', modelTypeClassName)}>
  48. {modelTypeFormat(modelItem.model_type)}
  49. </ModelBadge>
  50. )
  51. }
  52. {
  53. modelItem.model_properties.mode && showMode && (
  54. <ModelBadge className={cn('ml-1', modeClassName)}>
  55. {(modelItem.model_properties.mode as string).toLocaleUpperCase()}
  56. </ModelBadge>
  57. )
  58. }
  59. {
  60. showFeatures && modelItem.features?.map(feature => (
  61. <FeatureIcon
  62. key={feature}
  63. feature={feature}
  64. className={featuresClassName}
  65. />
  66. ))
  67. }
  68. {
  69. showContextSize && modelItem.model_properties.context_size && (
  70. <ModelBadge className='ml-1'>
  71. {sizeFormat(modelItem.model_properties.context_size as number)}
  72. </ModelBadge>
  73. )
  74. }
  75. {children}
  76. </div>
  77. )
  78. }
  79. export default ModelName