From 2d8f4f62b03b633e2f6456ca4294ade5e575ff10 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lopes" <26071571+TGlide@users.noreply.github.com> Date: Wed, 18 Jun 2025 11:14:38 +0100 Subject: [PATCH] better model name formatting --- src/lib/utils/strings.ts | 4 ++++ src/routes/chat/model-picker.svelte | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/lib/utils/strings.ts b/src/lib/utils/strings.ts index 0eda173..dac8490 100644 --- a/src/lib/utils/strings.ts +++ b/src/lib/utils/strings.ts @@ -6,3 +6,7 @@ export function getFirstSentence(text: string): [string | null, string] { return [text.slice(0, index + 1), text]; } + +export function capitalize(text: string): string { + return text.charAt(0).toUpperCase() + text.slice(1); +} diff --git a/src/routes/chat/model-picker.svelte b/src/routes/chat/model-picker.svelte index 04d6d8c..15843ae 100644 --- a/src/routes/chat/model-picker.svelte +++ b/src/routes/chat/model-picker.svelte @@ -24,6 +24,7 @@ import LogosClaudeIcon from '~icons/logos/claude-icon'; import LogosMistralAiIcon from '~icons/logos/mistral-ai-icon'; import MaterialIconThemeGeminiAi from '~icons/material-icon-theme/gemini-ai'; + import { capitalize } from '$lib/utils/strings'; type Props = { class?: string; @@ -152,14 +153,30 @@ }, }); + // Term replacements for proper formatting + const termReplacements = [ + { from: 'gpt', to: 'GPT' }, + { from: 'claude', to: 'Claude' }, + { from: 'deepseek', to: 'DeepSeek' }, + { from: 'o3', to: 'o3' }, + ]; + // Name splitter. splits -,_,: function splitName(name: string) { - return name.split(/[-_,:]/); + return name.split(/[-_,:]/).map((s) => formatTerms(s)); + } + + function formatTerms(text: string): string { + return termReplacements.reduce((result, { from, to }) => { + const capitalized = capitalize(result); + return capitalized.replace(new RegExp(`\\b${from}\\b`, 'gi'), to); + }, text); } function getModelTitle(modelId: string) { const sn = splitName(modelId.replace(/^[^/]+\//, '')); - return sn[0] + (sn.length > 1 ? ' ' + sn.slice(1).join(' ') : ''); + const title = sn[0] + (sn.length > 1 ? ' ' + sn.slice(1).join(' ') : ''); + return formatTerms(title); } @@ -247,9 +264,7 @@ {@const CompanyIcon = companyIcons[getCompanyFromModelId(model.model_id)]} {/if} -

+

{sn[0]}