diff --git a/lib/ai.js b/lib/ai.js index 4955b7cf4..6ae5f16b9 100644 --- a/lib/ai.js +++ b/lib/ai.js @@ -187,7 +187,7 @@ class AiAssistant { // this approach was tested via https://platform.openai.com/tokenizer // we need it to display current usage tokens usage so users could analyze effectiveness of AI - const inputString = messages.map(m => m.content).join(' '); + const inputString = messages.map(m => m.content).join(' ').trim(); const numWords = (inputString.match(/[^\s\-:=]+/g) || []).length; // 2.5 token is constant for average HTML input