@@ -19,7 +19,8 @@ class LanguageModel extends EventEmitter {
1919 modelUrl : '' , // if set, model.bin will be preloaded from provided URL (assumed to be embedded in llama2.data if not)
2020 tokenizerUrl : '' , // if set, tokenizer.bin will be preloaded from provided URL (assumed to be embedded in llama2.data if not)
2121 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
2324 stopOnBosOrEos : true , // stop when encountering beginning-of-sequence or end-of-sequence token
2425 } ;
2526
@@ -164,6 +165,7 @@ class LanguageModel extends EventEmitter {
164165 if ( typeof optionsOrCb === 'object' ) {
165166 this . options . steps = ( typeof optionsOrCb . steps === 'number' ) ? optionsOrCb . steps : this . options . steps ;
166167 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 ;
167169 this . options . stopOnBosOrEos = ( typeof optionsOrCb . stopOnBosOrEos == 'boolean' ) ? optionsOrCb . stopPropagation : this . options . stopOnBosOrEos ;
168170 }
169171 if ( typeof cb === 'function' ) {
@@ -179,7 +181,7 @@ class LanguageModel extends EventEmitter {
179181 this . promiseResolve ( this . text ) ;
180182 }
181183
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 ] ) ;
183185
184186 this . prompt = prompt ;
185187 this . text = '' ;
@@ -220,6 +222,7 @@ class LanguageModel extends EventEmitter {
220222 if ( typeof optionsOrCb === 'object' ) {
221223 this . options . steps = ( typeof optionsOrCb . steps === 'number' ) ? optionsOrCb . steps : this . options . steps ;
222224 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 ;
223226 this . options . stopOnBosOrEos = ( typeof optionsOrCb . stopOnBosOrEos == 'boolean' ) ? optionsOrCb . stopPropagation : this . options . stopOnBosOrEos ;
224227 }
225228 if ( typeof cb === 'function' ) {
@@ -235,7 +238,7 @@ class LanguageModel extends EventEmitter {
235238 this . promiseResolve ( this . text ) ;
236239 }
237240
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 ] ) ;
239242
240243 this . prompt = prompt ;
241244 this . text = '' ;
0 commit comments