@@ -940,17 +940,17 @@ def _create_completion(
940
940
941
941
completion_id : str = f"cmpl-{ str (uuid .uuid4 ())} "
942
942
created : int = int (time .time ())
943
- prefix_token_id : Optional [ int ] = self .metadata .get ("tokenizer.ggml.prefix_token_id" )
944
- middle_token_id : Optional [ int ] = self .metadata .get ("tokenizer.ggml.middle_token_id" )
945
- suffix_token_id : Optional [ int ] = self .metadata .get ("tokenizer.ggml.suffix_token_id" )
943
+ prefix_token_id : int = int ( self .metadata .get ("tokenizer.ggml.prefix_token_id" , self . token_prefix ()) )
944
+ middle_token_id : int = int ( self .metadata .get ("tokenizer.ggml.middle_token_id" , self . token_middle ()) )
945
+ suffix_token_id : int = int ( self .metadata .get ("tokenizer.ggml.suffix_token_id" , self . token_suffix ()) )
946
946
# If prompt is empty, initialize completion with BOS token to avoid
947
947
# detokenization including a space at the beginning of the completion
948
948
completion_tokens : List [int ] = [] if len (prompt ) > 0 else [self .token_bos ()]
949
949
# Add blank space to start of prompt to match OG llama tokenizer
950
950
prompt_tokens : List [int ] = (
951
951
(
952
- [int ( prefix_token_id ) ]
953
- if prefix_token_id and suffix is not None
952
+ [prefix_token_id ]
953
+ if prefix_token_id >= 0 and suffix is not None
954
954
else []
955
955
)
956
956
+
@@ -965,8 +965,8 @@ def _create_completion(
965
965
)
966
966
+
967
967
(
968
- [int ( suffix_token_id ) ]
969
- if suffix_token_id and suffix is not None
968
+ [suffix_token_id ]
969
+ if suffix_token_id >= 0 and suffix is not None
970
970
else []
971
971
)
972
972
+
@@ -977,8 +977,8 @@ def _create_completion(
977
977
)
978
978
+
979
979
(
980
- [int ( middle_token_id ) ]
981
- if middle_token_id and suffix is not None
980
+ [middle_token_id ]
981
+ if middle_token_id >= 0 and suffix is not None
982
982
else []
983
983
)
984
984
)
@@ -1360,7 +1360,7 @@ def logit_bias_processor(
1360
1360
if echo :
1361
1361
text_str = prompt + text_str
1362
1362
1363
- if not suffix_token_id and suffix is not None :
1363
+ if suffix_token_id < 0 and suffix is not None :
1364
1364
text_str = text_str + suffix
1365
1365
1366
1366
logprobs_or_none : Optional [CompletionLogprobs ] = None
0 commit comments