Skip to content

Commit

Permalink
feature: fixes evaluations filtering in documentuuid view (#163)
Browse files Browse the repository at this point in the history
Also reorders routes to make place for the evaluation detail view
  • Loading branch information
geclos authored Sep 11, 2024
1 parent 7050747 commit 50707ee
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 67 deletions.
20 changes: 5 additions & 15 deletions apps/web/src/actions/evaluations/runBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
DocumentVersion,
EvaluationDto,
Project,
ProviderApiKey,
Providers,
User,
Workspace,
} from '@latitude-data/core/browser'
Expand Down Expand Up @@ -63,8 +61,7 @@ describe('runBatchAction', () => {
document: DocumentVersion,
commit: Commit,
dataset: Dataset,
evaluation: EvaluationDto,
provider: ProviderApiKey
evaluation: EvaluationDto

beforeEach(async () => {
vi.clearAllMocks()
Expand All @@ -78,13 +75,6 @@ describe('runBatchAction', () => {
document = setup.documents[0]!
commit = setup.commit

provider = await factories.createProviderApiKey({
workspace,
type: Providers.OpenAI,
name: 'Test Provider',
user,
})

dataset = await factories
.createDataset({
name: 'Test Dataset',
Expand All @@ -93,8 +83,8 @@ describe('runBatchAction', () => {
})
.then((result) => result.dataset)

evaluation = await factories.createEvaluation({
provider,
evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
name: 'Test Evaluation',
})

Expand Down Expand Up @@ -181,8 +171,8 @@ describe('runBatchAction', () => {
})

it('enqueues multiple evaluation jobs for multiple evaluationIds', async () => {
const evaluation2 = await factories.createEvaluation({
provider,
const evaluation2 = await factories.createLlmAsJudgeEvaluation({
workspace,
name: 'Test Evaluation 2',
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default function ConnectedDocumentsTable({
.detail({ id: document.projectId })
.commits.detail({ uuid: HEAD_COMMIT })
.documents.detail({ uuid: document.documentUuid })
.evaluations.detail({ uuid: document.evaluationUuid }).root,
.evaluations.detail(document.evaluationUuid).root,
)
}
/>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { EvaluationDto } from '@latitude-data/core/browser'
import {
Icon,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
Text,
useCurrentCommit,
useCurrentDocument,
useCurrentProject,
} from '@latitude-data/web-ui'
import { useNavigate } from '$/hooks/useNavigate'
import { ROUTES } from '$/services/routes'
import Link from 'next/link'

export default function BatchEvaluationsTable({
evaluations,
}: {
evaluations: EvaluationDto[]
}) {
const navigate = useNavigate()
const { project } = useCurrentProject()
const { commit } = useCurrentCommit()
const document = useCurrentDocument()
return (
<Table className='table-auto'>
<TableHeader className='sticky top-0 z-10'>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Description</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody className='max-h-full overflow-y-auto'>
{evaluations.map((evaluation) => (
<TableRow
key={evaluation.id}
className='cursor-pointer border-b-[0.5px] h-12 max-h-12 border-border'
onClick={() =>
navigate.push(
ROUTES.projects
.detail({ id: project.id })
.commits.detail({ uuid: commit.uuid })
.documents.detail({ uuid: document.documentUuid })
.evaluations.detail(evaluation.uuid).dashboard.root,
)
}
>
<TableCell>
<Text.H4 noWrap>{evaluation.name}</Text.H4>
</TableCell>
<TableCell>
<Text.H4>{evaluation.description}</Text.H4>
</TableCell>
<TableCell onClick={(e) => e.stopPropagation()}>
<Link
href={
ROUTES.projects
.detail({ id: project.id })
.commits.detail({ uuid: commit.uuid })
.documents.detail({ uuid: document.documentUuid })
.evaluations.detail(evaluation.uuid).dashboard.destroy
}
>
<Icon name='trash' />
</Link>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client'

import { EvaluationDto } from '@latitude-data/core/browser'
import {
TableBlankSlate,
useCurrentCommit,
useCurrentDocument,
useCurrentProject,
} from '@latitude-data/web-ui'
import { ROUTES } from '$/services/routes'
import useEvaluations from '$/stores/evaluations'
import Link from 'next/link'

import BatchEvaluationsTable from './BatchEvaluationsTable'

export default function EvaluationsLayoutClient({
evaluations: fallbackData,
}: {
evaluations: EvaluationDto[]
}) {
const { project } = useCurrentProject()
const { commit } = useCurrentCommit()
const document = useCurrentDocument()
const { data: evaluations } = useEvaluations({
fallbackData,
params: { documentUuid: document.documentUuid },
})

const href = ROUTES.projects
.detail({ id: project.id })
.commits.detail({ uuid: commit.uuid })
.documents.detail({ uuid: document.documentUuid }).evaluations.dashboard
.connect.root

return (
<>
{evaluations.length > 0 && (
<BatchEvaluationsTable evaluations={evaluations} />
)}
{evaluations.length === 0 && (
<TableBlankSlate
description='There are no evaluations connected to this prompt yet. Connect one to start evaluating the prompt.'
link={
<Link href={href}>
<TableBlankSlate.Button>
Connect your first evaluation
</TableBlankSlate.Button>
</Link>
}
/>
)}
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ReactNode } from 'react'

import { TableBlankSlate, TableWithHeader } from '@latitude-data/web-ui'
import { TableWithHeader } from '@latitude-data/web-ui'
import { getEvaluationsByDocumentUuidCached } from '$/app/(private)/_data-access'
import { ROUTES } from '$/services/routes'
import Link from 'next/link'

import Layout from './_components/Layout'
import EvaluationsLayoutClient from './_components/Layout'

export default async function EvaluationsLayout({
children,
Expand All @@ -18,7 +18,7 @@ export default async function EvaluationsLayout({
const href = ROUTES.projects
.detail({ id: Number(projectId) })
.commits.detail({ uuid: commitUuid })
.documents.detail({ uuid: documentUuid }).evaluations.connect.root
.documents.detail({ uuid: documentUuid }).evaluations.dashboard.connect.root

return (
<div className='w-full p-6'>
Expand All @@ -30,23 +30,7 @@ export default async function EvaluationsLayout({
<TableWithHeader.Button>Connect evaluation</TableWithHeader.Button>
</Link>
}
table={
<>
{evaluations.length > 0 && <Layout evaluations={evaluations} />}
{evaluations.length === 0 && (
<TableBlankSlate
description='There are no evaluations connected to this prompt yet. Connect one to start evaluating the prompt.'
link={
<Link href={href}>
<TableBlankSlate.Button>
Connect your first evaluation
</TableBlankSlate.Button>
</Link>
}
/>
)}
</>
}
table={<EvaluationsLayoutClient evaluations={evaluations} />}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function EvaluationsDashboardPage() {
return null // --> layout.tsx
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export default function EvaluationsPage() {
return null // --> layout.tsx
import { ROUTES } from '$/services/routes'
import { redirect } from 'next/navigation'

export default function EvaluationsPage({
params: { projectId, documentUuid, commitUuid },
}: {
params: { projectId: string; documentUuid: string; commitUuid: string }
}) {
redirect(
ROUTES.projects
.detail({ id: Number(projectId) })
.commits.detail({ uuid: commitUuid })
.documents.detail({ uuid: documentUuid }).evaluations.dashboard.root,
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactNode } from 'react'

import { DocumentVersionProvider } from '@latitude-data/web-ui'
import { getDocumentByUuidCached } from '$/app/(private)/_data-access'
import env from '$/env'
import { ROUTES } from '$/services/routes'
Expand All @@ -26,13 +27,15 @@ export default async function DocumentPage({
})

return (
<DocumentsLayout
projectId={projectId}
commitUuid={commitUuid}
document={document}
>
<DocumentTabs params={params}>{children}</DocumentTabs>
</DocumentsLayout>
<DocumentVersionProvider document={document}>
<DocumentsLayout
projectId={projectId}
commitUuid={commitUuid}
document={document}
>
<DocumentTabs params={params}>{children}</DocumentTabs>
</DocumentsLayout>
</DocumentVersionProvider>
)
} catch (error) {
// TODO: Show a 404 page within the documents layout, while still showing
Expand Down
19 changes: 13 additions & 6 deletions apps/web/src/services/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,26 @@ export const ROUTES = {
root: rootDocuments,
detail: ({ uuid }: { uuid: string }) => {
const root = `${rootDocuments}/${uuid}`
const rootEvaluations = `${root}/evaluations`
const evaluationsRoot: string = `${root}/evaluations`
return {
root,
[DocumentRoutes.editor]: { root },
[DocumentRoutes.evaluations]: {
root: rootEvaluations,
connect: {
root: `${rootEvaluations}/connect`,
root: evaluationsRoot,
dashboard: {
root: `${evaluationsRoot}/dashboard`,
connect: {
root: `${evaluationsRoot}/dashboard/connect`,
},
},
detail: ({ uuid }: { uuid: string }) => {
const root = `${rootEvaluations}/${uuid}`
detail: (uuid: string) => {
const detailRoot = `${evaluationsRoot}/${uuid}`
return {
root,
dashboard: {
root: `${detailRoot}/dashboard`,
destroy: `${detailRoot}/dashboard/destroy`,
},
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tests/factories/evaluations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function createLlmAsJudgeEvaluation({
}: IEvaluationData) {
const evaluationResult = await createEvaluationService({
workspace,
metadata: { prompt },
metadata: { prompt: prompt ?? faker.lorem.sentence() },
type: EvaluationMetadataType.LlmAsJudge,
name: name ?? faker.company.catchPhrase(),
description: description ?? faker.lorem.sentence(),
Expand Down
33 changes: 33 additions & 0 deletions packages/web-ui/src/providers/DocumentProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use client'

import { createContext, ReactNode, useContext } from 'react'

import { DocumentVersion } from '@latitude-data/core/browser'

const DocumentContext = createContext<DocumentVersion | undefined>(undefined)

const DocumentVersionProvider = ({
children,
document,
}: {
children: ReactNode
document: DocumentVersion
}) => {
return (
<DocumentContext.Provider value={document}>
{children}
</DocumentContext.Provider>
)
}

const useCurrentDocument = () => {
const context = useContext(DocumentContext)
if (!context) {
throw new Error(
'useCurrentDocument must be used within a DocumentVersionProvider',
)
}
return context
}

export { DocumentVersionProvider, useCurrentDocument }
1 change: 1 addition & 0 deletions packages/web-ui/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './CommitProvider'
export * from './ProjectProvider'
export * from './SessionProvider'
export * from './DocumentProvider'

0 comments on commit 50707ee

Please sign in to comment.