@@ -75,7 +75,7 @@ def __init__(self,
75
75
76
76
# add instruction as antiprompt
77
77
if (self .instruct ):
78
- self .first_antiprompt .append (self ._tokenize (self . inp_prefix . strip ()))
78
+ self .first_antiprompt .append (self ._tokenize (instruct_inp_prefix . strip (), False ))
79
79
80
80
# primer feed
81
81
if (len (primer ) > 0 ):
@@ -197,7 +197,8 @@ def generate(self):
197
197
198
198
# respect n_predict even if antiprompt is present
199
199
if (self .use_antiprompt () and self .remaining_tokens <= 0 and self .n_predict != - 1 ):
200
- self .embd_inp += self .first_antiprompt [0 ]
200
+ if not self .instruct :
201
+ self .embd_inp += self .first_antiprompt [0 ]
201
202
break
202
203
203
204
def __enter__ (self ):
@@ -213,7 +214,7 @@ def past(self):
213
214
214
215
# write input
215
216
def input (self , prompt : str ):
216
- if (self .instruct ):
217
+ if (self .instruct and self . last_n_tokens [ - len ( self . inp_prefix ):] != self . inp_prefix ):
217
218
self .embd_inp += self .inp_prefix
218
219
self .embd_inp += self ._tokenize (prompt )
219
220
if (self .instruct ):
@@ -284,5 +285,6 @@ def inp():
284
285
for i in m .output ():
285
286
print (i ,end = "" ,flush = True )
286
287
except KeyboardInterrupt :
287
- print (f"\n { USER_NAME } :" ,end = "" )
288
- m .input (f"\n { USER_NAME } :" )
288
+ if not m .instruct :
289
+ print (f"\n { USER_NAME } :" ,end = "" )
290
+ m .input (f"\n { USER_NAME } :" )
0 commit comments