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"
2323NEXT_PROMPT_FILE=" ${CHAT_SAVE_DIR} /next-prompt.txt"
2424NEXT_PROMPT_CACHE=" ${CHAT_SAVE_DIR} /next-cache.bin"
2525
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:]]+'
2829SED_DELETE_MESSAGES=" /^(${USER_NAME} :|${AI_NAME} :|\\ .\\ .\\ .)/,\$ d"
2930
3031CTX_SIZE=2048
@@ -129,15 +130,12 @@ while read -e line; do
129130
130131 printf ' '
131132
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
136134 echo >&2 " Couldn't get number of tokens from ./llama-cli output!"
137135 exit 1
138136 fi
139137
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 " ) " )
141139
142140 if (( n_tokens > CTX_ROTATE_POINT)) ; then
143141 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