Download src/components/panels/ModelPicker.jsx from cheumk/studio: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/cheumk/studio/resolve/main/src/components/panels/ModelPicker.jsx
- Command line
-
hf download hf://spaces/cheumk/studio/src/components/panels/ModelPicker.jsx
-
curl -L -o ModelPicker.jsx https://huggingface.co/spaces/cheumk/studio/resolve/main/src/components/panels/ModelPicker.jsx
2.05 kB
| import { useStore } from '../../store/useStore' | |
| import { Field, inputCls } from '../ui' | |
| /** 供應商 + 模型選擇(模型可從清單選,也可手動輸入) */ | |
| export default function ModelPicker({ label = '模型', providerId, model, onChange }) { | |
| const providers = useStore((s) => s.providers) | |
| const provider = providers.find((p) => p.id === providerId) | |
| const listId = `models-${providerId}` | |
| return ( | |
| <Field label={label} hint={provider && !provider.models?.length ? '這個供應商還沒有模型清單,可直接輸入模型 id,或到「模型」頁按抓取。' : undefined}> | |
| <div className="space-y-2"> | |
| <select | |
| className={inputCls} | |
| value={provider ? providerId : ''} | |
| onChange={(e) => { | |
| const p = providers.find((x) => x.id === e.target.value) | |
| onChange(e.target.value, p?.models?.includes(model) ? model : p?.models?.[0] || '') | |
| }} | |
| > | |
| <option value="" disabled>選擇供應商…</option> | |
| {providers.map((p) => ( | |
| <option key={p.id} value={p.id}> | |
| {p.name}{!p.noKey && !p.apiKey ? '(未填金鑰)' : ''} | |
| </option> | |
| ))} | |
| </select> | |
| <input | |
| className={inputCls} | |
| list={listId} | |
| value={model || ''} | |
| onChange={(e) => onChange(providerId, e.target.value)} | |
| placeholder="模型 id,例如 openai/gpt-4o-mini" | |
| disabled={!provider} | |
| /> | |
| <datalist id={listId}> | |
| {(provider?.models || []).map((m) => <option key={m} value={m} />)} | |
| </datalist> | |
| {provider?.models?.length > 0 && ( | |
| <select className={inputCls} value={provider.models.includes(model) ? model : ''} onChange={(e) => onChange(providerId, e.target.value)}> | |
| <option value="" disabled>從清單選({provider.models.length} 個)…</option> | |
| {provider.models.map((m) => <option key={m} value={m}>{m}</option>)} | |
| </select> | |
| )} | |
| </div> | |
| </Field> | |
| ) | |
| } | |