Repository navigation
feat(admin): show experiment request log #3387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
apps/web/src/app/admin/model-experiments/ModelExperimentRequestsContent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| 'use client'; | ||
|
|
||
| import { Badge } from '@/components/ui/badge'; | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from '@/components/ui/table'; | ||
| import { useModelExperimentRequests } from '@/app/admin/api/model-experiments/hooks'; | ||
|
|
||
| function formatDate(value: string): string { | ||
| return new Date(value).toLocaleString(); | ||
| } | ||
|
|
||
| function formatNullable(value: string | null): string { | ||
| return value && value.length > 0 ? value : '—'; | ||
| } | ||
|
|
||
| function formatTokens(value: number): string { | ||
| return value.toLocaleString(); | ||
| } | ||
|
|
||
| function formatMicrodollars(value: number | null): string { | ||
| if (value === null) return '—'; | ||
| return value.toLocaleString(); | ||
| } | ||
|
|
||
| function HashCell({ value }: { value: string }) { | ||
| const display = value.length > 18 ? `${value.slice(0, 18)}…` : value; | ||
| return ( | ||
| <span className="font-mono text-xs" title={value}> | ||
| {display} | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| export function ModelExperimentRequestsContent() { | ||
| const { data, isLoading } = useModelExperimentRequests(); | ||
| const rows = data?.items ?? []; | ||
|
|
||
| return ( | ||
| <div className="flex w-full flex-col gap-y-4"> | ||
| <div className="flex flex-col gap-1"> | ||
| <h2 className="text-2xl font-bold">Experiment Requests</h2> | ||
| <p className="text-muted-foreground text-sm"> | ||
| Last 100 requests attributed to model experiments. Prompt bodies stay in R2; this table | ||
| shows attribution, routing, and usage metadata only. | ||
| </p> | ||
| </div> | ||
|
|
||
| {isLoading ? ( | ||
| <div className="text-muted-foreground text-sm">Loading…</div> | ||
| ) : rows.length === 0 ? ( | ||
| <div className="border-border bg-card text-muted-foreground rounded-lg border p-6 text-sm"> | ||
| No experiment requests recorded yet. | ||
| </div> | ||
| ) : ( | ||
| <div className="border-border overflow-x-auto rounded-lg border"> | ||
| <Table> | ||
| <TableHeader> | ||
| <TableRow> | ||
| <TableHead>Created</TableHead> | ||
| <TableHead>Experiment</TableHead> | ||
| <TableHead>Variant</TableHead> | ||
| <TableHead>Request</TableHead> | ||
| <TableHead>Usage</TableHead> | ||
| <TableHead>Prompt hash</TableHead> | ||
| <TableHead>User / org</TableHead> | ||
| </TableRow> | ||
| </TableHeader> | ||
| <TableBody> | ||
| {rows.map(row => ( | ||
| <TableRow key={row.usageId}> | ||
| <TableCell className="whitespace-nowrap align-top text-sm"> | ||
| {formatDate(row.createdAt)} | ||
| </TableCell> | ||
| <TableCell className="min-w-56 align-top"> | ||
| <div className="font-medium">{row.experimentName}</div> | ||
| <div className="text-muted-foreground font-mono text-xs"> | ||
| {row.publicModelId} | ||
| </div> | ||
| <div className="text-muted-foreground mt-1 font-mono text-xs"> | ||
| {row.experimentId} | ||
| </div> | ||
| </TableCell> | ||
| <TableCell className="min-w-48 align-top"> | ||
| <div className="font-medium">{row.variantLabel}</div> | ||
| <div className="text-muted-foreground font-mono text-xs"> | ||
| {row.variantVersionId} | ||
| </div> | ||
| </TableCell> | ||
| <TableCell className="min-w-48 align-top"> | ||
| <div className="flex flex-wrap items-center gap-1"> | ||
| <Badge variant="outline">{row.requestKind}</Badge> | ||
| <Badge variant="secondary">{row.allocationSubject}</Badge> | ||
| {row.wasTruncated && <Badge variant="destructive">truncated</Badge>} | ||
| </div> | ||
| <div className="text-muted-foreground mt-1 text-xs"> | ||
| Client: {formatNullable(row.clientRequestId)} | ||
| </div> | ||
| <div className="text-muted-foreground font-mono text-xs">{row.usageId}</div> | ||
| </TableCell> | ||
| <TableCell className="min-w-48 align-top text-sm"> | ||
| <div> | ||
| Tokens: {formatTokens(row.inputTokens)} in / {formatTokens(row.outputTokens)}{' '} | ||
| out | ||
| </div> | ||
| <div className="text-muted-foreground text-xs"> | ||
| Cache: {formatTokens(row.cacheWriteTokens)} write /{' '} | ||
| {formatTokens(row.cacheHitTokens)} hit | ||
| </div> | ||
| <div className="text-muted-foreground text-xs"> | ||
| Cost: {formatMicrodollars(row.costMicrodollars)} µ$ · discount:{' '} | ||
| {formatMicrodollars(row.cacheDiscountMicrodollars)} µ$ | ||
| </div> | ||
| {row.hasError && <Badge variant="destructive">error</Badge>} | ||
| </TableCell> | ||
| <TableCell className="min-w-44 align-top"> | ||
| <HashCell value={row.requestBodySha256} /> | ||
| </TableCell> | ||
| <TableCell className="min-w-56 align-top text-xs"> | ||
| <div className="font-mono">{row.userId}</div> | ||
| <div className="text-muted-foreground font-mono"> | ||
| {formatNullable(row.organizationId)} | ||
| </div> | ||
| <div className="text-muted-foreground mt-1"> | ||
| {formatNullable(row.provider)} / {formatNullable(row.inferenceProvider)} | ||
| </div> | ||
| <div className="text-muted-foreground font-mono"> | ||
| {formatNullable(row.requestedModel)} → {formatNullable(row.upstreamModel)} | ||
| </div> | ||
| </TableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.