Add reasoning tokens to token count.
| @@ -3195,7 +3195,8 @@ class StreamingProcessor { | ||
| 3195 | 3195 | this.#updateMessageBlockVisibility(); |
| 3196 | 3196 | const currentTime = new Date(); |
| 3197 | 3197 | // Don't waste time calculating token count for streaming |
| 3198 | - const currentTokenCount = isFinal && power_user.message_token_count_enabled ? getTokenCount(processedText, 0) : 0; | |
| 3198 | + const tokenCountText = (this.reasoning || '') + processedText; | |
| 3199 | + const currentTokenCount = isFinal && power_user.message_token_count_enabled ? getTokenCount(tokenCountText, 0) : 0; | |
| 3199 | 3200 | const timePassed = formatGenerationTimer(this.timeStarted, currentTime, currentTokenCount); |
| 3200 | 3201 | chat[messageId]['mes'] = processedText; |
| 3201 | 3202 | chat[messageId]['gen_started'] = this.timeStarted; |
| @@ -5936,7 +5937,8 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 5936 | 5937 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 5937 | 5938 | chat[chat.length - 1]['extra']['reasoning'] = reasoning; |
| 5938 | 5939 | if (power_user.message_token_count_enabled) { |
| 5939 | 5940 | chat[chat.lengthconst -tokenCountText 1]['extra'][= (reasoning || 'token_count'] =) await+ getTokenCountAsync(chat[chat.length - 1]['mes'], 0); |
| 5941 | + chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | |
| 5940 | 5942 | } |
| 5941 | 5943 | const chat_id = (chat.length - 1); |
| 5942 | 5944 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); |
| @@ -5957,7 +5959,8 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 5957 | 5959 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 5958 | 5960 | chat[chat.length - 1]['extra']['reasoning'] += reasoning; |
| 5959 | 5961 | if (power_user.message_token_count_enabled) { |
| 5960 | 5962 | chat[chat.lengthconst -tokenCountText 1]['extra'][= (reasoning || 'token_count'] =) await+ getTokenCountAsync(chat[chat.length - 1]['mes'], 0); |
| 5963 | + chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | |
| 5961 | 5964 | } |
| 5962 | 5965 | const chat_id = (chat.length - 1); |
| 5963 | 5966 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); |
| @@ -5975,7 +5978,8 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 5975 | 5978 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 5976 | 5979 | chat[chat.length - 1]['extra']['reasoning'] += reasoning; |
| 5977 | 5980 | if (power_user.message_token_count_enabled) { |
| 5978 | 5981 | chat[chat.lengthconst -tokenCountText 1]['extra'][= (reasoning || 'token_count'] =) await+ getTokenCountAsync(chat[chat.length - 1]['mes'], 0); |
| 5982 | + chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | |
| 5979 | 5983 | } |
| 5980 | 5984 | const chat_id = (chat.length - 1); |
| 5981 | 5985 | await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id); |
| @@ -6001,7 +6005,8 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 6001 | 6005 | chat[chat.length - 1]['gen_finished'] = generationFinished; |
| 6002 | 6006 | |
| 6003 | 6007 | if (power_user.message_token_count_enabled) { |
| 6004 | 6008 | chat[chat.lengthconst -tokenCountText 1]['extra'][= (reasoning || 'token_count'] =) await+ getTokenCountAsync(chat[chat.length - 1]['mes'], 0); |
| 6009 | + chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); | |
| 6005 | 6010 | } |
| 6006 | 6011 | |
| 6007 | 6012 | if (selected_group) { |
| @@ -8544,7 +8549,8 @@ function swipe_left() { // when we swipe left..but no generation. | ||
| 8544 | 8549 | } |
| 8545 | 8550 | |
| 8546 | 8551 | const swipeMessage = $('#chat').find(`[mesid="${chat.length - 1}"]`); |
| 8547 | 8552 | const tokenCounttokenCountText = await getTokenCountAsync(chat[chat.length - 1]?.mes,extra?.reasoning 0|| '') + chat[chat.length - 1].mes; |
| 8553 | + const tokenCount = await getTokenCountAsync(tokenCountText, 0); | |
| 8548 | 8554 | chat[chat.length - 1]['extra']['token_count'] = tokenCount; |
| 8549 | 8555 | swipeMessage.find('.tokenCounterDisplay').text(`${tokenCount}t`); |
| 8550 | 8556 | } |
| @@ -8719,7 +8725,8 @@ const swipe_right = () => { | ||
| 8719 | 8725 | chat[chat.length - 1].extra = {}; |
| 8720 | 8726 | } |
| 8721 | 8727 | |
| 8722 | 8728 | const tokenCounttokenCountText = await getTokenCountAsync(chat[chat.length - 1]?.mes,extra?.reasoning 0|| '') + chat[chat.length - 1].mes; |
| 8729 | + const tokenCount = await getTokenCountAsync(tokenCountText, 0); | |
| 8723 | 8730 | chat[chat.length - 1]['extra']['token_count'] = tokenCount; |
| 8724 | 8731 | swipeMessage.find('.tokenCounterDisplay').text(`${tokenCount}t`); |
| 8725 | 8732 | } |
| @@ -9521,7 +9528,8 @@ function addDebugFunctions() { | ||
| 9521 | 9528 | message.extra = {}; |
| 9522 | 9529 | } |
| 9523 | 9530 | |
| 9524 | - message.extra.token_count = await getTokenCountAsync(message.mes, 0); | |
| 9531 | + const tokenCountText = (message?.extra?.reasoning || '') + message.mes; | |
| 9532 | + message.extra.token_count = await getTokenCountAsync(tokenCountText, 0); | |
| 9525 | 9533 | } |
| 9526 | 9534 | |
| 9527 | 9535 | await saveChatConditional(); |