AI/ML
Inference Latency Card - Model Performance
Monitor inference latency and response times for ML models. Track p50, p95, p99 latencies and optimize model serving performance.
Inference Latency Card
The Inference Latency Card tracks model inference response times, helping teams ensure models meet performance SLAs.
Preview
Installation
npx shadcn@latest add https://vectormotion.vercel.app/registry/inference-latency-card.jsonInference Latency Card
'use client'import React from 'react';import { Zap, Activity } from 'lucide-react';import { motion } from 'motion/react';import { clsx, type ClassValue } from "clsx"import { twMerge } from "tailwind-merge"import { ResponsiveContainer, LineChart, Line, XAxis, YAxis, Tooltip, ReferenceLine } from 'recharts';function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs))}interface LatencyData { time: string; ms: number; [key: string]: any;}interface InferenceLatencyCardProps { className?: string; title?: string; subtitle?: string; currentLatency?: string; latencyChange?: string; data?: LatencyData[]; sloThreshold?: number;}const DEFAULT_DATA: LatencyData[] = [ { time: '0ms', ms: 42 }, { time: '10ms', ms: 45 }, { time: '20ms', ms: 52 }, { time: '30ms', ms: 48 }, { time: '40ms', ms: 41 }, { time: '50ms', ms: 45 }, { time: '60ms', ms: 43 },];const DEFAULT_TITLE = "Latency";const DEFAULT_SUBTITLE = "p95 Inference";const DEFAULT_CURRENT_LATENCY = "45ms";const DEFAULT_LATENCY_CHANGE = "-2ms";const DEFAULT_SLO_THRESHOLD = 50;export const InferenceLatencyCard: React.FC<InferenceLatencyCardProps> = ({ className = "", title = DEFAULT_TITLE, subtitle = DEFAULT_SUBTITLE, currentLatency = DEFAULT_CURRENT_LATENCY, latencyChange = DEFAULT_LATENCY_CHANGE, data = DEFAULT_DATA, sloThreshold = DEFAULT_SLO_THRESHOLD,}) => { return ( <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.5, delay: 0.1 }} className={cn( "relative overflow-hidden rounded-2xl border border-border bg-card text-card-foreground shadow-sm transition-all hover:border-yellow-300 dark:hover:border-yellow-700 hover:shadow-md flex flex-col h-full", className )} > <div className="p-5 flex flex-col h-full relative z-10"> <div className="mb-4 flex items-start justify-between"> <div> <h3 className="font-bold text-lg text-foreground"> {title} </h3> <div className="flex items-center gap-2 mt-1"> <span className="text-2xl font-bold text-foreground">{currentLatency}</span> <span className="text-xs font-medium text-emerald-500 bg-emerald-500/10 px-1.5 py-0.5 rounded-full"> {latencyChange} </span> </div> <p className="text-sm text-muted-foreground mt-1"> {subtitle} </p> </div> <div className="rounded-lg border-2 border-yellow-100 dark:border-yellow-800 p-2 text-yellow-500 dark:text-yellow-400 flex items-center justify-center"> <Zap className="h-5 w-5" /> </div> </div> <div className="flex-1 w-full min-h-[120px] relative"> <ResponsiveContainer width="100%" height="100%"> <LineChart data={data}> <Tooltip cursor={{ strokeDasharray: '3 3' }} content={() => null} /> <ReferenceLine y={sloThreshold} stroke="#ef4444" strokeDasharray="3 3" label={{ value: 'SLO', position: 'insideBottomRight', fill: '#ef4444', fontSize: 10 }} /> <Line type="monotone" dataKey="ms" stroke="#eab308" strokeWidth={2} dot={{ r: 2, fill: '#eab308' }} activeDot={{ r: 4 }} /> </LineChart> </ResponsiveContainer> </div> <div className="absolute -bottom-4 -right-4 z-0 opacity-5 pointer-events-none"> <Activity className="w-40 h-40 text-yellow-500" /> </div> </div> </motion.div> );};Props
Prop
Type
Usage
This component is a demo card displaying inference latency metrics with animated visualizations and dark mode support.