1
0
Fork 0

Group models

This commit is contained in:
Pabloader 2026-03-22 06:42:47 +00:00
parent 7f3e628954
commit e72cd513e5
1 changed files with 33 additions and 4 deletions

View File

@ -41,7 +41,30 @@ export const SettingsModal = ({ onClose }: Props) => {
const modelsData = useQuery(fetchModels, connectionToFetch); const modelsData = useQuery(fetchModels, connectionToFetch);
const isLoadingModels = connectionToFetch != null && modelsData == undefined; const isLoadingModels = connectionToFetch != null && modelsData == undefined;
const models = modelsData ?? []; const groupedModels = useMemo(() => {
const sorted = (modelsData ?? []).sort((a, b) => {
// Sort by tool support first (true before false)
if (a.support_tools !== b.support_tools) {
return a.support_tools ? -1 : 1;
}
// Then by max context (bigger first, undefined treated as 0)
const aContext = a.max_context ?? 0;
const bContext = b.max_context ?? 0;
if (aContext !== bContext) {
return bContext - aContext;
}
// Then by name (alphabetically)
return a.id.localeCompare(b.id);
});
// Group by context size
const groups = Map.groupBy(sorted, m => m.max_context ?? 0);
// Convert to array sorted by context size (bigger first)
return Array.from(groups.entries())
.sort((a, b) => b[0] - a[0])
.map(([context, models]) => ({ context, models }));
}, [modelsData]);
const handleBlur = () => { const handleBlur = () => {
if (url && apiKey) { if (url && apiKey) {
@ -119,15 +142,21 @@ export const SettingsModal = ({ onClose }: Props) => {
{connectionToTest ? ( {connectionToTest ? (
isLoadingModels ? ( isLoadingModels ? (
<p>Loading models...</p> <p>Loading models...</p>
) : models.length > 0 ? ( ) : groupedModels.length > 0 ? (
<select <select
value={selectedModel} value={selectedModel}
onChange={setSelectedModel} onChange={setSelectedModel}
class={styles.select} class={styles.select}
> >
<option value="">Select a model</option> <option value="">Select a model</option>
{models.map(m => ( {groupedModels.map(({ context, models }) => (
<option key={m.id} value={m.id}>{m.id}</option> <optgroup key={context} label={`${context} context`}>
{models.map(m => (
<option key={m.id} value={m.id}>
{m.support_tools ? '🔧 ' : ''}{m.id} {m.max_length ? `(len: ${m.max_length})` : ''}
</option>
))}
</optgroup>
))} ))}
</select> </select>
) : ( ) : (