ModelIcon.tsx 965 B

12345678910111213141516171819202122232425262728293031323334
  1. import { MODEL_ICON_DICT } from '@/utils/constants';
  2. import Image from 'next/image';
  3. import React, { memo, useMemo } from 'react';
  4. const DEFAULT_ICON_URL = '/models/huggingface.svg';
  5. const ModelIcon: React.FC<{ width?: number; height?: number; model?: string }> = ({ width, height, model }) => {
  6. const iconSrc = useMemo(() => {
  7. const formatterModal = model?.replaceAll('-', '_').split('_')[0];
  8. const dict = Object.keys(MODEL_ICON_DICT);
  9. for (let i = 0; i < dict.length; i++) {
  10. const element = dict[i];
  11. if (formatterModal?.includes(element)) {
  12. return MODEL_ICON_DICT[element];
  13. }
  14. }
  15. return DEFAULT_ICON_URL;
  16. }, [model]);
  17. if (!model) return null;
  18. return (
  19. <Image
  20. className='rounded-full border border-gray-200 object-contain bg-white inline-block'
  21. width={width || 24}
  22. height={height || 24}
  23. src={iconSrc}
  24. alt='llm'
  25. priority
  26. />
  27. );
  28. };
  29. export default memo(ModelIcon);