File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,9 @@ CUR_PROMPT_CACHE="${CHAT_SAVE_DIR}/current-cache.bin"
23
23
NEXT_PROMPT_FILE=" ${CHAT_SAVE_DIR} /next-prompt.txt"
24
24
NEXT_PROMPT_CACHE=" ${CHAT_SAVE_DIR} /next-cache.bin"
25
25
26
- SESSION_SIZE_MSG_PATTERN=' main: session file matches [[:digit:]]+ / [[:digit:]]+'
27
- SAMPLE_TIME_MSG_PATTERN=' sample time =[[:space:]]+[[:digit:]]+.[[:digit:]]+ ms /[[:space:]]+[[:digit:]]+'
26
+ SESSION_AND_SAMPLE_PATTERN=' main: session file matches [[:digit:]]+ / [[:digit:]]+' \
27
+ ' |' \
28
+ ' sampling time =[[:space:]]+[[:digit:]]+.[[:digit:]]+ ms /[[:space:]]+[[:digit:]]+'
28
29
SED_DELETE_MESSAGES=" /^(${USER_NAME} :|${AI_NAME} :|\\ .\\ .\\ .)/,\$ d"
29
30
30
31
CTX_SIZE=2048
@@ -129,15 +130,12 @@ while read -e line; do
129
130
130
131
printf ' '
131
132
132
- # HACK get num tokens from debug message
133
- # TODO get both messages in one go
134
- if ! session_size_msg=" $( tail -n30 " $LOG " | grep -oE " $SESSION_SIZE_MSG_PATTERN " ) " ||
135
- ! sample_time_msg=" $( tail -n10 " $LOG " | grep -oE " $SAMPLE_TIME_MSG_PATTERN " ) " ; then
133
+ if ! session_and_sample_msg=$( tail -n30 " $LOG " | grep -oE " $SESSION_AND_SAMPLE_PATTERN " ) ; then
136
134
echo >&2 " Couldn't get number of tokens from ./llama-cli output!"
137
135
exit 1
138
136
fi
139
137
140
- n_tokens=$(( $(cut - d / - f 2 <<< " $session_size_msg ") + $ (cut - d/ - f2 <<< " $sample_time_msg " )) )
138
+ n_tokens=$( awk ' {sum+=$1} END {print sum} ' <<< " $ (cut -d/ -f2 <<< " $session_and_sample_msg " ) " )
141
139
142
140
if (( n_tokens > CTX_ROTATE_POINT)) ; then
143
141
tail -c+$(( n_prompt_len_pre + 1 )) " $CUR_PROMPT_FILE " >> " $NEXT_PROMPT_FILE "
You can’t perform that action at this time.
0 commit comments