Skip to content

Commit 6daa09d

Browse files
authored
examples : read chat prompts from a template file (LostRuins#1196)
1 parent bca9ad9 commit 6daa09d

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

examples/chat-13B.sh

+18-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22

3+
set -e
4+
35
cd "$(dirname "$0")/.." || exit
46

57
MODEL="${MODEL:-./models/13B/ggml-model-q4_0.bin}"
6-
USER_NAME="${USER_NAME:-User}"
8+
PROMPT_TEMPLATE=${PROMPT_TEMPLATE:-./prompts/chat.txt}
9+
USER_NAME="${USER_NAME:-USER}"
710
AI_NAME="${AI_NAME:-ChatLLaMa}"
811

912
# Adjust to the number of CPU cores you want to use.
@@ -15,39 +18,24 @@ N_PREDICTS="${N_PREDICTS:-2048}"
1518
# For example, override the context size by doing: ./chatLLaMa --ctx_size 1024
1619
GEN_OPTIONS="${GEN_OPTIONS:---ctx_size 2048 --temp 0.7 --top_k 40 --top_p 0.5 --repeat_last_n 256 --batch_size 1024 --repeat_penalty 1.17647}"
1720

21+
DATE_TIME=$(date +%H:%M)
22+
DATE_YEAR=$(date +%Y)
23+
24+
PROMPT_FILE=$(mktemp -t llamacpp_prompt.XXXXXXX.txt)
25+
26+
sed -e "s/\[\[USER_NAME\]\]/$USER_NAME/g" \
27+
-e "s/\[\[AI_NAME\]\]/$AI_NAME/g" \
28+
-e "s/\[\[DATE_TIME\]\]/$DATE_TIME/g" \
29+
-e "s/\[\[DATE_YEAR\]\]/$DATE_YEAR/g" \
30+
$PROMPT_TEMPLATE > $PROMPT_FILE
31+
1832
# shellcheck disable=SC2086 # Intended splitting of GEN_OPTIONS
1933
./main $GEN_OPTIONS \
2034
--model "$MODEL" \
2135
--threads "$N_THREAD" \
2236
--n_predict "$N_PREDICTS" \
2337
--color --interactive \
38+
--file ${PROMPT_FILE} \
2439
--reverse-prompt "${USER_NAME}:" \
25-
--prompt "
26-
Text transcript of a never ending dialog, where ${USER_NAME} interacts with an AI assistant named ${AI_NAME}.
27-
${AI_NAME} is helpful, kind, honest, friendly, good at writing and never fails to answer ${USER_NAME}'s requests immediately and with details and precision.
28-
There are no annotations like (30 seconds passed...) or (to himself), just what ${USER_NAME} and ${AI_NAME} say aloud to each other.
29-
The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long.
30-
The transcript only includes text, it does not include markup like HTML and Markdown.
31-
32-
$USER_NAME: Hello, $AI_NAME!
33-
$AI_NAME: Hello $USER_NAME! How may I help you today?
34-
$USER_NAME: What year is it?
35-
$AI_NAME: We are in $(date +%Y).
36-
$USER_NAME: Please tell me the largest city in Europe.
37-
$AI_NAME: The largest city in Europe is Moscow, the capital of Russia.
38-
$USER_NAME: What can you tell me about Moscow?
39-
$AI_NAME: Moscow, on the Moskva River in western Russia, is the nation's cosmopolitan capital. In its historic core is the Kremlin, a complex that's home to the president and tsarist treasures in the Armoury. Outside its walls is Red Square, Russia’s symbolic center.
40-
$USER_NAME: What is a cat?
41-
$AI_NAME: A cat is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae.
42-
$USER_NAME: How do I pass command line arguments to a Node.js program?
43-
$AI_NAME: The arguments are stored in process.argv.
44-
45-
argv[0] is the path to the Node. js executable.
46-
argv[1] is the path to the script file.
47-
argv[2] is the first argument passed to the script.
48-
argv[3] is the second argument passed to the script and so on.
49-
$USER_NAME: Name a color.
50-
$AI_NAME: Blue.
51-
$USER_NAME: What time is it?
52-
$AI_NAME: It is $(date +%H:%M).
53-
$USER_NAME:" "$@"
40+
--in-prefix ' ' \
41+
"$@"

prompts/chat-with-vicuna-v0.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A chat between a curious human ("[[USER_NAME]]") and an artificial intelligence assistant ("[[AI_NAME]]"). The assistant gives helpful, detailed, and polite answers to the human's questions.
2+
3+
### [[USER_NAME]]: Hello, [[AI_NAME]].
4+
### [[AI_NAME]]: Hello. How may I help you today?
5+
### [[USER_NAME]]: Please tell me the largest city in Europe.
6+
### [[AI_NAME]]: Sure. The largest city in Europe is Moscow, the capital of Russia.
7+
### [[USER_NAME]]:

prompts/chat-with-vicuna-v1.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A chat between a curious human ("[[USER_NAME]]") and an artificial intelligence assistant ("[[AI_NAME]]"). The assistant gives helpful, detailed, and polite answers to the human's questions.
2+
3+
[[USER_NAME]]: Hello, [[AI_NAME]].
4+
[[AI_NAME]]: Hello. How may I help you today?
5+
[[USER_NAME]]: Please tell me the largest city in Europe.
6+
[[AI_NAME]]: Sure. The largest city in Europe is Moscow, the capital of Russia.
7+
[[USER_NAME]]:

prompts/chat.txt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Text transcript of a never ending dialog, where [[USER_NAME]] interacts with an AI assistant named [[AI_NAME]].
2+
[[AI_NAME]] is helpful, kind, honest, friendly, good at writing and never fails to answer [[USER_NAME]]'s requests immediately and with details and precision.
3+
There are no annotations like (30 seconds passed...) or (to himself), just what [[USER_NAME]] and [[AI_NAME]] say aloud to each other.
4+
The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long.
5+
The transcript only includes text, it does not include markup like HTML and Markdown.
6+
7+
[[USER_NAME]]: Hello, [[AI_NAME]]!
8+
[[AI_NAME]]: Hello [[USER_NAME]]! How may I help you today?
9+
[[USER_NAME]]: What year is it?
10+
[[AI_NAME]]: We are in [[DATE_YEAR]].
11+
[[USER_NAME]]: Please tell me the largest city in Europe.
12+
[[AI_NAME]]: The largest city in Europe is Moscow, the capital of Russia.
13+
[[USER_NAME]]: What can you tell me about Moscow?
14+
[[AI_NAME]]: Moscow, on the Moskva River in western Russia, is the nation's cosmopolitan capital. In its historic core is the Kremlin, a complex that's home to the president and tsarist treasures in the Armoury. Outside its walls is Red Square, Russia’s symbolic center.
15+
[[USER_NAME]]: What is a cat?
16+
[[AI_NAME]]: A cat is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae.
17+
[[USER_NAME]]: How do I pass command line arguments to a Node.js program?
18+
[[AI_NAME]]: The arguments are stored in process.argv.
19+
20+
argv[0] is the path to the Node. js executable.
21+
argv[1] is the path to the script file.
22+
argv[2] is the first argument passed to the script.
23+
argv[3] is the second argument passed to the script and so on.
24+
[[USER_NAME]]: Name a color.
25+
[[AI_NAME]]: Blue.
26+
[[USER_NAME]]: What time is it?
27+
[[AI_NAME]]: It is [[DATE_TIME]].
28+
[[USER_NAME]]:

0 commit comments

Comments
 (0)