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

Commit a9d832b

Browse files
authored
feat: upgrade llama-rs to llm (#62)
* feat: upgrade llama-rs to llm
1 parent 47a3f86 commit a9d832b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+881
-1348
lines changed

.github/workflows/llama-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- run: git submodule update --init --recursive
6969
- run: pnpm install
7070
- run: cargo clippy --all-targets
71-
- run: pnpm build:llama-rs
71+
- run: pnpm build:llm-rs
7272
- run: pnpm build:llama-cpp
7373
- run: pnpm build:rwkv-cpp
7474
- run: pnpm build

Cargo.lock

Lines changed: 109 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ llama-node: Node.js Library for Large Language Model
3636

3737
This project is in an early stage, the API for nodejs may change in the future, use it with caution.
3838

39-
This is a nodejs library for inferencing llama, rwkv or llama derived models. It was built on top of [llama-rs](https://github.com/rustformers/llama-rs), [llama.cpp](https://github.com/ggerganov/llama.cpp) and [rwkv.cpp](https://github.com/saharNooby/rwkv.cpp). It uses [napi-rs](https://github.com/napi-rs/napi-rs) for channel messages between node.js and llama thread.
39+
This is a nodejs library for inferencing llama, rwkv or llama derived models. It was built on top of [llm (originally llama-rs)](https://github.com/rustformers/llm), [llama.cpp](https://github.com/ggerganov/llama.cpp) and [rwkv.cpp](https://github.com/saharNooby/rwkv.cpp). It uses [napi-rs](https://github.com/napi-rs/napi-rs) for channel messages between node.js and llama thread.
4040

4141
Currently supported models (All of these should be converted to [GGML](https://github.com/ggerganov/ggml) format):
4242

@@ -77,7 +77,7 @@ npm install llama-node
7777
npm install @llama-node/llama-cpp
7878
```
7979

80-
- or llama-rs
80+
- or llm
8181

8282
```bash
8383
npm install @llama-node/core
@@ -106,7 +106,7 @@ This library was published under MIT/Apache-2.0 license. However, we strongly re
106106
- LLaMA models: [facebookresearch/llama](https://github.com/facebookresearch/llama)
107107
- RWKV models: [BlinkDL/RWKV-LM](https://github.com/BlinkDL/RWKV-LM)
108108
- llama.cpp: [ggreganov/llama.cpp](https://github.com/ggerganov/llama.cpp)
109-
- llama-rs: [rustformers/llama-rs](https://github.com/rustformers/llama-rs)
109+
- llm: [rustformers/llm](https://github.com/rustformers/llm)
110110
- rwkv.cpp: [saharNooby/rwkv.cpp](https://github.com/saharNooby/rwkv.cpp)
111111

112112
### Some source code comes from
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { LLM } from "llama-node";
2-
import { LLamaRS } from "llama-node/dist/llm/llama-rs.js";
2+
import { LLMRS } from "llama-node/dist/llm/llm-rs.js";
33
import path from "path";
44
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
5-
const llama = new LLM(LLamaRS);
5+
const llama = new LLM(LLMRS);
66
const template = `how are you`;
77
const prompt = `Below is an instruction that describes a task. Write a response that appropriately completes the request.
88
@@ -14,7 +14,7 @@ ${template}
1414
const params = {
1515
prompt,
1616
numPredict: 128,
17-
temp: 0.2,
17+
temperature: 0.2,
1818
topP: 1,
1919
topK: 40,
2020
repeatPenalty: 1,
@@ -24,7 +24,7 @@ const params = {
2424
};
2525
const run = async () => {
2626
const abortController = new AbortController();
27-
await llama.load({ path: model });
27+
await llama.load({ modelPath: model, modelType: "Llama" /* ModelType.Llama */ });
2828
setTimeout(() => {
2929
abortController.abort();
3030
}, 3000);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { LLM } from "llama-node";
2-
import { LLamaRS } from "llama-node/dist/llm/llama-rs.js";
2+
import { LLMRS } from "llama-node/dist/llm/llm-rs.js";
33
import path from "path";
44
import fs from "fs";
55
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
6-
const llama = new LLM(LLamaRS);
6+
const llama = new LLM(LLMRS);
77
const getWordEmbeddings = async (prompt, file) => {
88
const data = await llama.getEmbedding({
99
prompt,
1010
numPredict: 128,
11-
temp: 0.2,
11+
temperature: 0.2,
1212
topP: 1,
1313
topK: 40,
1414
repeatPenalty: 1,
@@ -19,7 +19,7 @@ const getWordEmbeddings = async (prompt, file) => {
1919
await fs.promises.writeFile(path.resolve(process.cwd(), file), JSON.stringify(data));
2020
};
2121
const run = async () => {
22-
await llama.load({ path: model });
22+
await llama.load({ modelPath: model, modelType: "Llama" /* ModelType.Llama */ });
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`;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { LLM } from "llama-node";
2-
import { LLamaRS } from "llama-node/dist/llm/llama-rs.js";
2+
import { LLMRS } from "llama-node/dist/llm/llm-rs.js";
33
import path from "path";
44
const model = path.resolve(process.cwd(), "../ggml-alpaca-7b-q4.bin");
5-
const llama = new LLM(LLamaRS);
5+
const llama = new LLM(LLMRS);
66
const template = `how are you`;
77
const prompt = `Below is an instruction that describes a task. Write a response that appropriately completes the request.
88
@@ -14,7 +14,7 @@ ${template}
1414
const params = {
1515
prompt,
1616
numPredict: 128,
17-
temp: 0.2,
17+
temperature: 0.2,
1818
topP: 1,
1919
topK: 40,
2020
repeatPenalty: 1,
@@ -23,7 +23,7 @@ const params = {
2323
feedPrompt: true,
2424
};
2525
const run = async () => {
26-
await llama.load({ path: model });
26+
await llama.load({ modelPath: model, modelType: "Llama" /* ModelType.Llama */ });
2727
await llama.createCompletion(params, (response) => {
2828
process.stdout.write(response.token);
2929
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)