From d4084006431ff0a83c320b8e337b31b68e332c45 Mon Sep 17 00:00:00 2001
From: "use-tusk[bot]" <144006087+use-tusk[bot]@users.noreply.github.com>
Date: Tue, 8 Oct 2024 17:12:55 +0000
Subject: [PATCH] fix: address review from kavinvalli
---
.../shared/themed/table/requestRow.tsx | 3 +-
web/components/shared/utils/formatNumber.ts | 3 --
web/components/templates/cache/cachePage.tsx | 3 +-
.../experiments/id/experimentIdPage.tsx | 3 +-
.../templates/properties/propertyPanel.tsx | 30 +++++++++----------
.../templates/requestsV2/requestCard.tsx | 3 +-
.../templates/requestsV2/requestRow.tsx | 3 +-
.../templates/users/id/userIdPage.tsx | 9 +++---
web/components/templates/users/userModal.tsx | 9 ++----
9 files changed, 26 insertions(+), 40 deletions(-)
delete mode 100755 web/components/shared/utils/formatNumber.ts
diff --git a/web/components/shared/themed/table/requestRow.tsx b/web/components/shared/themed/table/requestRow.tsx
index e54049c577..4724554045 100644
--- a/web/components/shared/themed/table/requestRow.tsx
+++ b/web/components/shared/themed/table/requestRow.tsx
@@ -2,7 +2,6 @@ import { ChevronRightIcon } from "@heroicons/react/20/solid";
import { NormalizedRequest } from "../../../templates/requestsV2/builder/abstractRequestBuilder";
import ModelPill from "../../../templates/requestsV2/modelPill";
import StatusBadge from "../../../templates/requestsV2/statusBadge";
-import { formatNumber } from "../../../templates/users/initialColumns";
import { clsx } from "../../clsx";
import { useState } from "react";
import CostPill from "../../../templates/requestsV2/costPill";
@@ -54,7 +53,7 @@ const RequestRow = (props: RequestRowProps) => {
{Number(row.latency) / 1000}s
{row.cost !== null ? (
- ${formatNumber(row.cost)}
+ ${row.cost.toFixed(4)}
) : row.status && row.status.code === 200 ? (
) : (
diff --git a/web/components/shared/utils/formatNumber.ts b/web/components/shared/utils/formatNumber.ts
deleted file mode 100755
index a9239bb814..0000000000
--- a/web/components/shared/utils/formatNumber.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export function formatNumber(num: number): string {
- return num.toFixed(4);
-}
diff --git a/web/components/templates/cache/cachePage.tsx b/web/components/templates/cache/cachePage.tsx
index 9cd78e327f..d1bccba09f 100644
--- a/web/components/templates/cache/cachePage.tsx
+++ b/web/components/templates/cache/cachePage.tsx
@@ -19,7 +19,6 @@ import UpgradeProModal from "../../shared/upgradeProModal";
import Link from "next/link";
import { useRouter } from "next/router";
import AuthHeader from "../../shared/authHeader";
-import { formatNumber } from "../users/initialColumns";
import { useOrg } from "@/components/layout/organizationContext";
import { DiffHighlight } from "../welcome/diffHighlight";
import { FeatureUpgradeCard } from "@/components/shared/helicone/FeatureUpgradeCard";
@@ -102,7 +101,7 @@ const CachePage = (props: CachePageProps) => {
{
id: "savings",
label: "All Time Savings",
- value: `$${formatNumber(chMetrics.totalSavings.data?.data ?? 0)}`,
+ value: `$${(chMetrics.totalSavings.data?.data ?? 0).toFixed(4)}`,
isLoading: isAnyLoading,
icon: BanknotesIcon,
},
diff --git a/web/components/templates/prompts/experiments/id/experimentIdPage.tsx b/web/components/templates/prompts/experiments/id/experimentIdPage.tsx
index 0f71768cfa..e2a1dcdee8 100644
--- a/web/components/templates/prompts/experiments/id/experimentIdPage.tsx
+++ b/web/components/templates/prompts/experiments/id/experimentIdPage.tsx
@@ -11,7 +11,6 @@ import { usePrompt } from "../../../../../services/hooks/prompts/prompts";
import ArrayDiffViewer from "../../id/arrayDiffViewer";
import ScoresTable from "../scoresTable";
import { SimpleTable } from "../../../../shared/table/simpleTable";
-import { formatNumber } from "../../../users/initialColumns";
interface PromptIdPageProps {
id: string;
@@ -59,7 +58,7 @@ const ExperimentIdPage = (props: PromptIdPageProps) => {
return score.value;
}
if (score.valueType === "number") {
- return formatNumber(score.value as number);
+ return (score.value as number).toFixed(4);
}
return score.value;
};
diff --git a/web/components/templates/properties/propertyPanel.tsx b/web/components/templates/properties/propertyPanel.tsx
index 6d17595925..bbc6ec2227 100644
--- a/web/components/templates/properties/propertyPanel.tsx
+++ b/web/components/templates/properties/propertyPanel.tsx
@@ -35,7 +35,6 @@ import ExportButton from "../../shared/themed/table/exportButton";
import { UIFilterRow } from "../../shared/themed/themedAdvancedFilters";
import ThemedTableHeader from "../../shared/themed/themedHeader";
import useSearchParams from "../../shared/utils/useSearchParams";
-import { formatNumber } from "../users/initialColumns";
interface PropertyPanelProps {
property: string;
@@ -188,7 +187,9 @@ const PropertyPanel = (props: PropertyPanelProps) => {
) : (
- {+(keyMetrics.totalRequests?.data?.data?.toFixed(2) ?? 0)}
+ {keyMetrics.totalRequests.data?.data
+ ? keyMetrics.totalRequests.data.data.toFixed(2)
+ : 0}
)}
@@ -285,26 +286,23 @@ const PropertyPanel = (props: PropertyPanelProps) => {
{propertyValue.total_requests}
- ${formatNumber(propertyValue.total_cost, 6)}
+ $
+ {propertyValue.total_cost.toFixed(6)}
- {formatNumber(
- propertyValue.avg_completion_tokens_per_request,
- 6
- )}
+ {
+ propertyValue.avg_completion_tokens_per_request.toFixed(6)
+ }
- {formatNumber(
- propertyValue.avg_latency_per_request,
- 6
- )}
+ {
+ propertyValue.avg_latency_per_request.toFixed(6)
+ }
- $
- {formatNumber(
- propertyValue.average_cost_per_request,
- 6
- )}
+ ${
+ propertyValue.average_cost_per_request.toFixed(6)
+ }
>
diff --git a/web/components/templates/requestsV2/requestCard.tsx b/web/components/templates/requestsV2/requestCard.tsx
index e056104153..dff0a014fc 100644
--- a/web/components/templates/requestsV2/requestCard.tsx
+++ b/web/components/templates/requestsV2/requestCard.tsx
@@ -2,7 +2,6 @@ import { useState } from "react";
import { updateRequestFeedback } from "../../../services/lib/requests";
import useNotification from "../../shared/notification/useNotification";
import FeedbackButtons from "../feedback/thumbsUpThumbsDown";
-import { formatNumber } from "../users/initialColumns";
import { NormalizedRequest } from "./builder/abstractRequestBuilder";
import CostPill from "./costPill";
import { CustomProperties } from "./customProperties";
@@ -82,7 +81,7 @@ const RequestCard = (props: RequestCardProps) => {
) : request.cost ? (
- ${formatNumber(request.cost)}
+ ${request.cost.toFixed(4)}
) : (
diff --git a/web/components/templates/requestsV2/requestRow.tsx b/web/components/templates/requestsV2/requestRow.tsx
index b30c5737f3..3e30a0751a 100644
--- a/web/components/templates/requestsV2/requestRow.tsx
+++ b/web/components/templates/requestsV2/requestRow.tsx
@@ -21,7 +21,6 @@ import StatusBadge from "./statusBadge";
import ThemedModal from "../../shared/themed/themedModal";
import NewDataset from "../datasets/NewDataset";
import { convertToUSDateFormat } from "../../shared/utils/dateConvertor";
-import { formatNumber } from "../../shared/utils/formatNumber";
function getPathName(url: string) {
try {
@@ -269,7 +268,7 @@ const RequestRow = (props: {
{request.cost !== null && request.cost !== undefined
- ? `$${formatNumber(request.cost)}`
+ ? `$${request.cost.toFixed(4)}`
: request.status.statusType === "success"
? "Calculating..."
: "N/A"}
diff --git a/web/components/templates/users/id/userIdPage.tsx b/web/components/templates/users/id/userIdPage.tsx
index 9cc39c3872..0e3bec088f 100644
--- a/web/components/templates/users/id/userIdPage.tsx
+++ b/web/components/templates/users/id/userIdPage.tsx
@@ -8,7 +8,6 @@ import {
} from "@tremor/react";
import { useUserId } from "../../../../services/hooks/users";
import LoadingAnimation from "../../../shared/loadingAnimation";
-import { formatNumber } from "../initialColumns";
import StyledAreaChart from "../../dashboard/styledAreaChart";
import RequestsPageV2 from "../../requestsV2/requestsPageV2";
import { ElementType } from "react";
@@ -85,7 +84,7 @@ const UserIdPage = (props: UserIdPageProps) => {
Total Cost
- ${formatNumber(Number(user.cost || 0), 6)}
+ ${Number(user.cost || 0).toFixed(6)}
@@ -122,7 +121,7 @@ const UserIdPage = (props: UserIdPageProps) => {
Average Requests per day
- {formatNumber(user.average_requests_per_day_active)}
+ {user.average_requests_per_day_active.toFixed(4)}
{" "}
@@ -130,7 +129,7 @@ const UserIdPage = (props: UserIdPageProps) => {
Average Tokens per request
- {formatNumber(user.average_tokens_per_request)}
+ {user.average_tokens_per_request.toFixed(4)}
{" "}
@@ -192,7 +191,7 @@ const UserIdPage = (props: UserIdPageProps) => {
colors={["green"]}
showLegend={false}
valueFormatter={(value) => {
- return `$${formatNumber(value, 6)}`;
+ return `$${Number(value).toFixed(6)}`;
}}
curveType="monotone"
/>
diff --git a/web/components/templates/users/userModal.tsx b/web/components/templates/users/userModal.tsx
index de944cddb9..b98292584b 100644
--- a/web/components/templates/users/userModal.tsx
+++ b/web/components/templates/users/userModal.tsx
@@ -3,7 +3,6 @@ import { UserMetric } from "../../../lib/api/users/users";
import { clsx } from "../../shared/clsx";
import ThemedModal from "../../shared/themed/themedModal";
import { getUSDateFromString } from "../../shared/utils/utils";
-import { formatNumber } from "./initialColumns";
import {
ClipboardDocumentIcon,
TableCellsIcon,
@@ -272,9 +271,7 @@ const UserModal = (props: UserModalProps) => {
Total Cost
- {`$${formatNumber(
- user.cost
- )}`}
+ {`$${user.cost.toFixed(4)}`}
@@ -303,7 +300,7 @@ const UserModal = (props: UserModalProps) => {
Average Requests per Day
- {formatNumber(user.average_requests_per_day_active)}
+ {user.average_requests_per_day_active.toFixed(4)}
@@ -312,7 +309,7 @@ const UserModal = (props: UserModalProps) => {
{user.average_tokens_per_request
- ? formatNumber(user.average_tokens_per_request)
+ ? user.average_tokens_per_request.toFixed(4)
: "N/A"}