mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-30 23:28:35 +00:00
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: 谨欣 <echo.cmy@antgroup.com> Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com> Co-authored-by: yanzhiyong <932374019@qq.com>
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { ChatContext } from '@/app/chat-context';
|
|
import ModelIcon from '@/new-components/chat/content/ModelIcon';
|
|
import { SwapOutlined } from '@ant-design/icons';
|
|
import type { MenuProps } from 'antd';
|
|
import { Dropdown, Popover } from 'antd';
|
|
import React, { useContext, useMemo } from 'react';
|
|
import { MobileChatContext } from '../';
|
|
|
|
const ModelSelector: React.FC = () => {
|
|
const { modelList } = useContext(ChatContext);
|
|
const { model, setModel } = useContext(MobileChatContext);
|
|
|
|
const items: MenuProps['items'] = useMemo(() => {
|
|
if (modelList.length > 0) {
|
|
return modelList.map(item => {
|
|
return {
|
|
label: (
|
|
<div
|
|
className='flex items-center gap-2'
|
|
onClick={() => {
|
|
setModel(item);
|
|
}}
|
|
>
|
|
<ModelIcon width={14} height={14} model={item} />
|
|
<span className='text-xs'>{item}</span>
|
|
</div>
|
|
),
|
|
key: item,
|
|
};
|
|
});
|
|
}
|
|
return [];
|
|
}, [modelList, setModel]);
|
|
|
|
return (
|
|
<Dropdown
|
|
menu={{
|
|
items,
|
|
}}
|
|
placement='top'
|
|
trigger={['click']}
|
|
>
|
|
<Popover content={model}>
|
|
<div className='flex items-center gap-1 border rounded-xl bg-white dark:bg-black p-2 flex-shrink-0'>
|
|
<ModelIcon width={16} height={16} model={model} />
|
|
<span
|
|
className='text-xs font-medium line-clamp-1'
|
|
style={{
|
|
maxWidth: 96,
|
|
}}
|
|
>
|
|
{model}
|
|
</span>
|
|
<SwapOutlined rotate={90} />
|
|
</div>
|
|
</Popover>
|
|
</Dropdown>
|
|
);
|
|
};
|
|
|
|
export default ModelSelector;
|