From a81ed7f66f47841fbcebd212681e7fcdcfe60a6e Mon Sep 17 00:00:00 2001 From: Justin McReynolds Date: Tue, 12 Nov 2024 11:38:51 -0800 Subject: [PATCH] Add token counts to llm message history --- static/ips/assets/js/llmChat.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static/ips/assets/js/llmChat.js b/static/ips/assets/js/llmChat.js index af91e216..5c781ce4 100644 --- a/static/ips/assets/js/llmChat.js +++ b/static/ips/assets/js/llmChat.js @@ -56,7 +56,11 @@ async function sendMessage() { content: [{ type: "text", text: data.content}] }); - insertMessageIntoUi('assistant', "LLM: " + data.content); + const promptTokens = data.prompt_tokens; + const completionTokens = data.completion_tokens; + + const formattedResponse = `LLM: ${data.content} (prompt_tokens=${promptTokens}, completion_tokens=${completionTokens})`; + insertMessageIntoUi('assistant', formattedResponse); } catch (error) { console.error('Error sending message to LLM:', error); insertMessageIntoUi('error', 'Failed to get a response. Please try again.');