Skip to content

Commit fbd87d3

Browse files
authored
[tasks] {{QUANT_TAG}} placeholder for all snippets (#1365)
cc @Vaibhavs10 @ngxson
1 parent 7d34694 commit fbd87d3

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

packages/tasks/src/local-apps.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("local-apps", () => {
1313
const snippet = snippetFunc(model);
1414

1515
expect(snippet[0].content).toEqual(`# Load and run the model:
16-
llama-cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF`);
16+
llama-cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF:{{QUANT_TAG}}`);
1717
});
1818

1919
it("llama.cpp non-conversational", async () => {
@@ -26,7 +26,7 @@ llama-cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF`);
2626
const snippet = snippetFunc(model);
2727

2828
expect(snippet[0].content).toEqual(`# Load and run the model:
29-
llama-cli -hf mlabonne/gemma-2b-GGUF \\
29+
llama-cli -hf mlabonne/gemma-2b-GGUF:{{QUANT_TAG}} \\
3030
-p "Once upon a time,"`);
3131
});
3232

packages/tasks/src/local-apps.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export type LocalApp = {
5757
/**
5858
* And if not (mostly llama.cpp), snippet to copy/paste in your terminal
5959
* Support the placeholder {{GGUF_FILE}} that will be replaced by the gguf file path or the list of available files.
60-
* Support the placeholder {{OLLAMA_TAG}} that will be replaced by the list of available quant tags or will be removed if there are no multiple quant files in a same repo.
60+
* Support the placeholder {{QUANT_TAG}} that will be replaced by the list of available quant tags or will be removed if there are no multiple quant files in a same repo.
6161
*/
6262
snippet: (model: ModelData, filepath?: string) => string | string[] | LocalAppSnippet | LocalAppSnippet[];
6363
}
@@ -94,14 +94,20 @@ function isMlxModel(model: ModelData) {
9494
return model.tags.includes("mlx");
9595
}
9696

97-
const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
98-
let tagName = "";
99-
if (filepath) {
100-
const quantLabel = parseGGUFQuantLabel(filepath);
101-
tagName = quantLabel ? `:${quantLabel}` : "";
97+
function getQuantTag(filepath?: string): string {
98+
const defaultTag = ":{{QUANT_TAG}}";
99+
100+
if (!filepath) {
101+
return defaultTag;
102102
}
103+
104+
const quantLabel = parseGGUFQuantLabel(filepath);
105+
return quantLabel ? `:${quantLabel}` : defaultTag;
106+
}
107+
108+
const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
103109
const command = (binary: string) => {
104-
const snippet = ["# Load and run the model:", `${binary} -hf ${model.id}${tagName}`];
110+
const snippet = ["# Load and run the model:", `${binary} -hf ${model.id}${getQuantTag(filepath)}`];
105111
if (!model.tags.includes("conversational")) {
106112
// for non-conversational models, add a prompt
107113
snippet[snippet.length - 1] += " \\";
@@ -138,13 +144,7 @@ const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[]
138144
};
139145

140146
const snippetNodeLlamaCppCli = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
141-
let tagName = "{{OLLAMA_TAG}}";
142-
143-
if (filepath) {
144-
const quantLabel = parseGGUFQuantLabel(filepath);
145-
tagName = quantLabel ? `:${quantLabel}` : tagName;
146-
}
147-
147+
const tagName = getQuantTag(filepath);
148148
return [
149149
{
150150
title: "Chat with the model",
@@ -158,12 +158,7 @@ const snippetNodeLlamaCppCli = (model: ModelData, filepath?: string): LocalAppSn
158158
};
159159

160160
const snippetOllama = (model: ModelData, filepath?: string): string => {
161-
if (filepath) {
162-
const quantLabel = parseGGUFQuantLabel(filepath);
163-
const ollamatag = quantLabel ? `:${quantLabel}` : "";
164-
return `ollama run hf.co/${model.id}${ollamatag}`;
165-
}
166-
return `ollama run hf.co/${model.id}{{OLLAMA_TAG}}`;
161+
return `ollama run hf.co/${model.id}${getQuantTag(filepath)}`;
167162
};
168163

169164
const snippetLocalAI = (model: ModelData, filepath?: string): LocalAppSnippet[] => {

0 commit comments

Comments
 (0)