From 32036e2093879403a1d89c99bd402b3821153c2e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 1 Oct 2025 18:46:43 -0700 Subject: [PATCH] feat(ui/): add common rate limit type form, for reuse for tpm/rpm across create + edit key --- .../RateLimitTypeFormItem.tsx | 98 +++++++++++++++++++ .../organisms/create_key_button.tsx | 89 +++-------------- .../components/templates/key_edit_view.tsx | 13 +++ 3 files changed, 124 insertions(+), 76 deletions(-) create mode 100644 ui/litellm-dashboard/src/components/common_components/RateLimitTypeFormItem.tsx diff --git a/ui/litellm-dashboard/src/components/common_components/RateLimitTypeFormItem.tsx b/ui/litellm-dashboard/src/components/common_components/RateLimitTypeFormItem.tsx new file mode 100644 index 00000000000..e0607d50681 --- /dev/null +++ b/ui/litellm-dashboard/src/components/common_components/RateLimitTypeFormItem.tsx @@ -0,0 +1,98 @@ +import React from "react" +import { Form, Select, Tooltip } from "antd" +import { InfoCircleOutlined } from "@ant-design/icons" + +const { Option } = Select + +interface RateLimitTypeFormItemProps { + /** The type of rate limit - either 'tpm' or 'rpm' */ + type: 'tpm' | 'rpm' + /** The form field name */ + name: string + /** Whether to show detailed descriptions (default: true) */ + showDetailedDescriptions?: boolean + /** Additional CSS classes */ + className?: string + /** Initial value for the field */ + initialValue?: string | null + /** Form instance for setting field values */ + form?: any + /** Custom onChange handler */ + onChange?: (value: string) => void +} + +export const RateLimitTypeFormItem: React.FC = ({ + type, + name, + showDetailedDescriptions = true, + className = "", + initialValue = null, + form, + onChange +}) => { + const limitTypeUpper = type.toUpperCase() + const limitTypeLower = type.toLowerCase() + + const handleChange = (value: string) => { + if (form) { + form.setFieldValue(name, value) + } + if (onChange) { + onChange(value) + } + } + + const tooltipTitle = `Select 'guaranteed_throughput' to prevent overallocating ${limitTypeUpper} limit when the key belongs to a Team with specific ${limitTypeUpper} limits.` + + return ( + + {limitTypeUpper} Rate Limit Type{' '} + + + + + } + name={name} + initialValue={initialValue} + className={className} + > + + + ) +} + +export default RateLimitTypeFormItem diff --git a/ui/litellm-dashboard/src/components/organisms/create_key_button.tsx b/ui/litellm-dashboard/src/components/organisms/create_key_button.tsx index e367565bae0..4c26c6cb76b 100644 --- a/ui/litellm-dashboard/src/components/organisms/create_key_button.tsx +++ b/ui/litellm-dashboard/src/components/organisms/create_key_button.tsx @@ -35,6 +35,7 @@ import MCPServerSelector from "../mcp_server_management/MCPServerSelector" import ModelAliasManager from "../common_components/ModelAliasManager" import NotificationsManager from "../molecules/notifications_manager" import KeyLifecycleSettings from "../common_components/KeyLifecycleSettings" +import RateLimitTypeFormItem from "../common_components/RateLimitTypeFormItem" const { Option } = Select; @@ -810,46 +811,14 @@ const CreateKey: React.FC = ({ > - - TPM Rate Limit Type {' '} - - - - - } + - - + initialValue={null} + form={form} + showDetailedDescriptions={true} + /> = ({ > - - RPM Rate Limit Type {' '} - - - - - } + - - + initialValue={null} + form={form} + showDetailedDescriptions={true} + /> diff --git a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx index 07a311da893..89453274d6e 100644 --- a/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx +++ b/ui/litellm-dashboard/src/components/templates/key_edit_view.tsx @@ -13,6 +13,7 @@ import { fetchMCPAccessGroups } from "../networking" import { mapInternalToDisplayNames, mapDisplayToInternalNames } from "../callback_info_helpers" import GuardrailSelector from "@/components/guardrails/GuardrailSelector" import KeyLifecycleSettings from "../common_components/KeyLifecycleSettings" +import RateLimitTypeFormItem from "../common_components/RateLimitTypeFormItem" interface KeyEditViewProps { keyData: KeyResponse @@ -222,10 +223,22 @@ export function KeyEditView({ + + + +