Skip to content

Commit

Permalink
Merge pull request #1607 from Agenta-AI/issue-1584/-hide-cost-and-usa…
Browse files Browse the repository at this point in the history
…ge-in-playground-and-evaluation-when-these-are-not-specified

Hide cost and usage in playground and evaluation when these are not specified
  • Loading branch information
aakrem authored May 13, 2024
2 parents f091cd0 + 6b2c66b commit e426e4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions agenta-web/src/components/Playground/Views/TestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import duration from "dayjs/plugin/duration"
import {useQueryParam} from "@/hooks/useQuery"
import {formatLatency} from "@/lib/helpers/formatters"
import {formatCurrency, formatLatency, formatTokenUsage} from "@/lib/helpers/formatters"

dayjs.extend(relativeTime)
dayjs.extend(duration)
Expand Down Expand Up @@ -218,13 +218,13 @@ const BoxComponent: React.FC<BoxComponentProps> = ({
<p>
Tokens:{" "}
{additionalData.usage !== null
? JSON.stringify(additionalData.usage.total_tokens)
? formatTokenUsage(additionalData.usage.total_tokens)
: 0}
</p>
<p>
Cost:{" "}
{additionalData.cost !== null
? `$${additionalData.cost.toFixed(4)}`
? formatCurrency(additionalData.cost)
: "$0.00"}
</p>
<p>
Expand Down
18 changes: 15 additions & 3 deletions agenta-web/src/lib/helpers/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ const intlNumber = new Intl.NumberFormat("en-US", {
const intlCurrency = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 4,
maximumFractionDigits: 6,
})

export const formatNumber = (value = 0) => {
return intlNumber.format(value)
}

export const formatCurrency = (value = 0) => {
return intlCurrency.format(value)
export const formatCurrency = (value: number) => {
if (value === null) {
return "-"
} else {
return intlCurrency.format(value)
}
}

export const formatLatency = (value = 0) => {
return `${Math.round(value * 1000)}ms`
}

export const formatTokenUsage = (value: number) => {
if (value === null) {
return "-"
} else {
return value
}
}

0 comments on commit e426e4d

Please sign in to comment.