Skip to content

Commit 7b56fba

Browse files
committed
fix: show a loader when resolving a URI from the CLI
1 parent 1515163 commit 7b56fba

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

src/cli/commands/PullCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ export const PullCommand: CommandModule<object, PullCommand> = {
117117
deleteTempFileOnCancel: noTempFile,
118118
skipExisting: !override,
119119
fileName: filename || undefined,
120-
parallelDownloads: parallel
120+
parallelDownloads: parallel,
121+
_showUriResolvingProgress: !noProgress
121122
});
122123

123124
if (!override && downloader.totalFiles === 1 && await fs.pathExists(downloader.entrypointFilePath)) {

src/cli/commands/inspect/commands/InspectEstimateCommand.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {resolveModelArgToFilePathOrUrl} from "../../../../utils/resolveModelDest
2323
import {printModelDestination} from "../../../utils/printModelDestination.js";
2424
import {toBytes} from "../../../utils/toBytes.js";
2525
import {printDidYouMeanUri} from "../../../utils/resolveCommandGgufPath.js";
26+
import {isModelUri} from "../../../../utils/parseModelUri.js";
2627

2728
type InspectEstimateCommand = {
2829
modelPath: string,
@@ -126,7 +127,14 @@ export const InspectEstimateCommand: CommandModule<object, InspectEstimateComman
126127

127128
const headers = resolveHeaderFlag(headerArg);
128129

129-
const [resolvedModelDestination, resolvedGgufPath] = await resolveModelArgToFilePathOrUrl(ggufPath, headers);
130+
const [resolvedModelDestination, resolvedGgufPath] = isModelUri(ggufPath)
131+
? await withOra({
132+
loading: chalk.blue("Resolving model URI"),
133+
success: chalk.blue("Resolved model URI"),
134+
fail: chalk.blue("Failed to resolve model URI"),
135+
noSuccessLiveStatus: true
136+
}, () => resolveModelArgToFilePathOrUrl(ggufPath, headers))
137+
: await resolveModelArgToFilePathOrUrl(ggufPath, headers);
130138

131139
if (resolvedModelDestination.type === "file" && !await fs.pathExists(resolvedGgufPath)) {
132140
console.error(`${chalk.red("File does not exist:")} ${resolvedGgufPath}`);

src/cli/commands/inspect/commands/InspectGgufCommand.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {getGgufMetadataKeyValue} from "../../../../gguf/utils/getGgufMetadataKey
1616
import {GgufTensorInfo} from "../../../../gguf/types/GgufTensorInfoTypes.js";
1717
import {toBytes} from "../../../utils/toBytes.js";
1818
import {printDidYouMeanUri} from "../../../utils/resolveCommandGgufPath.js";
19+
import {isModelUri} from "../../../../utils/parseModelUri.js";
1920

2021
type InspectGgufCommand = {
2122
modelPath: string,
@@ -94,7 +95,14 @@ export const InspectGgufCommand: CommandModule<object, InspectGgufCommand> = {
9495
}: InspectGgufCommand) {
9596
const headers = resolveHeaderFlag(headerArg);
9697

97-
const [resolvedModelDestination, resolvedGgufPath] = await resolveModelArgToFilePathOrUrl(ggufPath, headers);
98+
const [resolvedModelDestination, resolvedGgufPath] = (!plainJson && isModelUri(ggufPath))
99+
? await withOra({
100+
loading: chalk.blue("Resolving model URI"),
101+
success: chalk.blue("Resolved model URI"),
102+
fail: chalk.blue("Failed to resolve model URI"),
103+
noSuccessLiveStatus: true
104+
}, () => resolveModelArgToFilePathOrUrl(ggufPath, headers))
105+
: await resolveModelArgToFilePathOrUrl(ggufPath, headers);
98106

99107
if (resolvedModelDestination.type === "file" && !await fs.pathExists(resolvedGgufPath)) {
100108
console.error(`${chalk.red("File does not exist:")} ${resolvedGgufPath}`);

src/utils/createModelDownloader.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import process from "process";
22
import path from "path";
33
import {DownloadEngineMultiDownload, DownloadEngineNodejs, downloadFile, downloadSequence} from "ipull";
44
import fs from "fs-extra";
5+
import chalk from "chalk";
56
import {createSplitPartFilename, resolveSplitGgufParts} from "../gguf/utils/resolveSplitGgufParts.js";
67
import {getFilenameForBinarySplitGgufPartUrls, resolveBinarySplitGgufPartUrls} from "../gguf/utils/resolveBinarySplitGgufPartUrls.js";
78
import {cliModelsDirectory, isCI} from "../config.js";
@@ -10,6 +11,7 @@ import {ModelFileAccessTokens, resolveModelFileAccessTokensTryHeaders} from "./m
1011
import {pushAll} from "./pushAll.js";
1112
import {resolveModelDestination} from "./resolveModelDestination.js";
1213
import {getAuthorizationHeader, resolveParsedModelUri} from "./parseModelUri.js";
14+
import withOra from "./withOra.js";
1315

1416
export type ModelDownloaderOptions = ({
1517
/**
@@ -65,7 +67,10 @@ export type ModelDownloaderOptions = ({
6567
*/
6668
parallelDownloads?: number,
6769

68-
tokens?: ModelFileAccessTokens
70+
tokens?: ModelFileAccessTokens,
71+
72+
/** @internal */
73+
_showUriResolvingProgress?: boolean
6974
};
7075

7176
/**
@@ -436,7 +441,7 @@ export class ModelDownloader {
436441
/** @internal */
437442
public static async _create(options: ModelDownloaderOptions) {
438443
const {
439-
modelUri, modelUrl, dirPath = cliModelsDirectory, fileName
444+
modelUri, modelUrl, dirPath = cliModelsDirectory, fileName, _showUriResolvingProgress = false
440445
} = options as ModelDownloaderOptions & {
441446
modelUri?: string,
442447
modelUrl?: string
@@ -468,10 +473,22 @@ export class ModelDownloader {
468473
resolvedFileName: fileName || resolvedModelDestination.parsedUri.fullFilename
469474
};
470475

471-
const resolvedUri = await resolveParsedModelUri(resolvedModelDestination.parsedUri, {
472-
tokens: options.tokens,
473-
authorizationHeader: getAuthorizationHeader(options.headers)
474-
});
476+
const resolvedUri = _showUriResolvingProgress
477+
? await withOra({
478+
loading: chalk.blue("Resolving model URI"),
479+
success: chalk.blue("Resolved model URI"),
480+
fail: chalk.blue("Failed to resolve model URI"),
481+
noSuccessLiveStatus: true
482+
}, () => {
483+
return resolveParsedModelUri(resolvedModelDestination.parsedUri, {
484+
tokens: options.tokens,
485+
authorizationHeader: getAuthorizationHeader(options.headers)
486+
});
487+
})
488+
: await resolveParsedModelUri(resolvedModelDestination.parsedUri, {
489+
tokens: options.tokens,
490+
authorizationHeader: getAuthorizationHeader(options.headers)
491+
});
475492

476493
return {
477494
resolvedModelUrl: resolvedUri.resolvedUrl,

0 commit comments

Comments
 (0)