diff --git a/ui/litellm-dashboard/src/components/CostTrackingSettings/add_margin_form.tsx b/ui/litellm-dashboard/src/components/CostTrackingSettings/add_margin_form.tsx index 8c6237a0c9b..98a34c0217f 100644 --- a/ui/litellm-dashboard/src/components/CostTrackingSettings/add_margin_form.tsx +++ b/ui/litellm-dashboard/src/components/CostTrackingSettings/add_margin_form.tsx @@ -1,8 +1,20 @@ import React from "react"; -import { TextInput, Button } from "@tremor/react"; -import { Select as AntdSelect, Form, Tooltip, Radio } from "antd"; -import { InfoCircleOutlined } from "@ant-design/icons"; -import { Providers, provider_map, providerLogoMap } from "../provider_info_helpers"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { Select as AntdSelect, Form } from "antd"; +import { Info } from "lucide-react"; +import { + Providers, + provider_map, + providerLogoMap, +} from "../provider_info_helpers"; import { MarginConfig } from "./types"; import { handleImageError } from "./provider_display_helpers"; @@ -19,6 +31,17 @@ interface AddMarginFormProps { onAddProvider: () => void; } +const InfoTip: React.FC<{ children: React.ReactNode }> = ({ children }) => ( + + + + + + {children} + + +); + const AddMarginForm: React.FC = ({ marginConfig, selectedProvider, @@ -35,11 +58,12 @@ const AddMarginForm: React.FC = ({
+ Provider - - - + + Select 'Global' to apply margin to all providers, or + select a specific provider + } rules={[{ required: true, message: "Please select a provider" }]} @@ -53,66 +77,87 @@ const AddMarginForm: React.FC = ({ size="large" optionFilterProp="children" filterOption={(input, option) => - String(option?.label ?? "").toLowerCase().includes(input.toLowerCase()) + String(option?.label ?? "") + .toLowerCase() + .includes(input.toLowerCase()) } > - +
Global (All Providers)
- {Object.entries(Providers).map(([providerEnum, providerDisplayName]) => { - const providerValue = provider_map[providerEnum as keyof typeof provider_map]; - // Only show providers that don't already have a margin configured - if (providerValue && marginConfig[providerValue]) { - return null; - } - return ( - -
- {`${providerEnum} handleImageError(e, providerDisplayName)} - /> - {providerDisplayName} -
-
- ); - })} + {Object.entries(Providers).map( + ([providerEnum, providerDisplayName]) => { + const providerValue = + provider_map[providerEnum as keyof typeof provider_map]; + if (providerValue && marginConfig[providerValue]) { + return null; + } + return ( + +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {`${providerEnum} handleImageError(e, providerDisplayName)} + /> + {providerDisplayName} +
+
+ ); + }, + )}
+ Margin Type - - - + + Choose how to apply the margin: percentage-based or fixed amount + } rules={[{ required: true, message: "Please select a margin type" }]} > - onMarginTypeChange(e.target.value)} - className="w-full" + onValueChange={(v) => + onMarginTypeChange(v as "percentage" | "fixed") + } + className="flex gap-4" > - Percentage-based - Fixed Amount - + + + {marginType === "percentage" && ( + Margin Percentage - - - + + Enter a percentage value (e.g., 10 for 10% margin) + } rules={[ @@ -120,11 +165,15 @@ const AddMarginForm: React.FC = ({ { validator: (_, value) => { if (!value) { - return Promise.reject(new Error("Please enter a margin percentage")); + return Promise.reject( + new Error("Please enter a margin percentage"), + ); } const numValue = parseFloat(value); if (isNaN(numValue) || numValue < 0 || numValue > 1000) { - return Promise.reject(new Error("Percentage must be between 0 and 1000")); + return Promise.reject( + new Error("Percentage must be between 0 and 1000"), + ); } return Promise.resolve(); }, @@ -132,13 +181,13 @@ const AddMarginForm: React.FC = ({ ]} >
- onPercentageChange(e.target.value)} + className="rounded-lg flex-1" /> - % + %
)} @@ -146,11 +195,12 @@ const AddMarginForm: React.FC = ({ {marginType === "fixed" && ( + Fixed Margin Amount - - - + + Enter a fixed amount in USD (e.g., 0.001 for $0.001 per + request) + } rules={[ @@ -158,11 +208,15 @@ const AddMarginForm: React.FC = ({ { validator: (_, value) => { if (!value) { - return Promise.reject(new Error("Please enter a fixed amount")); + return Promise.reject( + new Error("Please enter a fixed amount"), + ); } const numValue = parseFloat(value); if (isNaN(numValue) || numValue < 0) { - return Promise.reject(new Error("Fixed amount must be non-negative")); + return Promise.reject( + new Error("Fixed amount must be non-negative"), + ); } return Promise.resolve(); }, @@ -170,23 +224,22 @@ const AddMarginForm: React.FC = ({ ]} >
- $ - $ + onFixedAmountChange(e.target.value)} + className="rounded-lg flex-1" />
)} -
-