index.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type { FC } from 'react'
  2. import type {
  3. Model,
  4. ModelProvider,
  5. } from '../declarations'
  6. import { useLanguage } from '../hooks'
  7. import { Group } from '@/app/components/base/icons/src/vender/other'
  8. import { OpenaiBlue, OpenaiTeal, OpenaiViolet, OpenaiYellow } from '@/app/components/base/icons/src/public/llm'
  9. import cn from '@/utils/classnames'
  10. import { renderI18nObject } from '@/i18n-config'
  11. type ModelIconProps = {
  12. provider?: Model | ModelProvider
  13. modelName?: string
  14. className?: string
  15. iconClassName?: string
  16. isDeprecated?: boolean
  17. }
  18. const ModelIcon: FC<ModelIconProps> = ({
  19. provider,
  20. className,
  21. modelName,
  22. iconClassName,
  23. isDeprecated = false,
  24. }) => {
  25. const language = useLanguage()
  26. if (provider?.provider && ['openai', 'langgenius/openai/openai'].includes(provider.provider) && modelName?.startsWith('o'))
  27. return <div className='flex items-center justify-center'><OpenaiYellow className={cn('h-5 w-5', className)} /></div>
  28. if (provider?.provider && ['openai', 'langgenius/openai/openai'].includes(provider.provider) && modelName?.includes('gpt-4.1'))
  29. return <div className='flex items-center justify-center'><OpenaiTeal className={cn('h-5 w-5', className)} /></div>
  30. if (provider?.provider && ['openai', 'langgenius/openai/openai'].includes(provider.provider) && modelName?.includes('gpt-4o'))
  31. return <div className='flex items-center justify-center'><OpenaiBlue className={cn('h-5 w-5', className)} /></div>
  32. if (provider?.provider && ['openai', 'langgenius/openai/openai'].includes(provider.provider) && modelName?.startsWith('gpt-4'))
  33. return <div className='flex items-center justify-center'><OpenaiViolet className={cn('h-5 w-5', className)} /></div>
  34. if (provider?.icon_small) {
  35. return (
  36. <div className={cn('flex h-5 w-5 items-center justify-center', isDeprecated && 'opacity-50', className)}>
  37. <img alt='model-icon' src={renderI18nObject(provider.icon_small, language)} className={iconClassName} />
  38. </div>
  39. )
  40. }
  41. return (
  42. <div className={cn(
  43. 'flex h-5 w-5 items-center justify-center rounded-md border-[0.5px] border-components-panel-border-subtle bg-background-default-subtle',
  44. className,
  45. )}>
  46. <div className={cn('flex h-5 w-5 items-center justify-center opacity-35', iconClassName)}>
  47. <Group className='h-3 w-3 text-text-tertiary' />
  48. </div>
  49. </div>
  50. )
  51. }
  52. export default ModelIcon