-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
478 additions
and
53 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/web/src/actions/connectedEvaluations/fetchConnectedDocuments.ts
This file contains 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,25 @@ | ||
'use server' | ||
|
||
import { ConnectedEvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { z } from 'zod' | ||
|
||
import { authProcedure } from '../procedures' | ||
|
||
export const fetchConnectedDocumentsAction = authProcedure | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
evaluationId: z.number(), | ||
}), | ||
) | ||
.handler(async ({ input, ctx }) => { | ||
const connectedEvaluationsScope = new ConnectedEvaluationsRepository( | ||
ctx.workspace.id, | ||
) | ||
const connectedDocuments = | ||
await connectedEvaluationsScope.getConnectedDocumentsWithMetadata( | ||
input.evaluationId, | ||
) | ||
|
||
return connectedDocuments.unwrap() | ||
}) |
This file contains 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 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
19 changes: 2 additions & 17 deletions
19
...(private)/evaluations/(evaluation)/[evaluationUuid]/_components/EvaluationTitle/index.tsx
This file contains 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
115 changes: 115 additions & 0 deletions
115
...ons/(evaluation)/[evaluationUuid]/dashboard/_components/ConnectedDocumentsTable/index.tsx
This file contains 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,115 @@ | ||
'use client' | ||
|
||
import { useMemo } from 'react' | ||
|
||
import { HEAD_COMMIT } from '@latitude-data/core/browser' | ||
import type { ConnectedDocumentWithMetadata } from '@latitude-data/core/repositories' | ||
import { | ||
Skeleton, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
Text, | ||
} from '@latitude-data/web-ui' | ||
import { formatCostInMillicents } from '$/app/_lib/formatCostInMillicents' | ||
import { useNavigate } from '$/hooks/useNavigate' | ||
import { ROUTES } from '$/services/routes' | ||
import useProjects from '$/stores/projects' | ||
|
||
const ConnectedDocumentTableRow = ({ | ||
document, | ||
onSelect, | ||
}: { | ||
document: ConnectedDocumentWithMetadata | ||
onSelect: () => void | ||
}) => { | ||
const { data: projects, isLoading: isProjectsLoading } = useProjects() | ||
const projectName = useMemo(() => { | ||
if (isProjectsLoading) return null | ||
|
||
return projects?.find((project) => project.id === document.projectId)?.name | ||
}, [document.projectId, isProjectsLoading, projects]) | ||
|
||
const promptPath = useMemo(() => { | ||
return document.path.split('/').slice(0, -1).join('/') | ||
}, [document.path]) | ||
|
||
const promptName = useMemo(() => { | ||
return document.path.split('/').pop() | ||
}, [document.path]) | ||
|
||
return ( | ||
<TableRow | ||
key={document.documentUuid} | ||
className='cursor-pointer border-b-[0.5px] h-12 max-h-12 border-border' | ||
onClick={onSelect} | ||
> | ||
<TableCell className='nowrap'> | ||
<Text.H4 color='foregroundMuted' noWrap> | ||
{promptPath} | ||
{Boolean(promptPath) && '/'} | ||
<Text.H4 noWrap>{promptName}</Text.H4> | ||
</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
{isProjectsLoading ? ( | ||
<Skeleton className='w-full h-4 bg-muted animate-pulse' /> | ||
) : ( | ||
<Text.H4 noWrap>{projectName}</Text.H4> | ||
)} | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4 noWrap>{document.evaluationLogs}</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4 noWrap>{document.totalTokens}</Text.H4> | ||
</TableCell> | ||
<TableCell> | ||
<Text.H4 noWrap> | ||
{formatCostInMillicents(document.costInMillicents ?? 0)} | ||
</Text.H4> | ||
</TableCell> | ||
</TableRow> | ||
) | ||
} | ||
|
||
export default function ConnectedDocumentsTable({ | ||
connectedDocumentsWithMetadata, | ||
}: { | ||
connectedDocumentsWithMetadata: ConnectedDocumentWithMetadata[] | ||
}) { | ||
const navigate = useNavigate() | ||
|
||
return ( | ||
<Table className='table-auto'> | ||
<TableHeader className='sticky top-0 z-10'> | ||
<TableRow> | ||
<TableHead>Prompt name</TableHead> | ||
<TableHead>Project</TableHead> | ||
<TableHead>Logs evaluated</TableHead> | ||
<TableHead>Tokens</TableHead> | ||
<TableHead>Cost</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody className='max-h-full overflow-y-auto'> | ||
{connectedDocumentsWithMetadata.map((document) => ( | ||
<ConnectedDocumentTableRow | ||
key={document.documentUuid} | ||
document={document} | ||
onSelect={() => | ||
navigate.push( | ||
ROUTES.projects | ||
.detail({ id: document.projectId }) | ||
.commits.detail({ uuid: HEAD_COMMIT }) | ||
.documents.detail({ uuid: document.documentUuid }).logs.root, // TODO: Navigate to the document evaluation details page | ||
) | ||
} | ||
/> | ||
))} | ||
</TableBody> | ||
</Table> | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
...vate)/evaluations/(evaluation)/[evaluationUuid]/dashboard/_components/EvaluationStats.tsx
This file contains 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,71 @@ | ||
'use client' | ||
|
||
import { useEffect, useState } from 'react' | ||
|
||
import { readMetadata } from '@latitude-data/compiler' | ||
import { EvaluationDto } from '@latitude-data/core/browser' | ||
import { ConnectedDocumentWithMetadata } from '@latitude-data/core/repositories' | ||
import { Skeleton, Text } from '@latitude-data/web-ui' | ||
import { formatCostInMillicents } from '$/app/_lib/formatCostInMillicents' | ||
import useConnectedDocuments from '$/stores/connectedEvaluations' | ||
|
||
export function Stat({ label, value }: { label: string; value?: string }) { | ||
return ( | ||
<div className='w-full min-w-[100px] max-w-[300px] h-24 flex flex-col gap-2 px-6 py-2 justify-center border border-border rounded-lg'> | ||
<Text.H4M color='foregroundMuted'>{label}</Text.H4M> | ||
{value == undefined ? ( | ||
<Skeleton className='w-[150px] h-8 bg-muted-foreground/10 animate-pulse' /> | ||
) : ( | ||
<Text.H3B>{value}</Text.H3B> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default function EvaluationStats({ | ||
evaluation, | ||
connectedDocumentsWithMetadata, | ||
}: { | ||
evaluation: EvaluationDto | ||
connectedDocumentsWithMetadata: ConnectedDocumentWithMetadata[] | ||
}) { | ||
const [model, setModel] = useState<string>() | ||
const { data: connectedDocuments, isLoading: connectedDocumentsLoading } = | ||
useConnectedDocuments({ evaluation }) | ||
|
||
useEffect(() => { | ||
readMetadata({ prompt: evaluation.metadata.prompt }).then((metadata) => { | ||
const metadataModel = (metadata.config['model'] as string) ?? 'Unknown' | ||
setModel(metadataModel) | ||
}) | ||
}, [evaluation.metadata]) | ||
|
||
return ( | ||
<div className='flex gap-6'> | ||
<Stat | ||
label='Prompts' | ||
value={ | ||
connectedDocumentsLoading | ||
? undefined | ||
: connectedDocuments?.length.toString() | ||
} | ||
/> | ||
<Stat label='Model' value={model} /> | ||
<Stat | ||
label='Logs' | ||
value={connectedDocumentsWithMetadata | ||
.reduce((acc, doc) => acc + doc.evaluationLogs, 0) | ||
.toString()} | ||
/> | ||
<Stat | ||
label='Cost' | ||
value={formatCostInMillicents( | ||
connectedDocumentsWithMetadata.reduce( | ||
(acc, doc) => acc + doc.costInMillicents, | ||
0, | ||
), | ||
)} | ||
/> | ||
</div> | ||
) | ||
} |
14 changes: 0 additions & 14 deletions
14
apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/layout.tsx
This file was deleted.
Oops, something went wrong.
31 changes: 29 additions & 2 deletions
31
apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/page.tsx
This file contains 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 |
---|---|---|
@@ -1,3 +1,30 @@ | ||
export default function DashboardPage() { | ||
return null // --> layout.tsx | ||
import { Container } from '@latitude-data/web-ui' | ||
import { | ||
getConnectedDocumentsWithMetadataCached, | ||
getEvaluationByUuidCached, | ||
} from '$/app/(private)/_data-access' | ||
|
||
import ConnectedDocumentsTable from './_components/ConnectedDocumentsTable' | ||
import EvaluationStats from './_components/EvaluationStats' | ||
|
||
export default async function DashboardPage({ | ||
params, | ||
}: { | ||
params: { evaluationUuid: string } | ||
}) { | ||
const evaluation = await getEvaluationByUuidCached(params.evaluationUuid) | ||
const connectedDocumentsWithMetadata = | ||
await getConnectedDocumentsWithMetadataCached(evaluation.id) | ||
|
||
return ( | ||
<Container> | ||
<EvaluationStats | ||
evaluation={evaluation} | ||
connectedDocumentsWithMetadata={connectedDocumentsWithMetadata} | ||
/> | ||
<ConnectedDocumentsTable | ||
connectedDocumentsWithMetadata={connectedDocumentsWithMetadata} | ||
/> | ||
</Container> | ||
) | ||
} |
This file contains 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 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 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
Oops, something went wrong.