@@ -19,7 +19,8 @@ class LanguageModel extends EventEmitter {
19
19
modelUrl : '' , // if set, model.bin will be preloaded from provided URL (assumed to be embedded in llama2.data if not)
20
20
tokenizerUrl : '' , // if set, tokenizer.bin will be preloaded from provided URL (assumed to be embedded in llama2.data if not)
21
21
steps : 0 , // how many tokens to generate (defaults to model's maximum)
22
- temperature : 0.9 , // 0.0 = (deterministic) argmax sampling, 1.0 = baseline
22
+ temperature : 1.0 , // 0.0 = (deterministic) argmax sampling, 1.0 = baseline, don't set higher
23
+ topp : 0.9 , // p value in top-p (nucleus) sampling, 0 = off
23
24
stopOnBosOrEos : true , // stop when encountering beginning-of-sequence or end-of-sequence token
24
25
} ;
25
26
@@ -164,6 +165,7 @@ class LanguageModel extends EventEmitter {
164
165
if ( typeof optionsOrCb === 'object' ) {
165
166
this . options . steps = ( typeof optionsOrCb . steps === 'number' ) ? optionsOrCb . steps : this . options . steps ;
166
167
this . options . temperature = ( typeof optionsOrCb . temperature === 'number' ) ? optionsOrCb . temperature : this . options . temperature ;
168
+ this . options . topp = ( typeof optionsOrCb . topp === 'number' ) ? optionsOrCb . topp : this . options . topp ;
167
169
this . options . stopOnBosOrEos = ( typeof optionsOrCb . stopOnBosOrEos == 'boolean' ) ? optionsOrCb . stopPropagation : this . options . stopOnBosOrEos ;
168
170
}
169
171
if ( typeof cb === 'function' ) {
@@ -179,7 +181,7 @@ class LanguageModel extends EventEmitter {
179
181
this . promiseResolve ( this . text ) ;
180
182
}
181
183
182
- await this . llama2 . ccall ( 'set_parameters' , null , [ 'number' , 'number' ] , [ this . options . temperature , this . options . steps ] ) ;
184
+ await this . llama2 . ccall ( 'set_parameters' , null , [ 'number' , 'number' , 'number' ] , [ this . options . temperature , this . options . topp , this . options . steps ] ) ;
183
185
184
186
this . prompt = prompt ;
185
187
this . text = '' ;
@@ -220,6 +222,7 @@ class LanguageModel extends EventEmitter {
220
222
if ( typeof optionsOrCb === 'object' ) {
221
223
this . options . steps = ( typeof optionsOrCb . steps === 'number' ) ? optionsOrCb . steps : this . options . steps ;
222
224
this . options . temperature = ( typeof optionsOrCb . temperature === 'number' ) ? optionsOrCb . temperature : this . options . temperature ;
225
+ this . options . topp = ( typeof optionsOrCb . topp === 'number' ) ? optionsOrCb . topp : this . options . topp ;
223
226
this . options . stopOnBosOrEos = ( typeof optionsOrCb . stopOnBosOrEos == 'boolean' ) ? optionsOrCb . stopPropagation : this . options . stopOnBosOrEos ;
224
227
}
225
228
if ( typeof cb === 'function' ) {
@@ -235,7 +238,7 @@ class LanguageModel extends EventEmitter {
235
238
this . promiseResolve ( this . text ) ;
236
239
}
237
240
238
- await this . llama2 . ccall ( 'set_parameters' , null , [ 'number' , 'number' ] , [ this . options . temperature , this . options . steps ] ) ;
241
+ await this . llama2 . ccall ( 'set_parameters' , null , [ 'number' , 'number' , 'number' ] , [ this . options . temperature , this . options . topp , this . options . steps ] ) ;
239
242
240
243
this . prompt = prompt ;
241
244
this . text = '' ;
0 commit comments