@@ -733,7 +733,7 @@ export class LlamaModel {
733
733
if ( modelLoaded )
734
734
await model . _model . dispose ( ) ;
735
735
736
- throw loadSignal . reason ;
736
+ throw loadSignal ! . reason ;
737
737
} else if ( ! modelLoaded )
738
738
throw new Error ( "Failed to load model" ) ;
739
739
@@ -757,12 +757,17 @@ export class LlamaModelTokens {
757
757
/** @internal */ private _bosToken ?: Token ;
758
758
/** @internal */ private _eosToken ?: Token ;
759
759
/** @internal */ private _eotToken ?: Token ;
760
+ /** @internal */ private _clsToken ?: Token ;
761
+ /** @internal */ private _sepToken ?: Token ;
760
762
/** @internal */ private _nlToken ?: Token ;
761
763
/** @internal */ private _bosString ?: string ;
762
764
/** @internal */ private _eosString ?: string ;
763
765
/** @internal */ private _eotString ?: string ;
766
+ /** @internal */ private _clsString ?: string ;
767
+ /** @internal */ private _sepString ?: string ;
764
768
/** @internal */ private _nlString ?: string ;
765
769
/** @internal */ private _shouldPrependBosToken ?: boolean ;
770
+ /** @internal */ private _shouldAppendEosToken ?: boolean ;
766
771
767
772
private constructor ( model : AddonModel , disposedState : DisposedState ) {
768
773
this . _model = model ;
@@ -826,6 +831,36 @@ export class LlamaModelTokens {
826
831
return this . _eotToken ;
827
832
}
828
833
834
+ /**
835
+ * @returns The CLS (Classification) token.
836
+ */
837
+ public get cls ( ) : Token | null {
838
+ this . _ensureNotDisposed ( ) ;
839
+
840
+ if ( this . _clsToken == null )
841
+ this . _clsToken = this . _model . clsToken ( ) ;
842
+
843
+ if ( this . _clsToken === - 1 )
844
+ return null ;
845
+
846
+ return this . _clsToken ;
847
+ }
848
+
849
+ /**
850
+ * @returns The SEP (Sentence Separator) token.
851
+ */
852
+ public get sep ( ) : Token | null {
853
+ this . _ensureNotDisposed ( ) ;
854
+
855
+ if ( this . _sepToken == null )
856
+ this . _sepToken = this . _model . sepToken ( ) ;
857
+
858
+ if ( this . _sepToken === - 1 )
859
+ return null ;
860
+
861
+ return this . _sepToken ;
862
+ }
863
+
829
864
/**
830
865
* @returns The NL (New Line) token.
831
866
*/
@@ -892,6 +927,40 @@ export class LlamaModelTokens {
892
927
return this . _eotString ;
893
928
}
894
929
930
+ /**
931
+ * @returns The CLS (Classification) token text representation.
932
+ */
933
+ public get clsString ( ) : string | null {
934
+ this . _ensureNotDisposed ( ) ;
935
+
936
+ const clsToken = this . cls ;
937
+
938
+ if ( clsToken == null )
939
+ return null ;
940
+
941
+ if ( this . _clsString == null )
942
+ this . _clsString = this . _model . getTokenString ( clsToken ) ;
943
+
944
+ return this . _clsString ;
945
+ }
946
+
947
+ /**
948
+ * @returns The SEP (Sentence Separator) token text representation.
949
+ */
950
+ public get sepString ( ) : string | null {
951
+ this . _ensureNotDisposed ( ) ;
952
+
953
+ const sepToken = this . sep ;
954
+
955
+ if ( sepToken == null )
956
+ return null ;
957
+
958
+ if ( this . _sepString == null )
959
+ this . _sepString = this . _model . getTokenString ( sepToken ) ;
960
+
961
+ return this . _sepString ;
962
+ }
963
+
895
964
/**
896
965
* @returns The NL (New Line) token text representation.
897
966
*/
@@ -921,6 +990,18 @@ export class LlamaModelTokens {
921
990
return this . _shouldPrependBosToken ;
922
991
}
923
992
993
+ /**
994
+ * @returns Whether we should append an EOS (End Of Sequence) token for evaluations with this model.
995
+ */
996
+ public get shouldAppendEosToken ( ) : boolean {
997
+ this . _ensureNotDisposed ( ) ;
998
+
999
+ if ( this . _shouldAppendEosToken == null )
1000
+ this . _shouldAppendEosToken = this . bos != null && this . _model . shouldAppendEosToken ( ) ;
1001
+
1002
+ return this . _shouldAppendEosToken ;
1003
+ }
1004
+
924
1005
/** @internal */
925
1006
private _ensureNotDisposed ( ) {
926
1007
if ( this . _disposedState . disposed )
0 commit comments