Skip to content

Commit

Permalink
fix: show a loader when resolving a URI from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
giladgd committed Jan 30, 2025
1 parent c851862 commit 526a8b5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/cli/commands/PullCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const PullCommand: CommandModule<object, PullCommand> = {
deleteTempFileOnCancel: noTempFile,
skipExisting: !override,
fileName: filename || undefined,
parallelDownloads: parallel
parallelDownloads: parallel,
_showUriResolvingProgress: !noProgress
});

if (!override && downloader.totalFiles === 1 && await fs.pathExists(downloader.entrypointFilePath)) {
Expand Down
10 changes: 9 additions & 1 deletion src/cli/commands/inspect/commands/InspectEstimateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {resolveModelArgToFilePathOrUrl} from "../../../../utils/resolveModelDest
import {printModelDestination} from "../../../utils/printModelDestination.js";
import {toBytes} from "../../../utils/toBytes.js";
import {printDidYouMeanUri} from "../../../utils/resolveCommandGgufPath.js";
import {isModelUri} from "../../../../utils/parseModelUri.js";

type InspectEstimateCommand = {
modelPath: string,
Expand Down Expand Up @@ -126,7 +127,14 @@ export const InspectEstimateCommand: CommandModule<object, InspectEstimateComman

const headers = resolveHeaderFlag(headerArg);

const [resolvedModelDestination, resolvedGgufPath] = await resolveModelArgToFilePathOrUrl(ggufPath, headers);
const [resolvedModelDestination, resolvedGgufPath] = isModelUri(ggufPath)
? await withOra({
loading: chalk.blue("Resolving model URI"),
success: chalk.blue("Resolved model URI"),
fail: chalk.blue("Failed to resolve model URI"),
noSuccessLiveStatus: true
}, () => resolveModelArgToFilePathOrUrl(ggufPath, headers))
: await resolveModelArgToFilePathOrUrl(ggufPath, headers);

if (resolvedModelDestination.type === "file" && !await fs.pathExists(resolvedGgufPath)) {
console.error(`${chalk.red("File does not exist:")} ${resolvedGgufPath}`);
Expand Down
10 changes: 9 additions & 1 deletion src/cli/commands/inspect/commands/InspectGgufCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {getGgufMetadataKeyValue} from "../../../../gguf/utils/getGgufMetadataKey
import {GgufTensorInfo} from "../../../../gguf/types/GgufTensorInfoTypes.js";
import {toBytes} from "../../../utils/toBytes.js";
import {printDidYouMeanUri} from "../../../utils/resolveCommandGgufPath.js";
import {isModelUri} from "../../../../utils/parseModelUri.js";

type InspectGgufCommand = {
modelPath: string,
Expand Down Expand Up @@ -94,7 +95,14 @@ export const InspectGgufCommand: CommandModule<object, InspectGgufCommand> = {
}: InspectGgufCommand) {
const headers = resolveHeaderFlag(headerArg);

const [resolvedModelDestination, resolvedGgufPath] = await resolveModelArgToFilePathOrUrl(ggufPath, headers);
const [resolvedModelDestination, resolvedGgufPath] = (!plainJson && isModelUri(ggufPath))
? await withOra({
loading: chalk.blue("Resolving model URI"),
success: chalk.blue("Resolved model URI"),
fail: chalk.blue("Failed to resolve model URI"),
noSuccessLiveStatus: true
}, () => resolveModelArgToFilePathOrUrl(ggufPath, headers))
: await resolveModelArgToFilePathOrUrl(ggufPath, headers);

if (resolvedModelDestination.type === "file" && !await fs.pathExists(resolvedGgufPath)) {
console.error(`${chalk.red("File does not exist:")} ${resolvedGgufPath}`);
Expand Down
29 changes: 23 additions & 6 deletions src/utils/createModelDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import process from "process";
import path from "path";
import {DownloadEngineMultiDownload, DownloadEngineNodejs, downloadFile, downloadSequence} from "ipull";
import fs from "fs-extra";
import chalk from "chalk";
import {createSplitPartFilename, resolveSplitGgufParts} from "../gguf/utils/resolveSplitGgufParts.js";
import {getFilenameForBinarySplitGgufPartUrls, resolveBinarySplitGgufPartUrls} from "../gguf/utils/resolveBinarySplitGgufPartUrls.js";
import {cliModelsDirectory, isCI} from "../config.js";
Expand All @@ -10,6 +11,7 @@ import {ModelFileAccessTokens, resolveModelFileAccessTokensTryHeaders} from "./m
import {pushAll} from "./pushAll.js";
import {resolveModelDestination} from "./resolveModelDestination.js";
import {getAuthorizationHeader, resolveParsedModelUri} from "./parseModelUri.js";
import withOra from "./withOra.js";

export type ModelDownloaderOptions = ({
/**
Expand Down Expand Up @@ -65,7 +67,10 @@ export type ModelDownloaderOptions = ({
*/
parallelDownloads?: number,

tokens?: ModelFileAccessTokens
tokens?: ModelFileAccessTokens,

/** @internal */
_showUriResolvingProgress?: boolean
};

/**
Expand Down Expand Up @@ -436,7 +441,7 @@ export class ModelDownloader {
/** @internal */
public static async _create(options: ModelDownloaderOptions) {
const {
modelUri, modelUrl, dirPath = cliModelsDirectory, fileName
modelUri, modelUrl, dirPath = cliModelsDirectory, fileName, _showUriResolvingProgress = false
} = options as ModelDownloaderOptions & {
modelUri?: string,
modelUrl?: string
Expand Down Expand Up @@ -468,10 +473,22 @@ export class ModelDownloader {
resolvedFileName: fileName || resolvedModelDestination.parsedUri.fullFilename
};

const resolvedUri = await resolveParsedModelUri(resolvedModelDestination.parsedUri, {
tokens: options.tokens,
authorizationHeader: getAuthorizationHeader(options.headers)
});
const resolvedUri = _showUriResolvingProgress
? await withOra({
loading: chalk.blue("Resolving model URI"),
success: chalk.blue("Resolved model URI"),
fail: chalk.blue("Failed to resolve model URI"),
noSuccessLiveStatus: true
}, () => {
return resolveParsedModelUri(resolvedModelDestination.parsedUri, {
tokens: options.tokens,
authorizationHeader: getAuthorizationHeader(options.headers)
});
})
: await resolveParsedModelUri(resolvedModelDestination.parsedUri, {
tokens: options.tokens,
authorizationHeader: getAuthorizationHeader(options.headers)
});

return {
resolvedModelUrl: resolvedUri.resolvedUrl,
Expand Down

0 comments on commit 526a8b5

Please # to comment.