Skip to content

Commit 7e6e143

Browse files
authored
Proposal: Improve llama.cpp snippet (#778)
In this PR, I propose some changes: - Update binary name to `llama-cli` (for more details, see this PR: ggml-org/llama.cpp#7809 and this [homebrew formula](https://github.com/Homebrew/homebrew-core/blob/03cf5d39d8bf27dfabfc90d62c9a3fe19205dc2a/Formula/l/llama.cpp.rb)) - Add method to download llama.cpp via pre-built release - Split snippet into 3 sections: `title`, `setup` and `command` - Use `--conversation` mode to start llama.cpp in chat mode (chat template is now supported, ref: ggml-org/llama.cpp#8068) --- Proposal for the UI: (Note: Maybe the 3 sections title - setup - command can be more separated visually) ![image](https://github.com/huggingface/huggingface.js/assets/7702203/2bd302f0-88b1-4057-9cd3-3cf4536aae50)
1 parent 3f9c0a9 commit 7e6e143

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

packages/tasks/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export { snippets };
4747
export { SKUS, DEFAULT_MEMORY_OPTIONS } from "./hardware";
4848
export type { HardwareSpec, SkuType } from "./hardware";
4949
export { LOCAL_APPS } from "./local-apps";
50-
export type { LocalApp, LocalAppKey } from "./local-apps";
50+
export type { LocalApp, LocalAppKey, LocalAppSnippet } from "./local-apps";
5151

5252
export { DATASET_LIBRARIES_UI_ELEMENTS } from "./dataset-libraries";
5353
export type { DatasetLibraryUiElement, DatasetLibraryKey } from "./dataset-libraries";

packages/tasks/src/local-apps.ts

+49-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
import type { ModelData } from "./model-data";
22
import type { PipelineType } from "./pipelines";
33

4+
export interface LocalAppSnippet {
5+
/**
6+
* Title of the snippet
7+
*/
8+
title: string;
9+
/**
10+
* Optional setup guide
11+
*/
12+
setup?: string;
13+
/**
14+
* Content (or command) to be run
15+
*/
16+
content: string;
17+
}
18+
419
/**
520
* Elements configurable by a local app.
621
*/
@@ -39,36 +54,48 @@ export type LocalApp = {
3954
* And if not (mostly llama.cpp), snippet to copy/paste in your terminal
4055
* Support the placeholder {{GGUF_FILE}} that will be replaced by the gguf file path or the list of available files.
4156
*/
42-
snippet: (model: ModelData, filepath?: string) => string | string[];
57+
snippet: (model: ModelData, filepath?: string) => string | string[] | LocalAppSnippet | LocalAppSnippet[];
4358
}
4459
);
4560

4661
function isGgufModel(model: ModelData) {
4762
return model.tags.includes("gguf");
4863
}
4964

50-
const snippetLlamacpp = (model: ModelData, filepath?: string): string[] => {
65+
const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
66+
const command = (binary: string) =>
67+
[
68+
"# Load and run the model:",
69+
`${binary} \\`,
70+
` --hf-repo "${model.id}" \\`,
71+
` --hf-file ${filepath ?? "{{GGUF_FILE}}"} \\`,
72+
' -p "You are a helpful assistant" \\',
73+
" --conversation",
74+
].join("\n");
5175
return [
52-
`# Option 1: use llama.cpp with brew
53-
brew install llama.cpp
54-
55-
# Load and run the model
56-
llama \\
57-
--hf-repo "${model.id}" \\
58-
--hf-file ${filepath ?? "{{GGUF_FILE}}"} \\
59-
-p "I believe the meaning of life is" \\
60-
-n 128`,
61-
`# Option 2: build llama.cpp from source with curl support
62-
git clone https://github.com/ggerganov/llama.cpp.git
63-
cd llama.cpp
64-
LLAMA_CURL=1 make
65-
66-
# Load and run the model
67-
./main \\
68-
--hf-repo "${model.id}" \\
69-
-m ${filepath ?? "{{GGUF_FILE}}"} \\
70-
-p "I believe the meaning of life is" \\
71-
-n 128`,
76+
{
77+
title: "Install from brew",
78+
setup: "brew install llama.cpp",
79+
content: command("llama-cli"),
80+
},
81+
{
82+
title: "Use pre-built binary",
83+
setup: [
84+
// prettier-ignore
85+
"# Download pre-built binary from:",
86+
"# https://github.com/ggerganov/llama.cpp/releases",
87+
].join("\n"),
88+
content: command("./llama-cli"),
89+
},
90+
{
91+
title: "Build from source code",
92+
setup: [
93+
"git clone https://github.com/ggerganov/llama.cpp.git",
94+
"cd llama.cpp",
95+
"LLAMA_CURL=1 make llama-cli",
96+
].join("\n"),
97+
content: command("./llama-cli"),
98+
},
7299
];
73100
};
74101

0 commit comments

Comments
 (0)