forked from open-webui/open-webui
		
	feat: human readable Generation Info total
Add new function to convert nanoseconds into `approximate_total:` for *Generation Info* tooltip.
This commit is contained in:
		
							parent
							
								
									0d3ce18a61
								
							
						
					
					
						commit
						23b674ddda
					
				
					 2 changed files with 27 additions and 1 deletions
				
			
		|  | @ -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'}<br/> | ||||
|                     eval_duration: ${ | ||||
| 											Math.round(((message.info.eval_duration ?? 0) / 1000000) * 100) / 100 ?? 'N/A' | ||||
| 										}ms</span>`, | ||||
| 										}ms<br/> | ||||
|                     approximate_total: ${ | ||||
| 											approximateToHumanReadable(message.info.total_duration) | ||||
| 										}</span>`, | ||||
| 				allowHTML: true | ||||
| 			}); | ||||
| 		} | ||||
|  |  | |||
|  | @ -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(' '); | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Self Denial
						Self Denial