Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 956b677

Browse files
refactor(ollama): use prettyBytes for model size formatting
1 parent 8a6b4b5 commit 956b677

19 files changed

Lines changed: 49 additions & 132 deletions

File tree

webview-ui/src/components/settings/providers/Ollama.tsx

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { useAppTranslation } from "@src/i18n/TranslationContext"
1515
import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
1616
import { vscode } from "@src/utils/vscode"
1717
import { Button } from "@src/components/ui/button"
18+
import prettyBytes from "pretty-bytes"
1819

1920
import { inputEventTransform } from "../transforms"
20-
import { ModelPicker } from "../ModelPicker"
2121

2222
type OllamaProps = {
2323
apiConfiguration: ProviderSettings
@@ -382,47 +382,36 @@ export const Ollama = ({ apiConfiguration, setApiConfigurationField }: OllamaPro
382382
</tr>
383383
</thead>
384384
<tbody>
385-
{sortedModelsWithTools.map((model) => {
386-
const formatSize = (bytes?: number): string => {
387-
if (!bytes) return "-"
388-
const gb = bytes / (1024 * 1024 * 1024)
389-
if (gb >= 1) {
390-
return `${gb.toFixed(1)} ${t("settings:providers.ollama.table.sizeFormatting.gb")}`
391-
}
392-
const mb = bytes / (1024 * 1024)
393-
return `${mb.toFixed(1)} ${t("settings:providers.ollama.table.sizeFormatting.mb")}`
394-
}
395-
return (
396-
<tr
397-
key={model.name}
398-
className="border-b border-vscode-foreground/5 hover:bg-vscode-foreground/5">
399-
<td className="py-2 px-3">
400-
<VSCodeRadio
401-
value={model.name}
402-
checked={apiConfiguration?.ollamaModelId === model.name}>
403-
{model.name}
404-
</VSCodeRadio>
405-
</td>
406-
<td className="py-2 px-3 text-vscode-descriptionForeground">
407-
{model.contextWindow.toLocaleString()}
408-
</td>
409-
<td className="py-2 px-3 text-vscode-descriptionForeground">
410-
{formatSize(model.size)}
411-
</td>
412-
<td className="py-2 px-3 text-vscode-descriptionForeground">
413-
{model.quantizationLevel || "-"}
414-
</td>
415-
<td className="py-2 px-3 text-vscode-descriptionForeground">
416-
{model.family || "-"}
417-
</td>
418-
<td className="py-2 px-3 text-vscode-descriptionForeground">
419-
{model.supportsImages
420-
? t("settings:providers.ollama.table.yes")
421-
: t("settings:providers.ollama.table.no")}
422-
</td>
423-
</tr>
424-
)
425-
})}
385+
{sortedModelsWithTools.map((model) => (
386+
<tr
387+
key={model.name}
388+
className="border-b border-vscode-foreground/5 hover:bg-vscode-foreground/5">
389+
<td className="py-2 px-3">
390+
<VSCodeRadio
391+
value={model.name}
392+
checked={apiConfiguration?.ollamaModelId === model.name}>
393+
{model.name}
394+
</VSCodeRadio>
395+
</td>
396+
<td className="py-2 px-3 text-vscode-descriptionForeground">
397+
{model.contextWindow.toLocaleString()}
398+
</td>
399+
<td className="py-2 px-3 text-vscode-descriptionForeground">
400+
{model.size ? prettyBytes(model.size) : "-"}
401+
</td>
402+
<td className="py-2 px-3 text-vscode-descriptionForeground">
403+
{model.quantizationLevel || "-"}
404+
</td>
405+
<td className="py-2 px-3 text-vscode-descriptionForeground">
406+
{model.family || "-"}
407+
</td>
408+
<td className="py-2 px-3 text-vscode-descriptionForeground">
409+
{model.supportsImages
410+
? t("settings:providers.ollama.table.yes")
411+
: t("settings:providers.ollama.table.no")}
412+
</td>
413+
</tr>
414+
))}
426415
</tbody>
427416
</table>
428417
</div>

webview-ui/src/i18n/locales/ca/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,7 @@
511511
"family": "Family",
512512
"images": "Images",
513513
"yes": "Yes",
514-
"no": "No",
515-
"sizeFormatting": {
516-
"gb": "GB",
517-
"mb": "MB"
518-
}
514+
"no": "No"
519515
},
520516
"streaming": "Streaming",
521517
"streamingHelp": "Streaming is always enabled for Ollama API requests. Responses are streamed in real-time as they are generated.",

webview-ui/src/i18n/locales/es/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/hi/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/id/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/it/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/ja/settings.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)