import { ChatContext } from '@/app/chat-context'; import { apiInterceptors, getUsableModels } from '@/client/api'; import { MODEL_ICON_MAP } from '@/utils/constants'; import { CaretDownOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import { Select } from 'antd'; import Image from 'next/image'; import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './styles.module.css'; const DEFAULT_ICON_URL = '/models/huggingface.svg'; export function renderModelIcon(model?: string, props?: { width: number; height: number }) { const { width, height } = props || {}; if (!model) return null; return ( ); } const ModelSelector: React.FC = () => { const { t } = useTranslation(); const { model, setModel } = useContext(ChatContext); const [modelList, setModelList] = useState([]); useRequest(async () => await apiInterceptors(getUsableModels()), { onSuccess: data => { const [, res] = data; setModelList(res || []); }, }); if (modelList.length === 0) { return null; } return ( } onChange={val => { setModel(val); }} > {modelList.map(item => ( {renderModelIcon(item)} {MODEL_ICON_MAP[item]?.label || item} ))} ); }; export default ModelSelector;