Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 755e6ea

Browse files
committed
release: v0.1.0
1 parent e82222d commit 755e6ea

File tree

27 files changed

+191
-136
lines changed

27 files changed

+191
-136
lines changed

example/js/langchain/langchain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const config = {
1818
embedding: true,
1919
useMmap: true,
2020
};
21-
llama.load(config);
2221
const run = async () => {
22+
await llama.load(config);
2323
// Load the docs into the vector store
2424
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world"], [{ id: 2 }, { id: 1 }, { id: 3 }], new LLamaEmbeddings({ maxConcurrency: 1 }, llama));
2525
// Search for the most similar document

example/js/llama-cpp/embedding.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const config = {
1616
embedding: true,
1717
useMmap: true,
1818
};
19-
llama.load(config);
2019
const prompt = `Who is the president of the United States?`;
2120
const params = {
2221
nThreads: 4,
@@ -27,4 +26,8 @@ const params = {
2726
repeatPenalty: 1,
2827
prompt,
2928
};
30-
llama.getEmbedding(params).then(console.log);
29+
const run = async () => {
30+
await llama.load(config);
31+
await llama.getEmbedding(params).then(console.log);
32+
};
33+
run();

example/js/llama-cpp/inference.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ const config = {
1616
embedding: false,
1717
useMmap: true,
1818
};
19-
llama.load(config);
2019
const template = `How are you?`;
2120
const prompt = `A chat between a user and an assistant.
2221
USER: ${template}
2322
ASSISTANT:`;
24-
llama.createCompletion({
23+
const params = {
2524
nThreads: 4,
2625
nTokPredict: 2048,
2726
topK: 40,
2827
topP: 0.1,
2928
temp: 0.2,
3029
repeatPenalty: 1,
3130
prompt,
32-
}, (response) => {
33-
process.stdout.write(response.token);
34-
});
31+
};
32+
const run = async () => {
33+
await llama.load(config);
34+
await llama.createCompletion(params, (response) => {
35+
process.stdout.write(response.token);
36+
});
37+
};
38+
run();

example/js/llama-cpp/tokenize.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const config = {
1616
embedding: false,
1717
useMmap: true,
1818
};
19-
llama.load(config);
2019
const content = "how are you?";
21-
llama.tokenize({ content, nCtx: 2048 }).then(console.log);
20+
const run = async () => {
21+
await llama.load(config);
22+
await llama.tokenize({ content, nCtx: 2048 }).then(console.log);
23+
};
24+
run();

example/js/llama-rs/embedding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import path from "path";
44
import fs from "fs";
55
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
66
const llama = new LLM(LLamaRS);
7-
llama.load({ path: model });
87
const getWordEmbeddings = async (prompt, file) => {
98
const data = await llama.getEmbedding({
109
prompt,
@@ -20,6 +19,7 @@ const getWordEmbeddings = async (prompt, file) => {
2019
await fs.promises.writeFile(path.resolve(process.cwd(), file), JSON.stringify(data));
2120
};
2221
const run = async () => {
22+
await llama.load({ path: model });
2323
const dog1 = `My favourite animal is the dog`;
2424
await getWordEmbeddings(dog1, "./example/semantic-compare/dog1.json");
2525
const dog2 = `I have just adopted a cute dog`;

example/js/llama-rs/inference.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { LLamaRS } from "llama-node/dist/llm/llama-rs.js";
33
import path from "path";
44
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
55
const llama = new LLM(LLamaRS);
6-
llama.load({ path: model });
76
const template = `how are you`;
87
const prompt = `Below is an instruction that describes a task. Write a response that appropriately completes the request.
98
@@ -12,7 +11,7 @@ const prompt = `Below is an instruction that describes a task. Write a response
1211
${template}
1312
1413
### Response:`;
15-
llama.createCompletion({
14+
const params = {
1615
prompt,
1716
numPredict: 128,
1817
temp: 0.2,
@@ -22,6 +21,11 @@ llama.createCompletion({
2221
repeatLastN: 64,
2322
seed: 0,
2423
feedPrompt: true,
25-
}, (response) => {
26-
process.stdout.write(response.token);
27-
});
24+
};
25+
const run = async () => {
26+
await llama.load({ path: model });
27+
await llama.createCompletion(params, (response) => {
28+
process.stdout.write(response.token);
29+
});
30+
};
31+
run();

example/js/llama-rs/tokenize.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { LLamaRS } from "llama-node/dist/llm/llama-rs.js";
33
import path from "path";
44
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
55
const llama = new LLM(LLamaRS);
6-
llama.load({ path: model });
76
const content = "how are you?";
8-
llama.tokenize(content).then(console.log);
7+
const run = async () => {
8+
await llama.load({ path: model });
9+
await llama.tokenize(content).then(console.log);
10+
};
11+
run();

example/js/rwkv-cpp/inference.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ const config = {
1010
nThreads: 4,
1111
enableLogging: true,
1212
};
13-
rwkv.load(config);
1413
const template = `Who is the president of the United States?`;
1514
const prompt = `Below is an instruction that describes a task. Write a response that appropriately completes the request.
1615
1716
### Instruction: ${template}
1817
1918
### Response:`;
20-
rwkv.createCompletion({
19+
const params = {
2120
maxPredictLength: 2048,
2221
topP: 0.1,
2322
temp: 0.1,
2423
prompt,
25-
}, (response) => {
26-
process.stdout.write(response.token);
27-
});
24+
};
25+
const run = async () => {
26+
await rwkv.load(config);
27+
await rwkv.createCompletion(params, (response) => {
28+
process.stdout.write(response.token);
29+
});
30+
};
31+
run();

example/js/rwkv-cpp/tokenize.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ const config = {
1010
nThreads: 4,
1111
enableLogging: true,
1212
};
13-
rwkv.load(config);
14-
rwkv.tokenize({ content: "hello world" }).then(console.log);
13+
const run = async () => {
14+
await rwkv.load(config);
15+
await rwkv.tokenize({ content: "hello world" }).then(console.log);
16+
};
17+
run();

example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@llama-node/examples",
3-
"version": "0.0.37",
3+
"version": "0.1.0",
44
"description": "",
55
"main": "index.js",
66
"type": "module",
@@ -18,9 +18,9 @@
1818
"langchain": "^0.0.56"
1919
},
2020
"dependencies": {
21-
"@llama-node/core": "0.0.37",
22-
"@llama-node/llama-cpp": "0.0.37",
23-
"@llama-node/rwkv-cpp": "0.0.37",
24-
"llama-node": "0.0.37"
21+
"@llama-node/core": "0.1.0",
22+
"@llama-node/llama-cpp": "0.1.0",
23+
"@llama-node/rwkv-cpp": "0.1.0",
24+
"llama-node": "0.1.0"
2525
}
2626
}

0 commit comments

Comments
 (0)