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 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 LlamaChatSession({
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 = model.encode(q1);
110
+ const tokens = context.encode(q1);
109
111
  const res: number[] = [];
110
- for await (const chunk of model.evaluate(tokens)) {
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 = model.decode(Uint32Array.from(res));
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 = model.decode(Uint32Array.from(res)).split("USER:")[0];
125
+ const a1 = context.decode(Uint32Array.from(res)).split("USER:")[0];
124
126
  console.log("AI: " + a1);
125
127
  ```
126
128
 
@@ -1,3 +1,2 @@
1
1
  export declare class AbortError extends Error {
2
- constructor();
3
2
  }
@@ -1,4 +1,5 @@
1
1
  export class AbortError extends Error {
2
+ /** @internal */
2
3
  constructor() {
3
4
  super("AbortError");
4
5
  }
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-llama-cpp",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "node.js bindings for llama.cpp",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",