feat: list, pick and manage Ollama models from a command
This commit is contained in:
@@ -50,6 +50,33 @@ export function recencyGroup(timestamp: number, now: number = Date.now()): Recen
|
||||
return "Older";
|
||||
}
|
||||
|
||||
/**
|
||||
* A byte count for a person to read: "6.6 GB", "326 B".
|
||||
*
|
||||
* Decimal units, not the 1024-based ones a memory figure would use, because
|
||||
* that is what every other tool in this ecosystem prints: `ollama list` shows
|
||||
* 6550813657 bytes as 6.6 GB, and a number that disagreed with the terminal the
|
||||
* user just looked at would read as a bug in this extension.
|
||||
*
|
||||
* `undefined` for a size that is absent or nonsense, so a caller can leave the
|
||||
* field out rather than print "NaN B".
|
||||
*/
|
||||
export function formatBytes(bytes: number | undefined): string | undefined {
|
||||
if (bytes === undefined || !Number.isFinite(bytes) || bytes < 0) return undefined;
|
||||
if (bytes < 1000) return `${Math.round(bytes)} B`;
|
||||
|
||||
const units = ["kB", "MB", "GB", "TB"];
|
||||
let value = bytes / 1000;
|
||||
let unit = 0;
|
||||
|
||||
while (value >= 1000 && unit < units.length - 1) {
|
||||
value /= 1000;
|
||||
unit += 1;
|
||||
}
|
||||
|
||||
return `${value.toFixed(1)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
/** Pulls a human-readable message out of anything that can be thrown. */
|
||||
export function errorMessage(error: unknown): string {
|
||||
if (error instanceof Error) return error.message;
|
||||
|
||||
Reference in New Issue
Block a user