diff --git a/config.py b/config.py
index 63f622c..58ff42a 100644
--- a/config.py
+++ b/config.py
@@ -9,7 +9,7 @@ import logging
log = logging.getLogger("caic")
-VERSION = "v0.17.18"
+VERSION = "v0.17.19"
OLLAMA_BASE = os.environ.get("OLLAMA_BASE", "http://localhost:11434")
LLAMA_SERVER_BASE = os.environ.get("LLAMA_SERVER_BASE", "http://192.168.50.108:8081")
SEARXNG_BASE = "http://localhost:8888"
diff --git a/templates/index.html b/templates/index.html
index 6822697..a4c0cd6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -1133,6 +1133,7 @@ async function sendSearch() {
setStreamingState(true);
const ttrStart = performance.now();
let ttr = 0;
+ let tokenCount = 0;
try {
abortController = new AbortController();
const resp = await authFetch('/api/search', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ conversation_id: currentConvId, query, model }), signal: abortController.signal });
@@ -1154,7 +1155,7 @@ async function sendSearch() {
if (data.error) { textEl.textContent = 'Error: ' + data.error; setStreamingState(false); return; }
if (data.conversation_id && !currentConvId) { currentConvId = data.conversation_id; await loadConversations(); }
if (data.search_results) { textEl.innerHTML = '
🔍 Found ' + data.search_results + ' results, summarizing...
'; }
- if (data.token) { if (firstToken) { textEl.innerHTML = ''; firstToken = false; ttr = performance.now() - ttrStart; } fullText += data.token; textEl.innerHTML = renderMarkdown(fullText); scrollToTop(); }
+ if (data.token) { if (firstToken) { textEl.innerHTML = ''; firstToken = false; ttr = performance.now() - ttrStart; tokenCount = 0; } fullText += data.token; tokenCount++; textEl.innerHTML = renderMarkdown(fullText); scrollToTop(); }
if (data.raw_results) {
let rawHtml = '🔍 View raw search results (' + data.raw_results.length + ')
';
data.raw_results.forEach(r => {
@@ -1179,6 +1180,13 @@ async function sendSearch() {
const ttrSec = ttr / 1000;
roleLabel.innerHTML += `ttr: ${ttrSec.toFixed(1)}s`;
}
+ if (tokenCount > 0) {
+ const pt = data.prompt_tokens || 0;
+ const totalTokens = pt + tokenCount;
+ const ctxLen = data.context_length || 4096;
+ const usedPct = Math.round((totalTokens / ctxLen) * 100);
+ roleLabel.innerHTML += `tok: ${totalTokens}/${ctxLen} ${usedPct}%`;
+ }
}
conversationHistory.push({ role: 'assistant', content: fullText });
addCopyButtons(assistantDiv);
@@ -1362,8 +1370,7 @@ async function sendMessage() {
}
if (tokenCount > 0 && roleLabel) {
const pt = data.prompt_tokens || 0;
- const ct = data.completion_tokens || 0;
- const totalTokens = pt + ct;
+ const totalTokens = pt + tokenCount;
const ctxLen = data.context_length || 4096;
const usedPct = Math.round((totalTokens / ctxLen) * 100);
roleLabel.innerHTML += `tok: ${totalTokens}/${ctxLen} ${usedPct}%`;