node-llama-cpp 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/dist/AbortError.d.ts +0 -1
- package/dist/AbortError.js +1 -0
- package/dist/AbortError.js.map +1 -1
- package/dist/llamaEvaluator/LlamaContext.d.ts +0 -8
- package/llamaBins/mac-arm64-16.node +0 -0
- package/llamaBins/mac-arm64-17.node +0 -0
- package/llamaBins/mac-arm64-18.node +0 -0
- package/llamaBins/mac-arm64-19.node +0 -0
- package/llamaBins/mac-arm64-20.node +0 -0
- package/llamaBins/mac-x64-16.node +0 -0
- package/llamaBins/mac-x64-17.node +0 -0
- package/llamaBins/mac-x64-18.node +0 -0
- package/llamaBins/mac-x64-19.node +0 -0
- package/llamaBins/mac-x64-20.node +0 -0
- package/llamaBins/win-x64-16.node +0 -0
- package/llamaBins/win-x64-17.node +0 -0
- package/llamaBins/win-x64-18.node +0 -0
- package/llamaBins/win-x64-19.node +0 -0
- package/llamaBins/win-x64-20.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,8 +29,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
29
29
|
|
|
30
30
|
const model = new LlamaModel({
|
|
31
31
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin")
|
|
32
|
-
})
|
|
33
|
-
const session = new LlamaChatSession({model});
|
|
32
|
+
});
|
|
33
|
+
const session = new LlamaChatSession({context: model.createContext()});
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
const q1 = "Hi there, how are you?";
|
|
@@ -73,7 +73,7 @@ const model = new LlamaModel({
|
|
|
73
73
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin"),
|
|
74
74
|
promptWrapper: new MyCustomChatPromptWrapper() // by default, LlamaChatPromptWrapper is used
|
|
75
75
|
})
|
|
76
|
-
const session = new LlamaChatSession({model});
|
|
76
|
+
const session = new LlamaChatSession({context: model.createContext()});
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
const q1 = "Hi there, how are you?";
|
|
@@ -98,29 +98,31 @@ import {LlamaModel, LlamaChatSession} from "node-llama-cpp";
|
|
|
98
98
|
|
|
99
99
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
100
100
|
|
|
101
|
-
const model = new
|
|
101
|
+
const model = new LlamaModel({
|
|
102
102
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin")
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
+
const context = model.createContext();
|
|
106
|
+
|
|
105
107
|
const q1 = "Hi there, how are you?";
|
|
106
108
|
console.log("AI: " + q1);
|
|
107
109
|
|
|
108
|
-
const tokens =
|
|
110
|
+
const tokens = context.encode(q1);
|
|
109
111
|
const res: number[] = [];
|
|
110
|
-
for await (const chunk of
|
|
112
|
+
for await (const chunk of context.evaluate(tokens)) {
|
|
111
113
|
res.push(chunk);
|
|
112
114
|
|
|
113
115
|
// it's important to not concatinate the results as strings,
|
|
114
116
|
// as doing so will break some characters (like some emojis) that are made of multiple tokens.
|
|
115
117
|
// by using an array of tokens, we can decode them correctly together.
|
|
116
|
-
const resString: string =
|
|
118
|
+
const resString: string = context.decode(Uint32Array.from(res));
|
|
117
119
|
|
|
118
120
|
const lastPart = resString.split("ASSISTANT:").reverse()[0];
|
|
119
121
|
if (lastPart.includes("USER:"))
|
|
120
122
|
break;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
const a1 =
|
|
125
|
+
const a1 = context.decode(Uint32Array.from(res)).split("USER:")[0];
|
|
124
126
|
console.log("AI: " + a1);
|
|
125
127
|
```
|
|
126
128
|
|
package/dist/AbortError.d.ts
CHANGED
package/dist/AbortError.js
CHANGED
package/dist/AbortError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../src/AbortError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC;QACI,KAAK,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;CACJ"}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../src/AbortError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,gBAAgB;IAChB;QACI,KAAK,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { LLAMAContext } from "./LlamaBins.js";
|
|
2
|
-
type LlamaContextConstructorParameters = {
|
|
3
|
-
prependBos: boolean;
|
|
4
|
-
ctx: LLAMAContext;
|
|
5
|
-
};
|
|
6
1
|
export declare class LlamaContext {
|
|
7
2
|
private readonly _ctx;
|
|
8
3
|
private _prependBos;
|
|
9
|
-
/** @internal */
|
|
10
|
-
constructor({ ctx, prependBos }: LlamaContextConstructorParameters);
|
|
11
4
|
encode(text: string): Uint32Array;
|
|
12
5
|
decode(tokens: Uint32Array): string;
|
|
13
6
|
evaluate(tokens: Uint32Array, getRestrictions?: () => Uint32Array): AsyncGenerator<number, void, unknown>;
|
|
14
7
|
}
|
|
15
|
-
export {};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|