Skip to content

Commit

Permalink
sort all models
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoMac1 committed Oct 9, 2024
1 parent 4de4b0d commit 8b83ea4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/lib/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export async function listModels(): Promise<Model[]> {
.catch(() => []);
const openaiModels = await new OpenAIStrategy().getModels().catch(() => []);

return [...ollamaModels, ...openaiModels];
return [...ollamaModels, ...openaiModels].sort((a, b) => {
const nameA = a.name;
const nameB = b.name;
// Compare ignoring case and accents
return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
});
}

export function getLastUsedModels(): Model[] {
Expand Down
10 changes: 1 addition & 9 deletions src/lib/chat/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,7 @@ export class OllamaStrategy implements ChatStrategy {
throw new Error('Failed to parse Ollama tags', { cause: data });
}

// Sort alphabetically and add the api property
data.models = data.models
.sort((a, b) => {
const nameA = a.name;
const nameB = b.name;
// Compare ignoring case and accents
return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
})
.map((model) => ({ ...model, api: 'ollama' }));
data.models = data.models.map((model) => ({ ...model, api: 'ollama' }));

return data;
}
Expand Down

0 comments on commit 8b83ea4

Please sign in to comment.