Skip to content

Commit e3da126

Browse files
committed
main : inject reverse prompt after EOS + update examples/chat.sh
1 parent 8af1991 commit e3da126

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

examples/chat.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ cd ..
1111
#
1212
# "--keep 48" is based on the contents of prompts/chat-with-bob.txt
1313
#
14-
./main -m ./models/7B/ggml-model-q4_0.bin -c 512 -b 1024 -n 256 --keep 48 \
15-
--repeat_penalty 1.0 --color -i \
16-
-r "User:" -f prompts/chat-with-bob.txt
14+
./main -m ./models/7B/ggml-model-q4_0.bin -c 512 -b 1024 -n -1 --keep 48 \
15+
--repeat_penalty 1.0 --color \
16+
-i --interactive-first \
17+
-r "User:" --in-prefix " " \
18+
-f prompts/chat-with-bob.txt

examples/main/main.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,14 @@ int main(int argc, char ** argv) {
634634
llama_grammar_accept_token(ctx, grammar, id);
635635
}
636636

637-
// replace end of text token with newline token when in interactive mode
637+
// replace end of text token with newline token and inject reverse prompt when in interactive mode
638638
if (id == llama_token_eos() && params.interactive && !params.instruct && !params.input_prefix_bos) {
639639
id = llama_token_nl();
640+
if (params.antiprompt.size() != 0) {
641+
// tokenize and inject first reverse prompt
642+
const auto first_antiprompt = ::llama_tokenize(ctx, params.antiprompt.front(), false);
643+
embd_inp.insert(embd_inp.end(), first_antiprompt.begin(), first_antiprompt.end());
644+
}
640645
}
641646

642647
last_n_tokens.erase(last_n_tokens.begin());

0 commit comments

Comments
 (0)