v0.17.19: fix token count badge — use client-side tokenCount instead of server completion_tokens; add tok badge to search responses
This commit is contained in:
@@ -9,7 +9,7 @@ import logging
|
|||||||
|
|
||||||
log = logging.getLogger("caic")
|
log = logging.getLogger("caic")
|
||||||
|
|
||||||
VERSION = "v0.17.18"
|
VERSION = "v0.17.19"
|
||||||
OLLAMA_BASE = os.environ.get("OLLAMA_BASE", "http://localhost:11434")
|
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")
|
LLAMA_SERVER_BASE = os.environ.get("LLAMA_SERVER_BASE", "http://192.168.50.108:8081")
|
||||||
SEARXNG_BASE = "http://localhost:8888"
|
SEARXNG_BASE = "http://localhost:8888"
|
||||||
|
|||||||
+10
-3
@@ -1133,6 +1133,7 @@ async function sendSearch() {
|
|||||||
setStreamingState(true);
|
setStreamingState(true);
|
||||||
const ttrStart = performance.now();
|
const ttrStart = performance.now();
|
||||||
let ttr = 0;
|
let ttr = 0;
|
||||||
|
let tokenCount = 0;
|
||||||
try {
|
try {
|
||||||
abortController = new AbortController();
|
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 });
|
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.error) { textEl.textContent = 'Error: ' + data.error; setStreamingState(false); return; }
|
||||||
if (data.conversation_id && !currentConvId) { currentConvId = data.conversation_id; await loadConversations(); }
|
if (data.conversation_id && !currentConvId) { currentConvId = data.conversation_id; await loadConversations(); }
|
||||||
if (data.search_results) { textEl.innerHTML = '<div class="search-indicator">🔍 Found ' + data.search_results + ' results, summarizing...</div>'; }
|
if (data.search_results) { textEl.innerHTML = '<div class="search-indicator">🔍 Found ' + data.search_results + ' results, summarizing...</div>'; }
|
||||||
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) {
|
if (data.raw_results) {
|
||||||
let rawHtml = '<details class="raw-results"><summary>🔍 View raw search results (' + data.raw_results.length + ')</summary><ul>';
|
let rawHtml = '<details class="raw-results"><summary>🔍 View raw search results (' + data.raw_results.length + ')</summary><ul>';
|
||||||
data.raw_results.forEach(r => {
|
data.raw_results.forEach(r => {
|
||||||
@@ -1179,6 +1180,13 @@ async function sendSearch() {
|
|||||||
const ttrSec = ttr / 1000;
|
const ttrSec = ttr / 1000;
|
||||||
roleLabel.innerHTML += `<span class="ttr-badge search">ttr: ${ttrSec.toFixed(1)}s</span>`;
|
roleLabel.innerHTML += `<span class="ttr-badge search">ttr: ${ttrSec.toFixed(1)}s</span>`;
|
||||||
}
|
}
|
||||||
|
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 += `<span class="tok-badge">tok: ${totalTokens}/${ctxLen} ${usedPct}%</span>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
conversationHistory.push({ role: 'assistant', content: fullText });
|
conversationHistory.push({ role: 'assistant', content: fullText });
|
||||||
addCopyButtons(assistantDiv);
|
addCopyButtons(assistantDiv);
|
||||||
@@ -1362,8 +1370,7 @@ async function sendMessage() {
|
|||||||
}
|
}
|
||||||
if (tokenCount > 0 && roleLabel) {
|
if (tokenCount > 0 && roleLabel) {
|
||||||
const pt = data.prompt_tokens || 0;
|
const pt = data.prompt_tokens || 0;
|
||||||
const ct = data.completion_tokens || 0;
|
const totalTokens = pt + tokenCount;
|
||||||
const totalTokens = pt + ct;
|
|
||||||
const ctxLen = data.context_length || 4096;
|
const ctxLen = data.context_length || 4096;
|
||||||
const usedPct = Math.round((totalTokens / ctxLen) * 100);
|
const usedPct = Math.round((totalTokens / ctxLen) * 100);
|
||||||
roleLabel.innerHTML += `<span class="tok-badge">tok: ${totalTokens}/${ctxLen} ${usedPct}%</span>`;
|
roleLabel.innerHTML += `<span class="tok-badge">tok: ${totalTokens}/${ctxLen} ${usedPct}%</span>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user