ModelSwitcher.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { ChatContext } from '@/app/chat-context';
  2. import { ChatContentContext } from '@/pages/chat';
  3. import { SettingOutlined } from '@ant-design/icons';
  4. import { Select, Tooltip } from 'antd';
  5. import React, { memo, useContext, useMemo } from 'react';
  6. import { useTranslation } from 'react-i18next';
  7. import ModelIcon from '../content/ModelIcon';
  8. const ModelSwitcher: React.FC = () => {
  9. const { modelList } = useContext(ChatContext);
  10. const { appInfo, modelValue, setModelValue } = useContext(ChatContentContext);
  11. const { t } = useTranslation();
  12. // 左边工具栏动态可用key
  13. const paramKey: string[] = useMemo(() => {
  14. return appInfo.param_need?.map(i => i.type) || [];
  15. }, [appInfo.param_need]);
  16. if (!paramKey.includes('model')) {
  17. return (
  18. <Tooltip title={t('model_tip')}>
  19. <div className='flex w-8 h-8 items-center justify-center rounded-md hover:bg-[rgb(221,221,221,0.6)]'>
  20. <SettingOutlined className='text-xl cursor-not-allowed opacity-30' />
  21. </div>
  22. </Tooltip>
  23. );
  24. }
  25. return (
  26. <Select
  27. value={modelValue}
  28. placeholder={t('choose_model')}
  29. className='h-8 rounded-3xl'
  30. onChange={val => {
  31. setModelValue(val);
  32. }}
  33. popupMatchSelectWidth={300}
  34. >
  35. {modelList.map(item => (
  36. <Select.Option key={item}>
  37. <div className='flex items-center'>
  38. <ModelIcon model={item} />
  39. <span className='ml-2'>{item}</span>
  40. </div>
  41. </Select.Option>
  42. ))}
  43. </Select>
  44. );
  45. };
  46. export default memo(ModelSwitcher);