Skip to content

Commit c862e8b

Browse files
author
Mug
committed
Fix repeating instructions and an antiprompt bug
1 parent 9cde797 commit c862e8b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: examples/low_level_api_chatllama_cpp.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self,
7575

7676
# add instruction as antiprompt
7777
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))
7979

8080
# primer feed
8181
if (len(primer) > 0):
@@ -197,7 +197,8 @@ def generate(self):
197197

198198
# respect n_predict even if antiprompt is present
199199
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]
201202
break
202203

203204
def __enter__(self):
@@ -213,7 +214,7 @@ def past(self):
213214

214215
# write input
215216
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):
217218
self.embd_inp += self.inp_prefix
218219
self.embd_inp += self._tokenize(prompt)
219220
if (self.instruct):
@@ -284,5 +285,6 @@ def inp():
284285
for i in m.output():
285286
print(i,end="",flush=True)
286287
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

Comments
 (0)