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