From 23b674dddaf477bb4a61ede1f89f882ff47cca31 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sat, 13 Apr 2024 22:27:00 -0600 Subject: [PATCH 1/3] feat: human readable Generation Info total Add new function to convert nanoseconds into `approximate_total:` for *Generation Info* tooltip. --- .../chat/Messages/ResponseMessage.svelte | 6 ++++- src/lib/utils/index.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 7aa6f65ce..d44e6443a 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -18,6 +18,7 @@ import { synthesizeOpenAISpeech } from '$lib/apis/openai'; import { imageGenerations } from '$lib/apis/images'; import { + approximateToHumanReadable, extractSentences, revertSanitizedResponseContent, sanitizeResponseContent @@ -122,7 +123,10 @@ eval_count: ${message.info.eval_count ?? 'N/A'}
eval_duration: ${ Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A' - }ms`, + }ms
+ approximate_total: ${ + approximateToHumanReadable(message.info.total_duration) + }`, allowHTML: true }); } diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index e9a4e229b..559e7391f 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -467,3 +467,25 @@ export const blobToFile = (blob, fileName) => { const file = new File([blob], fileName, { type: blob.type }); return file; }; + +export const approximateToHumanReadable = (nanoseconds: number) => { + const seconds = Math.floor((nanoseconds / 1e+9) % 60); + const minutes = Math.floor((nanoseconds / 6e+10) % 60); + const hours = Math.floor((nanoseconds / 3.6e+12) % 24); + + const results: string[] = []; + + if (seconds >= 0) { + results.push(`${seconds}s`); + } + + if (minutes > 0) { + results.push(`${minutes}m`); + } + + if (hours > 0) { + results.push(`${hours}h`); + } + + return results.reverse().join(' '); +}; From d2d255228c1ba35a673c7a07736f68ebf3e70377 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sat, 13 Apr 2024 22:39:10 -0600 Subject: [PATCH 2/3] Format fix --- src/lib/utils/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 559e7391f..338430bb5 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -469,9 +469,9 @@ export const blobToFile = (blob, fileName) => { }; export const approximateToHumanReadable = (nanoseconds: number) => { - const seconds = Math.floor((nanoseconds / 1e+9) % 60); - const minutes = Math.floor((nanoseconds / 6e+10) % 60); - const hours = Math.floor((nanoseconds / 3.6e+12) % 24); + const seconds = Math.floor((nanoseconds / 1e9) % 60); + const minutes = Math.floor((nanoseconds / 6e10) % 60); + const hours = Math.floor((nanoseconds / 3.6e12) % 24); const results: string[] = []; From b93337e62fc9a5f247889a41c1b36cc11c75dca3 Mon Sep 17 00:00:00 2001 From: Self Denial Date: Sat, 13 Apr 2024 22:41:22 -0600 Subject: [PATCH 3/3] Format fix --- src/lib/components/chat/Messages/ResponseMessage.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index d44e6443a..3789faaa9 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -124,9 +124,9 @@ eval_duration: ${ Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A' }ms
- approximate_total: ${ - approximateToHumanReadable(message.info.total_duration) - }`, + approximate_total: ${approximateToHumanReadable( + message.info.total_duration + )}`, allowHTML: true }); }