diff --git a/src/lib/apis/streaming/index.ts b/src/lib/apis/streaming/index.ts
index f91edad83..722cca9a1 100644
--- a/src/lib/apis/streaming/index.ts
+++ b/src/lib/apis/streaming/index.ts
@@ -18,6 +18,8 @@ type ResponseUsage = {
completion_tokens: number;
/** Sum of the above two fields */
total_tokens: number;
+ /** Any other fields that aren't part of the base OpenAI spec */
+ [other: string]: unknown;
};
// createOpenAITextStream takes a responseBody with a SSE response,
diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte
index eeb2f330f..9c9707e6d 100644
--- a/src/lib/components/chat/Chat.svelte
+++ b/src/lib/components/chat/Chat.svelte
@@ -1393,7 +1393,7 @@
}
if (usage) {
- responseMessage.info = { ...usage, openai: true };
+ responseMessage.info = { ...usage, openai: true, usage };
}
if (citations) {
diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte
index ff1983cbd..7bd6563fe 100644
--- a/src/lib/components/chat/Messages/ResponseMessage.svelte
+++ b/src/lib/components/chat/Messages/ResponseMessage.svelte
@@ -18,7 +18,8 @@
extractParagraphsForAudio,
extractSentencesForAudio,
cleanText,
- getMessageContentParts
+ getMessageContentParts,
+ sanitizeResponseContent
} from '$lib/utils';
import { WEBUI_BASE_URL } from '$lib/constants';
@@ -73,6 +74,7 @@
prompt_eval_duration?: number;
total_duration?: number;
load_duration?: number;
+ usage?: unknown;
};
annotation?: { type: string; rating: number };
}
@@ -621,30 +623,32 @@
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
- >
${sanitizeResponseContent( + JSON.stringify(message.info.usage, null, 2) + .replace(/"([^(")"]+)":/g, '$1:') + .slice(1, -1) + .split('\n') + .map((line) => line.slice(2)) + .map((line) => (line.endsWith(',') ? line.slice(0, -1) : line)) + .join('\n') + )}` + : `prompt_tokens: ${message.info.prompt_tokens ?? 'N/A'}