mirror of
https://github.com/arc53/DocsGPT
synced 2024-11-17 21:26:26 +00:00
Denominations on tokens
This commit is contained in:
parent
6e15403f60
commit
8834a19743
@ -2,6 +2,24 @@ import { DocumentsProps } from '../models/misc';
|
|||||||
import Trash from '../assets/trash.svg';
|
import Trash from '../assets/trash.svg';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
// Utility function to format numbers
|
||||||
|
const formatTokens = (tokens: number): string => {
|
||||||
|
const roundToTwoDecimals = (num: number): string => {
|
||||||
|
return (Math.round((num + Number.EPSILON) * 100) / 100).toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (tokens >= 1_000_000_000) {
|
||||||
|
return roundToTwoDecimals(tokens / 1_000_000_000) + 'b';
|
||||||
|
} else if (tokens >= 1_000_000) {
|
||||||
|
return roundToTwoDecimals(tokens / 1_000_000) + 'm';
|
||||||
|
} else if (tokens >= 1_000) {
|
||||||
|
return roundToTwoDecimals(tokens / 1_000) + 'k';
|
||||||
|
} else {
|
||||||
|
return tokens.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const Documents: React.FC<DocumentsProps> = ({
|
const Documents: React.FC<DocumentsProps> = ({
|
||||||
documents,
|
documents,
|
||||||
handleDeleteDocument,
|
handleDeleteDocument,
|
||||||
@ -40,7 +58,7 @@ const Documents: React.FC<DocumentsProps> = ({
|
|||||||
{document.date}
|
{document.date}
|
||||||
</td>
|
</td>
|
||||||
<td className="border-r border-t px-4 py-2">
|
<td className="border-r border-t px-4 py-2">
|
||||||
{document.tokens ? document.tokens : ''}
|
{document.tokens ? formatTokens(+document.tokens) : ''}
|
||||||
</td>
|
</td>
|
||||||
<td className="border-r border-t px-4 py-2">
|
<td className="border-r border-t px-4 py-2">
|
||||||
{document.location === 'remote'
|
{document.location === 'remote'
|
||||||
|
Loading…
Reference in New Issue
Block a user