Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

feat: support vector display on table and details popover, custom date range (#218)

Aman Agarwalb539bf6079ba
diff --git a/src/client/package-lock.json b/src/client/package-lock.json
index c58b7978..cc88497c 100644
--- a/src/client/package-lock.json
+++ b/src/client/package-lock.json
@@ -15,6 +15,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
+ "@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
@@ -33,6 +34,7 @@
"next-auth": "^4.24.7",
"next-themes": "^0.3.0",
"react": "^18",
+ "react-day-picker": "^8.10.1",
"react-dom": "^18",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.6",
@@ -927,6 +929,43 @@
}
}
},
+ "node_modules/@radix-ui/react-popover": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.0.7.tgz",
+ "integrity": "sha512-shtvVnlsxT6faMnK/a7n0wptwBD23xc1Z5mdrtKLwVEfsEMXodS0r5s0/g5P0hX//EKYZS2sxUjqfzlg52ZSnQ==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-compose-refs": "1.0.1",
+ "@radix-ui/react-context": "1.0.1",
+ "@radix-ui/react-dismissable-layer": "1.0.5",
+ "@radix-ui/react-focus-guards": "1.0.1",
+ "@radix-ui/react-focus-scope": "1.0.4",
+ "@radix-ui/react-id": "1.0.1",
+ "@radix-ui/react-popper": "1.1.3",
+ "@radix-ui/react-portal": "1.0.4",
+ "@radix-ui/react-presence": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-slot": "1.0.2",
+ "@radix-ui/react-use-controllable-state": "1.0.1",
+ "aria-hidden": "^1.1.1",
+ "react-remove-scroll": "2.5.5"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-popper": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.1.3.tgz",
@@ -5364,6 +5403,19 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-day-picker": {
+ "version": "8.10.1",
+ "resolved": "https://registry.npmjs.org/react-day-picker/-/react-day-picker-8.10.1.tgz",
+ "integrity": "sha512-TMx7fNbhLk15eqcMt+7Z7S2KF7mfTId/XJDjKE8f+IUcFn0l08/kI4FiYTL/0yuOLmEcbR4Fwe3GJf/NiiMnPA==",
+ "funding": {
+ "type": "individual",
+ "url": "https://github.com/sponsors/gpbl"
+ },
+ "peerDependencies": {
+ "date-fns": "^2.28.0 || ^3.0.0",
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
"node_modules/react-dom": {
"version": "18.2.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
diff --git a/src/client/package.json b/src/client/package.json
index 07e847a5..0189d04c 100644
--- a/src/client/package.json
+++ b/src/client/package.json
@@ -17,6 +17,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
+ "@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
@@ -35,6 +36,7 @@
"next-auth": "^4.24.7",
"next-themes": "^0.3.0",
"react": "^18",
+ "react-day-picker": "^8.10.1",
"react-dom": "^18",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.6",
diff --git a/src/client/src/app/(playground)/dashboard/number-stats.tsx b/src/client/src/app/(playground)/dashboard/number-stats.tsx
index 3dd5270d..75fff354 100644
--- a/src/client/src/app/(playground)/dashboard/number-stats.tsx
+++ b/src/client/src/app/(playground)/dashboard/number-stats.tsx
@@ -24,7 +24,7 @@ function NumberStats() {
icon={Timer}
textSuffix="s"
parser={(value: any) =>
- integerParser(`${value}`, TraceMapping.requestDuration.multiplier)
+ integerParser(`${value}`, TraceMapping.requestDuration.offset)
}
url="/api/metrics/request/duration/average"
/>
diff --git a/src/client/src/app/(playground)/requests/request-details.tsx b/src/client/src/app/(playground)/requests/request-details.tsx
index 76a159d0..4a84354b 100644
--- a/src/client/src/app/(playground)/requests/request-details.tsx
+++ b/src/client/src/app/(playground)/requests/request-details.tsx
@@ -2,27 +2,18 @@ import { useRequest } from "@/app/(playground)/requests/request-context";
import Image from "next/image";
import { round } from "lodash";
import { format } from "date-fns";
-import { normalizeTrace } from "@/helpers/trace";
-import { TransformedTraceRow } from "@/constants/traces";
+import { getRequestDetailsDisplayKeys, normalizeTrace } from "@/helpers/trace";
+import { TraceMapping, TransformedTraceRow } from "@/constants/traces";
import {
- AudioLines,
- Boxes,
- Braces,
CalendarDays,
- CircleDollarSign,
- ClipboardType,
Clock,
- Container,
ExternalLink,
- Image as ImageIcon,
LucideIcon,
PyramidIcon,
- TicketPlus,
} from "lucide-react";
import {
Sheet,
SheetContent,
- SheetDescription,
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
@@ -43,6 +34,15 @@ const TagItem = ({
</div>
);
+const CodeItem = ({ label, text }: { label: string; text: string }) => (
+ <div className="flex flex-col space-y-3 mt-4">
+ <span className="text-sm text-stone-500 font-medium">{label} : </span>
+ <code className="text-sm inline-flex text-left items-center bg-stone-950 text-stone-200 rounded-md p-4">
+ {text}
+ </code>
+ </div>
+);
+
export default function RequestDetails() {
const [request, updateRequest] = useRequest();
@@ -53,6 +53,7 @@ export default function RequestDetails() {
if (!request) return null;
const normalizedItem: TransformedTraceRow = normalizeTrace(request);
+ const displayKeys = getRequestDetailsDisplayKeys(normalizedItem.type);
return (
<Sheet open onOpenChange={onClose}>
@@ -66,13 +67,13 @@ export default function RequestDetails() {
<div className="flex items-center mt-3">
<PyramidIcon size="12" />
<p className="ml-3 text-sm leading-none">
- {normalizedItem.provider}
+ {normalizedItem.provider || normalizedItem.system}
</p>
</div>
</div>
</SheetTitle>
</SheetHeader>
- <SheetDescription>
+ <div className="h-full w-full flex grow pb-8">
<div className="flex h-full w-full flex-col overflow-y-scroll">
<div className="relative py-6 flex-1 flex flex-col gap-3">
<div className="flex items-start flex-wrap gap-3">
@@ -86,87 +87,41 @@ export default function RequestDetails() {
title="Request duration : "
value={`${round(normalizedItem.requestDuration, 4)}s`}
/>
- <TagItem
- icon={Boxes}
- title="Model : "
- value={normalizedItem.model}
- />
- <TagItem
- icon={CircleDollarSign}
- title="Usage cost : "
- value={round(normalizedItem.cost, 6)}
- />
- {normalizedItem.promptTokens > 0 && (
- <TagItem
- icon={Braces}
- title="Prompt tokens : "
- value={normalizedItem.promptTokens}
- />
- )}
- {normalizedItem.totalTokens > 0 && (
- <TagItem
- icon={TicketPlus}
- title="Total tokens : "
- value={normalizedItem.totalTokens}
- />
- )}
- <TagItem
- icon={Container}
- title="Environment : "
- value={normalizedItem.environment}
- />
- {normalizedItem.audioVoice && (
- <TagItem
- icon={AudioLines}
- title="Audio voice : "
- value={normalizedItem.audioVoice}
- />
- )}
- {normalizedItem.imageSize && (
- <TagItem
- icon={ImageIcon}
- title="Image size : "
- value={normalizedItem.imageSize}
- />
- )}
- {normalizedItem.type && (
- <TagItem
- icon={ClipboardType}
- title="Type : "
- value={normalizedItem.type}
- />
+ {displayKeys.map(
+ (keyItem, index) =>
+ normalizedItem[keyItem] && (
+ <TagItem
+ key={`${keyItem}-${index}`}
+ icon={TraceMapping[keyItem].icon}
+ title={`${TraceMapping[keyItem].label} : `}
+ value={normalizedItem[keyItem]}
+ />
+ )
)}
</div>
+
+ {/* Prompts */}
{normalizedItem.prompt && (
- <div className="flex flex-col space-y-3 mt-4">
- <span className="text-sm text-stone-500 font-medium">
- Prompt :{" "}
- </span>
- <code className="text-sm inline-flex text-left items-center bg-stone-950 text-stone-200 rounded-md p-4">
- {normalizedItem.prompt}
- </code>
- </div>
+ <CodeItem
+ label={TraceMapping["prompt"].label}
+ text={normalizedItem.prompt}
+ />
)}
{normalizedItem.revisedPrompt && (
- <div className="flex flex-col space-y-3 mt-4">
- <span className="text-sm text-stone-500 font-medium">
- Revised Prompt :{" "}
- </span>
- <code className="text-sm inline-flex text-left items-center bg-stone-950 text-stone-200 rounded-md p-4">
- {normalizedItem.revisedPrompt}
- </code>
- </div>
+ <CodeItem
+ label={TraceMapping["revisedPrompt"].label}
+ text={normalizedItem.revisedPrompt}
+ />
)}
{normalizedItem.response && (
- <div className="flex flex-col space-y-3 mt-4">
- <span className="text-sm text-stone-500 font-medium">
- Response :{" "}
- </span>
- <code className="text-sm inline-flex text-left items-center bg-stone-950 text-stone-200 rounded-md p-4">
- {normalizedItem.response}
- </code>
- </div>
+ <CodeItem
+ label={TraceMapping["response"].label}
+ text={normalizedItem.response}
+ />
)}
+ {/* Prompts */}
+
+ {/* Image */}
{normalizedItem.image && normalizedItem.imageSize && (
<a
href={normalizedItem.image}
@@ -189,9 +144,42 @@ export default function RequestDetails() {
</span>
</a>
)}
+ {/* Image */}
+
+ {/* Vector */}
+ {normalizedItem.statement && (
+ <CodeItem
+ label={TraceMapping["statement"].label}
+ text={normalizedItem.statement}
+ />
+ )}
+
+ {normalizedItem.whereDocument && (
+ <CodeItem
+ label={TraceMapping["whereDocument"].label}
+ text={normalizedItem.whereDocument}
+ />
+ )}
+
+ {normalizedItem.filter && (
+ <CodeItem
+ label={TraceMapping["filter"].label}
+ text={normalizedItem.filter}
+ />
+ )}
+ {/* Vector */}
+
+ {/* Framework */}
+ {normalizedItem.retrievalSource && (
+ <CodeItem
+ label={TraceMapping["retrievalSource"].label}
+ text={normalizedItem.retrievalSource}
+ />
+ )}
+ {/* Framework */}
</div>
</div>
- </SheetDescription>
+ </div>
</SheetContent>
</Sheet>
);
diff --git a/src/client/src/app/(playground)/requests/request-table.tsx b/src/client/src/app/(playground)/requests/request-table.tsx
index 7b7dfb27..08c3fd8d 100644
--- a/src/client/src/app/(playground)/requests/request-table.tsx
+++ b/src/client/src/app/(playground)/requests/request-table.tsx
@@ -1,18 +1,14 @@
import { format } from "date-fns";
-import { fill, round } from "lodash";
+import { fill, isNil, round } from "lodash";
import { useRequest } from "./request-context";
import { ReactNode } from "react";
-import { normalizeTrace } from "@/helpers/trace";
-import { TraceRow, TransformedTraceRow } from "@/constants/traces";
+import { getRequestTableDisplayKeys, normalizeTrace } from "@/helpers/trace";
import {
- Boxes,
- Braces,
- CalendarDays,
- CircleDollarSign,
- Clock,
- PyramidIcon,
- TicketPlus,
-} from "lucide-react";
+ TraceMapping,
+ TraceRow,
+ TransformedTraceRow,
+} from "@/constants/traces";
+import { CalendarDays, Clock } from "lucide-react";
import IntermediateState from "@/components/(playground)/intermediate-state";
type RenderRowProps = {
@@ -62,6 +58,7 @@ const RenderRow = ({ item, isLoading }: RenderRowProps) => {
const onClick = () => !isLoading && updateRequest(item);
const normalizedItem: TransformedTraceRow = normalizeTrace(item);
+ const requestDisplayItems = getRequestTableDisplayKeys(normalizedItem.type);
return (
<div className="flex flex-col">
@@ -87,47 +84,29 @@ const RenderRow = ({ item, isLoading }: RenderRowProps) => {
}`}
onClick={onClick}
>
- <RowItem
- containerClass="w-3/12"
- label="App name"
- text={normalizedItem.applicationName}
- textClass="font-medium"
- />
- <RowItem
- containerClass="w-3/12"
- icon={<PyramidIcon size="16" />}
- label="Client"
- text={normalizedItem.provider}
- textClass="text-sm"
- />
- <RowItem
- containerClass="w-1.5/12"
- icon={<Boxes size="16" />}
- label="Model"
- text={normalizedItem.model}
- textClass="text-sm"
- />
- <RowItem
- containerClass="w-1.5/12"
- icon={<CircleDollarSign size="16" />}
- label="Usage cost"
- text={`${round(normalizedItem.cost, 6)}`}
- textClass="text-sm"
- />
- <RowItem
- containerClass="w-1.5/12"
- icon={<Braces size="16" />}
- label="Prompt Tokens"
- text={`${normalizedItem.promptTokens || "-"}`}
- textClass="text-sm"
- />
- <RowItem
- containerClass="w-1.5/12"
- icon={<TicketPlus size="16" />}
- label="Total Tokens"
- text={`${normalizedItem.totalTokens || "-"}`}
- textClass="text-sm"
- />
+ {requestDisplayItems.map((keyItem, index) => {
+ if (!keyItem || isNil(normalizedItem[keyItem]))
+ return (
+ <RowItem
+ key={`empty-${index}`}
+ containerClass={index <= 1 ? "w-3/12" : "w-1.5/12"}
+ label={""}
+ text={""}
+ textClass={index === 0 ? "font-medium" : "text-sm"}
+ />
+ );
+ const IconElement = TraceMapping[keyItem].icon;
+ return (
+ <RowItem
+ key={`${keyItem}-${index}`}
+ containerClass={index <= 1 ? "w-3/12" : "w-1.5/12"}
+ label={TraceMapping[keyItem].label}
+ text={normalizedItem[keyItem]}
+ icon={IconElement && <IconElement size="16" />}
+ textClass={index === 0 ? "font-medium" : "text-sm"}
+ />
+ );
+ })}
</div>
</div>
);
diff --git a/src/client/src/components/(playground)/filter.tsx b/src/client/src/components/(playground)/filter.tsx
index 7ddfee96..ca1d74f8 100644
--- a/src/client/src/components/(playground)/filter.tsx
+++ b/src/client/src/components/(playground)/filter.tsx
@@ -1,14 +1,16 @@
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { getFilterDetails, getUpdateFilter } from "@/selectors/filter";
import { useRootStore } from "@/store";
+import { DatePickerWithRange } from "@/components/ui/date-range-picker";
const DEFAULT_TIME_RANGE = "24H";
-const TIME_RANGE_TYPE: Record<"24H" | "7D" | "1M" | "3M", string> = {
+const TIME_RANGE_TYPE: Record<"24H" | "7D" | "1M" | "3M" | "CUSTOM", string> = {
"24H": "24H",
"7D": "7D",
"1M": "1M",
"3M": "3M",
+ CUSTOM: "CUSTOM",
};
const TIME_RANGE_TABS: { key: string; label: string }[] = Object.keys(
@@ -25,20 +27,28 @@ const Filter = () => {
updateFilter("timeLimit.type", key);
};
+ const onCustomDateChange = (start: Date, end: Date) => {
+ updateFilter("timeLimit.type", TIME_RANGE_TYPE.CUSTOM, { start, end });
+ };
+
return (
- <Tabs
- defaultValue={DEFAULT_TIME_RANGE}
- className="w-[400px] mb-4 md:mb-4"
- onValueChange={handleChange}
- >
- <TabsList>
- {TIME_RANGE_TABS.map(({ label, key }) => (
- <TabsTrigger key={key} value={key}>
- {label}
- </TabsTrigger>
- ))}
- </TabsList>
- </Tabs>
+ <div className="flex w-full mb-4 md:mb-4 gap-4">
+ <Tabs defaultValue={DEFAULT_TIME_RANGE} onValueChange={handleChange}>
+ <TabsList>
+ {TIME_RANGE_TABS.map(({ label, key }) => (
+ <TabsTrigger key={key} value={key}>
+ {label}
+ </TabsTrigger>
+ ))}
+ </TabsList>
+ </Tabs>
+ {filter.timeLimit.type === "CUSTOM" && (
+ <DatePickerWithRange
+ selectedDate={filter.timeLimit}
+ onCustomDateChange={onCustomDateChange}
+ />
+ )}
+ </div>
);
};
diff --git a/src/client/src/components/ui/button.tsx b/src/client/src/components/ui/button.tsx
index c5ced27f..184451dd 100644
--- a/src/client/src/components/ui/button.tsx
+++ b/src/client/src/components/ui/button.tsx
@@ -22,6 +22,7 @@ const buttonVariants = cva(
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
+ xs: "h-6 rounded-sm px-2 text-xs",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
diff --git a/src/client/src/components/ui/calendar.tsx b/src/client/src/components/ui/calendar.tsx
new file mode 100644
index 00000000..45ebf9be
--- /dev/null
+++ b/src/client/src/components/ui/calendar.tsx
@@ -0,0 +1,65 @@
+"use client"
+
+import * as React from "react"
+import { ChevronLeft, ChevronRight } from "lucide-react"
+import { DayPicker } from "react-day-picker"
+
+import { cn } from "@/lib/utils"
+import { buttonVariants } from "@/components/ui/button"
+
+export type CalendarProps = React.ComponentProps<typeof DayPicker>
+
+function Calendar({
+ className,
+ classNames,
+ showOutsideDays = true,
+ ...props
+}: CalendarProps) {
+ return (
+ <DayPicker
+ showOutsideDays={showOutsideDays}
+ className={cn("p-3", className)}
+ classNames={{
+ months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
+ month: "space-y-4",
+ caption: "flex justify-center pt-1 relative items-center",
+ caption_label: "text-sm font-medium",
+ nav: "space-x-1 flex items-center",
+ nav_button: cn(
+ buttonVariants({ variant: "outline" }),
+ "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
+ ),
+ nav_button_previous: "absolute left-1",
+ nav_button_next: "absolute right-1",
+ table: "w-full border-collapse space-y-1",
+ head_row: "flex",
+ head_cell:
+ "text-stone-500 rounded-md w-9 font-normal text-[0.8rem] dark:text-stone-400",
+ row: "flex w-full mt-2",
+ cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-stone-100/50 [&:has([aria-selected])]:bg-stone-100 first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20 dark:[&:has([aria-selected].day-outside)]:bg-stone-800/50 dark:[&:has([aria-selected])]:bg-stone-800",
+ day: cn(
+ buttonVariants({ variant: "ghost" }),
+ "h-9 w-9 p-0 font-normal aria-selected:opacity-100"
+ ),
+ day_range_end: "day-range-end",
+ day_selected:
+ "bg-stone-900 text-stone-50 hover:bg-stone-900 hover:text-stone-50 focus:bg-stone-900 focus:text-stone-50 dark:bg-stone-50 dark:text-stone-900 dark:hover:bg-stone-50 dark:hover:text-stone-900 dark:focus:bg-stone-50 dark:focus:text-stone-900",
+ day_outside:
+ "day-outside text-stone-500 opacity-50 aria-selected:bg-stone-100/50 aria-selected:text-stone-500 aria-selected:opacity-30 dark:text-stone-400 dark:aria-selected:bg-stone-800/50 dark:aria-selected:text-stone-400",
+ day_disabled: "text-stone-500 opacity-50 dark:text-stone-400",
+ day_range_middle:
+ "aria-selected:bg-stone-100 aria-selected:text-stone-900 dark:aria-selected:bg-stone-800 dark:aria-selected:text-stone-50",
+ day_hidden: "invisible",
+ ...classNames,
+ }}
+ components={{
+ IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
+ IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
+ }}
+ {...props}
+ />
+ )
+}
+Calendar.displayName = "Calendar"
+
+export { Calendar }
diff --git a/src/client/src/components/ui/date-range-picker.tsx b/src/client/src/components/ui/date-range-picker.tsx
new file mode 100644
index 00000000..1b04a1f1
--- /dev/null
+++ b/src/client/src/components/ui/date-range-picker.tsx
@@ -0,0 +1,88 @@
+"use client";
+
+import * as React from "react";
+import { addDays, format } from "date-fns";
+import { Calendar as CalendarIcon } from "lucide-react";
+import { DateRange } from "react-day-picker";
+
+import { cn } from "@/lib/utils";
+import { Button } from "@/components/ui/button";
+import { Calendar } from "@/components/ui/calendar";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+
+export function DatePickerWithRange({
+ className,
+ onCustomDateChange,
+ selectedDate,
+}: React.HTMLAttributes<HTMLDivElement> & {
+ onCustomDateChange: (start: Date, end: Date) => void;
+ selectedDate?: {
+ start?: Date;
+ end?: Date;
+ };
+}) {
+ const [date, setDate] = React.useState<DateRange | undefined>({
+ from: selectedDate?.start || addDays(new Date(), -15),
+ to: selectedDate?.end || new Date(),
+ });
+
+ const onCustomChange = React.useCallback(() => {
+ if (date?.from && date?.to) onCustomDateChange(date?.from, date?.to);
+ }, [date]);
+
+ return (
+ <div className={cn("grid gap-2", className)}>
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button
+ id="date"
+ variant={"outline"}
+ className={cn(
+ "justify-start text-left font-normal dark:bg-stone-900 dark:text-stone-100",
+ !date && "text-muted-foreground"
+ )}
+ >
+ <CalendarIcon className="mr-2 h-4 w-4" />
+ {date?.from ? (
+ date.to ? (
+ <>
+ {format(date.from, "LLL dd, y")} -{" "}
+ {format(date.to, "LLL dd, y")}
+ </>
+ ) : (
+ format(date.from, "LLL dd, y")
+ )
+ ) : (
+ <span>Pick a date</span>
+ )}
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-auto p-0" align="start">
+ <Calendar
+ initialFocus
+ mode="range"
+ defaultMonth={date?.from}
+ selected={date}
+ onSelect={setDate}
+ numberOfMonths={2}
+ />
+ <div className="flex justify-end px-3 pb-3">
+ <Button
+ className="w-20"
+ variant="default"
+ size="xs"
+ disabled={!date?.from || !date?.to}
+ onClick={onCustomChange}
+ >
+ Done
+ </Button>
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ );
+}
diff --git a/src/client/src/components/ui/popover.tsx b/src/client/src/components/ui/popover.tsx
new file mode 100644
index 00000000..8b35ce6d
--- /dev/null
+++ b/src/client/src/components/ui/popover.tsx
@@ -0,0 +1,31 @@
+"use client"
+
+import * as React from "react"
+import * as PopoverPrimitive from "@radix-ui/react-popover"
+
+import { cn } from "@/lib/utils"
+
+const Popover = PopoverPrimitive.Root
+
+const PopoverTrigger = PopoverPrimitive.Trigger
+
+const PopoverContent = React.forwardRef<
+ React.ElementRef<typeof PopoverPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
+ <PopoverPrimitive.Portal>
+ <PopoverPrimitive.Content
+ ref={ref}
+ align={align}
+ sideOffset={sideOffset}
+ className={cn(
+ "z-50 w-72 rounded-md border border-stone-200 bg-white p-4 text-stone-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-stone-800 dark:bg-stone-950 dark:text-stone-50",
+ className
+ )}
+ {...props}
+ />
+ </PopoverPrimitive.Portal>
+))
+PopoverContent.displayName = PopoverPrimitive.Content.displayName
+
+export { Popover, PopoverTrigger, PopoverContent }
diff --git a/src/client/src/constants/traces.ts b/src/client/src/constants/traces.ts
index daaa19d7..069cda76 100644
--- a/src/client/src/constants/traces.ts
+++ b/src/client/src/constants/traces.ts
@@ -1,8 +1,34 @@
import { ValueOf } from "@/utils/types";
+import {
+ AudioLines,
+ BookKey,
+ Boxes,
+ Braces,
+ CircleDollarSign,
+ CircleGauge,
+ ClipboardType,
+ Combine,
+ Container,
+ Crop,
+ DoorClosed,
+ Factory,
+ FileAudio2,
+ FileStack,
+ Fingerprint,
+ ImageIcon,
+ LucideIcon,
+ PyramidIcon,
+ ScanSearch,
+ ShieldCheck,
+ SquareCode,
+ SquareRadical,
+ TicketPlus,
+} from "lucide-react";
-export const SpanAttributesPrefix = "gen_ai";
+export const SpanAttributesGenAIPrefix = "gen_ai";
+export const SpanAttributesDBPrefix = "db";
-export type TraceKeyType = "string" | "integer" | "float";
+export type TraceKeyType = "string" | "integer" | "float" | "round";
export const TraceMapping: Record<
string,
@@ -12,7 +38,9 @@ export const TraceMapping: Record<
path: string;
prefix?: string;
isRoot?: boolean;
- multiplier?: number;
+ offset?: number;
+ icon?: LucideIcon;
+ defaultValue?: string | number | boolean;
}
> = {
// Root Key
@@ -22,6 +50,13 @@ export const TraceMapping: Record<
path: "Timestamp",
isRoot: true,
},
+ requestDuration: {
+ label: "Request Duration",
+ type: "integer",
+ path: "Duration",
+ isRoot: true,
+ offset: 10e-10,
+ },
id: {
label: "Id",
@@ -33,70 +68,83 @@ export const TraceMapping: Record<
label: "Provider",
type: "string",
path: "system",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: PyramidIcon,
},
applicationName: {
- label: "Application Name",
+ label: "App Name",
type: "string",
path: "application_name",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
environment: {
label: "Environment",
type: "string",
path: "environment",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: Container,
},
type: {
label: "Type",
type: "string",
path: "type",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: ClipboardType,
},
endpoint: {
label: "Endpoint",
type: "string",
path: "endpoint",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: DoorClosed,
},
temperature: {
label: "Temperature",
type: "float",
path: "temperature",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
// Tokens & Cost
cost: {
- label: "Cost",
- type: "float",
+ label: "Usage Cost",
+ type: "round",
path: "usage.cost",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: CircleDollarSign,
+ offset: 6,
+ defaultValue: "-",
},
promptTokens: {
label: "Prompt Tokens",
type: "integer",
path: "usage.prompt_tokens",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: Braces,
+ defaultValue: "-",
},
completionTokens: {
label: "Completion Tokens",
type: "integer",
path: "usage.completion_tokens",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ defaultValue: "-",
},
totalTokens: {
label: "Total Tokens",
type: "integer",
path: "usage.total_tokens",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: TicketPlus,
+ defaultValue: "-",
},
maxTokens: {
label: "Maximum tokens",
type: "integer",
path: "request.max_tokens",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ defaultValue: "-",
},
// Audio
@@ -105,19 +153,22 @@ export const TraceMapping: Record<
label: "Audio Voice",
type: "string",
path: "request.audio_voice",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: AudioLines,
},
audioFormat: {
label: "Audio Format",
type: "string",
path: "request.audio_response_format",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: FileAudio2,
},
audioSpeed: {
label: "Audio Speed",
type: "string",
path: "request.audio_speed",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: CircleGauge,
},
// Image
@@ -125,26 +176,29 @@ export const TraceMapping: Record<
image: {
label: "Image",
type: "string",
- path: "request.image",
- prefix: SpanAttributesPrefix,
+ path: "response.image.0",
+ prefix: SpanAttributesGenAIPrefix,
},
imageSize: {
label: "Image Size",
type: "string",
path: "request.image_size",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: ImageIcon,
},
imageQuality: {
label: "Image Quality",
type: "string",
path: "request.image_quality",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: ScanSearch,
},
imageStyle: {
label: "Image Style",
type: "string",
path: "request.image_style",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: Crop,
},
// Request and Response
@@ -152,38 +206,32 @@ export const TraceMapping: Record<
label: "Model",
type: "string",
path: "request.model",
- prefix: SpanAttributesPrefix,
- },
- requestDuration: {
- label: "Request Duration",
- type: "integer",
- path: "Duration",
- isRoot: true,
- multiplier: 10e-10,
+ prefix: SpanAttributesGenAIPrefix,
+ icon: Boxes,
},
prompt: {
label: "Prompt",
type: "string",
path: "content.prompt",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
finishReason: {
label: "Finish Reason",
type: "string",
path: "response.finish_reason",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
response: {
label: "Response",
type: "string",
path: "content.completion",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
randomSeed: {
label: "Random seed",
type: "float",
path: "request.seed",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
// Embedding
@@ -192,13 +240,13 @@ export const TraceMapping: Record<
label: "Embedding Format",
type: "string",
path: "request.embedding_format",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
embeddingDimension: {
label: "Embedding Dimension",
type: "string",
path: "request.embedding_dimension",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
// Fine tune
@@ -206,43 +254,134 @@ export const TraceMapping: Record<
label: "Training File",
type: "string",
path: "request.training_file",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
validationFile: {
label: "Validation File",
type: "string",
path: "request.validation_file",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
fineTuneBatchSize: {
label: "Fine Tune Batch Size",
type: "string",
path: "request.fine_tune_batch_size",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
learningRateMultiplier: {
label: "Learning rate multiplier",
type: "string",
path: "request.learning_rate_multiplier",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
fineTuneNEpochs: {
label: "Fine Tune and Epochs",
type: "string",
path: "request.fine_tune_n_epochs",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
fineTuneModelSuffix: {
label: "Fine Tune Model Suffix",
type: "string",
path: "request.fine_tune_model_suffix",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
},
finetuneJobStatus: {
label: "Fine Tune Job Status",
type: "string",
path: "request.fine_tune_status",
- prefix: SpanAttributesPrefix,
+ prefix: SpanAttributesGenAIPrefix,
+ },
+
+ // vector db
+ operation: {
+ label: "Operation",
+ type: "string",
+ path: "operation",
+ prefix: SpanAttributesDBPrefix,
+ icon: SquareRadical,
+ },
+ system: {
+ label: "Provider",
+ type: "string",
+ path: "system",
+ prefix: SpanAttributesDBPrefix,
+ icon: PyramidIcon,
+ },
+ documentsCount: {
+ label: "Documents count",
+ type: "integer",
+ path: "documents_count",
+ prefix: SpanAttributesDBPrefix,
+ icon: FileStack,
+ },
+ idsCount: {
+ label: "Ids count",
+ type: "integer",
+ path: "ids_count",
+ prefix: SpanAttributesDBPrefix,
+ icon: Fingerprint,
+ },
+ vectorCount: {
+ label: "Vector count",
+ type: "integer",
+ path: "vector_count",
+ prefix: SpanAttributesDBPrefix,
+ icon: Factory,
+ },
+ statement: {
+ label: "Statement",
+ type: "string",
+ path: "statement",
+ prefix: SpanAttributesDBPrefix,
+ },
+ nResults: {
+ label: "N results",
+ type: "string",
+ path: "n_results",
+ prefix: SpanAttributesDBPrefix,
+ },
+ collectionName: {
+ label: "Collection Name",
+ type: "string",
+ path: "collection.name",
+ prefix: SpanAttributesDBPrefix,
+ icon: Combine,
+ },
+ whereDocument: {
+ label: "Where Document",
+ type: "string",
+ path: "where_document",
+ prefix: SpanAttributesDBPrefix,
+ },
+ filter: {
+ label: "Filter",
+ type: "string",
+ path: "filter",
+ prefix: SpanAttributesDBPrefix,
+ },
+
+ // framework
+ owner: {
+ label: "Hub Owner",
+ type: "string",
+ path: "hub.owner",
+ prefix: SpanAttributesGenAIPrefix,
+ icon: ShieldCheck,
+ },
+ repo: {
+ label: "Hub Repo",
+ type: "string",
+ path: "hub.repo",
+ prefix: SpanAttributesGenAIPrefix,
+ icon: BookKey,
+ },
+ retrievalSource: {
+ label: "Retrieval Source",
+ type: "string",
+ path: "retrieval.source",
+ prefix: SpanAttributesGenAIPrefix,
+ icon: SquareCode,
},
};
diff --git a/src/client/src/helpers/platform.ts b/src/client/src/helpers/platform.ts
index efd930e5..87d6df0a 100644
--- a/src/client/src/helpers/platform.ts
+++ b/src/client/src/helpers/platform.ts
@@ -1,7 +1,7 @@
import { SPAN_KIND } from "@/constants/traces";
import { ValueOf } from "../utils/types";
import { MetricParams } from "@/lib/platform/common";
-import { addDays, addMonths } from "date-fns";
+import { addDays, addMonths, differenceInDays } from "date-fns";
export const validateMetricsRequestType = {
// Request
@@ -188,6 +188,17 @@ export const getFilterPreviousParams = (filter: MetricParams) => {
).toISOString();
previousParams.timeLimit.end = addMonths(end as Date, -3).toISOString();
break;
+ case "CUSTOM":
+ const differenceDays = differenceInDays(end as Date, start as Date);
+ previousParams.timeLimit.start = addDays(
+ start as Date,
+ -differenceDays
+ ).toISOString();
+ previousParams.timeLimit.end = addDays(
+ end as Date,
+ -differenceDays
+ ).toISOString();
+ break;
default:
}
diff --git a/src/client/src/helpers/trace.ts b/src/client/src/helpers/trace.ts
index bb10e041..94173613 100644
--- a/src/client/src/helpers/trace.ts
+++ b/src/client/src/helpers/trace.ts
@@ -4,12 +4,13 @@ import {
TraceRow,
TransformedTraceRow,
} from "@/constants/traces";
+import { round } from "lodash";
-export const integerParser = (value: string, multiplier?: number) =>
- parseInt((value || "0") as string, 10) * (multiplier || 1);
+export const integerParser = (value: string, offset?: number) =>
+ parseInt((value || "0") as string, 10) * (offset || 1);
-export const floatParser = (value: string, multiplier?: number) =>
- parseFloat((value || "0") as string) * (multiplier || 1);
+export const floatParser = (value: string, offset?: number) =>
+ parseFloat((value || "0") as string) * (offset || 1);
export const normalizeTrace = (item: TraceRow): TransformedTraceRow => {
return Object.keys(TraceMapping).reduce(
@@ -21,19 +22,26 @@ export const normalizeTrace = (item: TraceRow): TransformedTraceRow => {
value = item.SpanAttributes[getTraceMappingKeyFullPath(traceKey)];
}
- if (TraceMapping[traceKey].type === "integer") {
- acc[traceKey] = integerParser(
- value as string,
- TraceMapping[traceKey].multiplier
- );
- } else if (TraceMapping[traceKey].type === "float") {
- acc[traceKey] = floatParser(
- (value || "0") as string,
- TraceMapping[traceKey].multiplier
- );
+ if (value) {
+ if (TraceMapping[traceKey].type === "integer") {
+ acc[traceKey] = integerParser(
+ value as string,
+ TraceMapping[traceKey].offset
+ );
+ } else if (TraceMapping[traceKey].type === "float") {
+ acc[traceKey] = floatParser(
+ (value || "0") as string,
+ TraceMapping[traceKey].offset
+ );
+ } else if (TraceMapping[traceKey].type === "round") {
+ acc[traceKey] = round(value as number, TraceMapping[traceKey].offset);
+ } else {
+ acc[traceKey] = value;
+ }
} else {
- acc[traceKey] = value;
+ acc[traceKey] = TraceMapping[traceKey].defaultValue;
}
+
return acc;
},
{}
@@ -44,3 +52,61 @@ export const getTraceMappingKeyFullPath = (key: TraceMappingKeyType) => {
if (!TraceMapping[key].prefix) return TraceMapping[key].path;
return [TraceMapping[key].prefix, TraceMapping[key].path].join(".");
};
+
+export const getRequestTableDisplayKeys = (
+ type: string
+): TraceMappingKeyType[] => {
+ switch (type) {
+ case "vectordb":
+ return [
+ "applicationName",
+ "system",
+ "operation",
+ "documentsCount",
+ "idsCount",
+ "vectorCount",
+ ];
+ case "framework":
+ return ["applicationName", "provider", "endpoint", "owner", "repo", ""];
+ default:
+ return [
+ "applicationName",
+ "provider",
+ "model",
+ "cost",
+ "promptTokens",
+ "totalTokens",
+ ];
+ }
+};
+
+export const getRequestDetailsDisplayKeys = (
+ type: string
+): TraceMappingKeyType[] => {
+ let keys: TraceMappingKeyType[] = getRequestTableDisplayKeys(type);
+ switch (type) {
+ case "vectordb":
+ keys = keys.concat(["environment", "type", "nResults", "endpoint"]);
+ break;
+ case "framework":
+ keys = keys.concat(["environment", "type"]);
+ break;
+ default:
+ keys = keys.concat([
+ "environment",
+ "type",
+ "audioVoice",
+ "audioFormat",
+ "audioSpeed",
+ "imageSize",
+ "imageQuality",
+ "imageStyle",
+ "endpoint",
+ ]);
+ break;
+ }
+
+ return keys.filter(
+ (i) => !["applicationName", "provider", "system"].includes(i)
+ );
+};
diff --git a/src/client/src/store/filter.ts b/src/client/src/store/filter.ts
index 3773600d..dedd5ca9 100644
--- a/src/client/src/store/filter.ts
+++ b/src/client/src/store/filter.ts
@@ -2,11 +2,15 @@ import { set } from "lodash";
import { addDays, addMonths, addWeeks } from "date-fns";
import { lens } from "@dhmk/zustand-lens";
-export const TIME_RANGE_TYPE: Record<"24H" | "7D" | "1M" | "3M", string> = {
+export const TIME_RANGE_TYPE: Record<
+ "24H" | "7D" | "1M" | "3M" | "CUSTOM",
+ string
+> = {
"24H": "24H",
"7D": "7D",
"1M": "1M",
"3M": "3M",
+ CUSTOM: "CUSTOM",
};
export const DEFAULT_TIME_RANGE = "24H";
@@ -21,7 +25,11 @@ export interface FilterType {
offset: number;
}
-function getTimeLimitObject(value: string, keyPrefix: string) {
+function getTimeLimitObject(
+ value: string,
+ keyPrefix: string,
+ extraParams?: any
+) {
let object = {};
if (value === TIME_RANGE_TYPE["24H"]) {
const currentDate = new Date();
@@ -39,6 +47,13 @@ function getTimeLimitObject(value: string, keyPrefix: string) {
const currentDate = new Date();
set(object, `${keyPrefix}start`, addMonths(currentDate, -3));
set(object, `${keyPrefix}end`, currentDate);
+ } else if (value === TIME_RANGE_TYPE["CUSTOM"]) {
+ const start = extraParams?.start;
+ const end = extraParams?.end;
+ if (start && end) {
+ set(object, `${keyPrefix}start`, start);
+ set(object, `${keyPrefix}end`, end);
+ }
}
return object;
}
@@ -54,16 +69,16 @@ const INITIAL_FILTER: FilterType = {
export type FilterStore = {
details: FilterType;
- updateFilter: (key: string, value: any) => void;
+ updateFilter: (key: string, value: any, extraParams?: any) => void;
};
export const filterStoreSlice: FilterStore = lens((setStore, getStore) => ({
details: INITIAL_FILTER,
- updateFilter: (key: string, value: any) => {
+ updateFilter: (key: string, value: any, extraParams?: any) => {
let object = {};
switch (key) {
case "timeLimit.type":
- object = getTimeLimitObject(value, "timeLimit.");
+ object = getTimeLimitObject(value, "timeLimit.", extraParams);
break;
case "limit":
set(object, "offset", 0);