Skip to content

Commit 3939aac

Browse files
committed
LanguageModel: Rename .out to .text
1 parent 350ebfe commit 3939aac

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

examples/LanguageModel/sketch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ function generateText() {
4242
lm.generate(prompt, options, gotText);
4343
}
4444

45-
function gotText(out, lm) {
46-
console.log('Model returned "' + out + '"');
45+
function gotText(text, lm) {
46+
console.log('Model returned "' + text + '"');
4747
// lm.words contains the output broken up in words
4848
words = lm.words;
4949
curWord = 0;

examples/LanguageModelEvents/sketch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ function onWord(word, lm) {
5959
pop();
6060
}
6161

62-
function onFinsh(out, lm) {
62+
function onFinsh(text, lm) {
6363
console.log('Generation finished');
6464
}

src/LanguageModel/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LanguageModel extends EventEmitter {
4848
throw 'You need to provide the name of the model to load, e.g. TinyStories-15M';
4949
}
5050

51-
this.out = '';
51+
this.text = '';
5252
this.tokens = [];
5353
this.words = [];
5454
this.finished = true;
@@ -110,7 +110,7 @@ class LanguageModel extends EventEmitter {
110110
if (this.options.stopOnBosOrEos && (token == 1 || token == 2)) {
111111
this.finished = true;
112112
} else {
113-
this.out += tokenStr;
113+
this.text += tokenStr;
114114
}
115115

116116
// on-token event
@@ -120,9 +120,9 @@ class LanguageModel extends EventEmitter {
120120
const wordDelimiters = ' .,:;"“?!\n';
121121
const re = new RegExp('(?=[' + wordDelimiters + '])|(?<=[' + wordDelimiters + '])', 'g');
122122
const prevNumWords = this.words.length;
123-
this.words = this.out.split(re);
123+
this.words = this.text.split(re);
124124
// ignore the last word if we can't be certain it's complete
125-
if (!wordDelimiters.includes(this.out.slice(-1)) && !this.finished) {
125+
if (!wordDelimiters.includes(this.text.slice(-1)) && !this.finished) {
126126
this.words.pop();
127127
}
128128
// on-word event
@@ -134,11 +134,11 @@ class LanguageModel extends EventEmitter {
134134
if (this.finished) {
135135
// fulfill the promise returned by generate()
136136
if (this.promiseResolve) {
137-
this.promiseResolve(this.out);
137+
this.promiseResolve(this.text);
138138
}
139-
this.emit('finish', this.out, this);
139+
this.emit('finish', this.text, this);
140140
if (this.callback) {
141-
this.callback(this.out, this);
141+
this.callback(this.text, this);
142142
}
143143
}
144144
}, 'viifi');
@@ -175,12 +175,12 @@ class LanguageModel extends EventEmitter {
175175
// if there are any outstanding requests, resolve them
176176
// with the output received so far
177177
if (this.promiseResolve) {
178-
this.promiseResolve(this.out);
178+
this.promiseResolve(this.text);
179179
}
180180

181181
await this.llama2.ccall('set_parameters', null, [ 'number', 'number' ], [ this.options.temperature, this.options.steps ]);
182182

183-
this.out = '';
183+
this.text = '';
184184
this.tokens = [{ index: 1, str: '<s>', probability: 1 }];
185185
this.words = [];
186186
this.finished = false;
@@ -230,12 +230,12 @@ class LanguageModel extends EventEmitter {
230230
// if there are any outstanding requests, resolve them
231231
// with the output received so far
232232
if (this.promiseResolve) {
233-
this.promiseResolve(this.out);
233+
this.promiseResolve(this.text);
234234
}
235235

236236
await this.llama2.ccall('set_parameters', null, [ 'number', 'number' ], [ this.options.temperature, this.options.steps ]);
237237

238-
this.out = '';
238+
this.text = '';
239239
this.tokens = [];
240240
this.words = [];
241241
this.finished = true;

0 commit comments

Comments
 (0)