Files
eosphoros-ai--db-gpt/web/components/chat/header/model-selector.tsx
T
wehub-resource-sync d13100ebf3
Update draft releases / main (push) Has been cancelled
Build and push docs image / build-image (push) Has been cancelled
Build Web Application / build-web (macos-latest) (push) Has been cancelled
Build Web Application / build-web (ubuntu-latest) (push) Has been cancelled
Python Code Quality Checks / build (push) Has been cancelled
Test Python / test-python (macos-latest, 3.10) (push) Has been cancelled
Test Python / test-python (macos-latest, 3.11) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.10) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.11) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:27:08 +08:00

64 lines
1.6 KiB
TypeScript

/**
* multi-models selector
*/
import { ChatContext } from '@/app/chat-context';
import { MODEL_ICON_MAP } from '@/utils/constants';
import { Select } from 'antd';
import Image from 'next/image';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
interface Props {
onChange?: (model: string) => void;
}
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 (
<Image
className='rounded-full border border-gray-200 object-contain bg-white inline-block'
width={width || 24}
height={height || 24}
src={MODEL_ICON_MAP[model]?.icon || DEFAULT_ICON_URL}
key={MODEL_ICON_MAP[model]?.icon || DEFAULT_ICON_URL}
alt='llm'
/>
);
}
function ModelSelector({ onChange }: Props) {
const { t } = useTranslation();
const { modelList, model } = useContext(ChatContext);
if (!modelList || modelList.length <= 0) {
return null;
}
return (
<Select
value={model}
placeholder={t('choose_model')}
className='min-w-[120px]'
popupMatchSelectWidth={false}
onChange={val => {
onChange?.(val);
}}
>
{modelList.map(item => (
<Select.Option key={item} title={item}>
<div className='flex items-center'>
{renderModelIcon(item)}
<span className='ml-2'>{item}</span>
</div>
</Select.Option>
))}
</Select>
);
}
export default ModelSelector;