Skip to content

Commit

Permalink
Evaluation dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed Sep 10, 2024
1 parent 9cd6a0b commit d4bfb94
Show file tree
Hide file tree
Showing 32 changed files with 1,070 additions and 191 deletions.
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()
})
26 changes: 3 additions & 23 deletions apps/web/src/actions/evaluations/connect.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { randomUUID } from 'crypto'

import {
Commit,
DocumentVersion,
Project,
ProviderApiKey,
Expand Down Expand Up @@ -30,7 +27,6 @@ describe('connectEvaluationsAction', () => {
const [_, error] = await connectEvaluationsAction({
projectId: 1,
documentUuid: 'fake-document-uuid',
commitUuid: 'fake-commit-uuid',
templateIds: [1],
evaluationUuids: ['fake-evaluation-uuid'],
})
Expand All @@ -43,7 +39,6 @@ describe('connectEvaluationsAction', () => {
let workspace: Workspace,
user: User,
document: DocumentVersion,
commit: Commit,
provider: ProviderApiKey,
project: Project

Expand All @@ -54,7 +49,6 @@ describe('connectEvaluationsAction', () => {
workspace = setup.workspace
user = setup.user
document = setup.documents[0]!
commit = setup.commit
project = setup.project

provider = await factories.createProviderApiKey({
Expand All @@ -71,9 +65,10 @@ describe('connectEvaluationsAction', () => {
})

it('connects evaluations and templates to a document', async () => {
const evaluation = await factories.createEvaluation({
provider,
const evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
name: 'Test Evaluation',
prompt: factories.helpers.createPrompt({ provider }),
})

const template = await factories.createEvaluationTemplate({
Expand All @@ -85,7 +80,6 @@ describe('connectEvaluationsAction', () => {
const [result, error] = await connectEvaluationsAction({
projectId: project.id,
documentUuid: document.documentUuid,
commitUuid: commit.uuid,
templateIds: [template.id],
evaluationUuids: [evaluation.uuid],
})
Expand All @@ -110,7 +104,6 @@ describe('connectEvaluationsAction', () => {
const [result, error] = await connectEvaluationsAction({
projectId: project.id,
documentUuid: document.documentUuid,
commitUuid: commit.uuid,
templateIds: [],
evaluationUuids: [],
})
Expand All @@ -123,19 +116,6 @@ describe('connectEvaluationsAction', () => {
const [_, error] = await connectEvaluationsAction({
projectId: project.id,
documentUuid: 'non-existent-uuid',
commitUuid: randomUUID(),
templateIds: [],
evaluationUuids: [],
})

expect(error!.name).toEqual('NotFoundError')
})

it('fails when the commit does not exist', async () => {
const [_, error] = await connectEvaluationsAction({
projectId: project.id,
documentUuid: document.documentUuid,
commitUuid: randomUUID(),
templateIds: [],
evaluationUuids: [],
})
Expand Down
30 changes: 4 additions & 26 deletions apps/web/src/actions/evaluations/connect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use server'

import { filterEvaluationTemplatesById } from '@latitude-data/core/data-access'
import {
DocumentVersionsRepository,
EvaluationsRepository,
} from '@latitude-data/core/repositories'
import { connectEvaluations } from '@latitude-data/core/services/evaluations/connect'
import { z } from 'zod'

Expand All @@ -15,33 +10,16 @@ export const connectEvaluationsAction = withProject
.input(
z.object({
documentUuid: z.string(),
commitUuid: z.string(),
templateIds: z.array(z.number()),
evaluationUuids: z.array(z.string()),
}),
)
.handler(async ({ ctx, input }) => {
const selectedTemplates = await filterEvaluationTemplatesById(
input.templateIds,
).then((r) => r.unwrap())
const scope = new EvaluationsRepository(ctx.workspace.id)
const selectedEvaluations = await scope
.filterByUuids(input.evaluationUuids)
.then((r) => r.unwrap())

const documentsScope = new DocumentVersionsRepository(ctx.workspace.id)
const document = await documentsScope
.getDocumentAtCommit({
projectId: ctx.project.id,
commitUuid: input.commitUuid,
documentUuid: input.documentUuid,
})
.then((r) => r.unwrap())

const connectedEvaluations = await connectEvaluations({
document,
templates: selectedTemplates,
evaluations: selectedEvaluations,
workspace: ctx.workspace,
documentUuid: input.documentUuid,
evaluationUuids: input.evaluationUuids,
templateIds: input.templateIds,
}).then((r) => r.unwrap())

return connectedEvaluations
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/actions/evaluations/destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe('destroyEvaluationAction', () => {
name: 'Test Provider',
user: userData,
})
const evaluation = await factories.createEvaluation({ provider })
const evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
prompt: factories.helpers.createPrompt({ provider }),
})
evaluationId = evaluation.id
})

Expand Down Expand Up @@ -63,7 +66,10 @@ describe('destroyEvaluationAction', () => {
name: 'Test Provider',
user,
})
evaluation = await factories.createEvaluation({ provider })
evaluation = await factories.createLlmAsJudgeEvaluation({
workspace,
prompt: factories.helpers.createPrompt({ provider }),
})

mocks.getSession.mockReturnValue({
user: userData,
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/app/(private)/_data-access/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { findAllEvaluationTemplates } from '@latitude-data/core/data-access'
import { NotFoundError } from '@latitude-data/core/lib/errors'
import {
CommitsRepository,
ConnectedEvaluationsRepository,
DocumentLogsRepository,
DocumentVersionsRepository,
EvaluationsRepository,
Expand Down Expand Up @@ -186,3 +187,17 @@ export const getEvaluationsByDocumentUuidCached = cache(
return result.unwrap()
},
)

export const getConnectedDocumentsWithMetadataCached = cache(
async (evaluationId: number) => {
const { workspace } = await getCurrentUser()
const connectedEvaluationsScope = new ConnectedEvaluationsRepository(
workspace.id,
)
const result =
await connectedEvaluationsScope.getConnectedDocumentsWithMetadata(
evaluationId,
)
return result.unwrap()
},
)
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
'use client'

import { Evaluation } from '@latitude-data/core/browser'
import { TabSelector } from '@latitude-data/web-ui'
import { useNavigate } from '$/hooks/useNavigate'
import { EvaluationRoutes, ROUTES } from '$/services/routes'
import { useSelectedLayoutSegment } from 'next/navigation'

export function EvaluationTabSelector({
evaluationUuid,
evaluation,
}: {
evaluationUuid: string
evaluation: Evaluation
}) {
const router = useNavigate()
const selectedSegment = useSelectedLayoutSegment() as EvaluationRoutes | null

const pathTo = (evaluationRoute: EvaluationRoutes) => {
const evaluationDetail = ROUTES.evaluations.detail({ uuid: evaluationUuid })
const evaluationDetail = ROUTES.evaluations.detail({
uuid: evaluation.uuid,
})
const detail = evaluationDetail[evaluationRoute] ?? evaluationDetail
return detail.root
}
Expand All @@ -23,7 +26,7 @@ export function EvaluationTabSelector({
<div className='flex flex-row p-4 pb-0'>
<TabSelector
options={[
{ label: 'History', value: EvaluationRoutes.dashboard },
{ label: 'Dashboard', value: EvaluationRoutes.dashboard },
{ label: 'Editor', value: EvaluationRoutes.editor },
]}
selected={selectedSegment ?? EvaluationRoutes.dashboard}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
'use client'

import { useMemo } from 'react'

import { Evaluation } from '@latitude-data/core/browser'
import { Text } from '@latitude-data/web-ui'
import useEvaluations from '$/stores/evaluations'

export function EvaluationTitle({
evaluationUuid,
}: {
evaluationUuid: string
}) {
const { data: evaluations } = useEvaluations()
const evaluation = useMemo(() => {
return evaluations?.find((evaluation) => evaluation.uuid === evaluationUuid)
}, [evaluations, evaluationUuid])

if (!evaluation) return null

export function EvaluationTitle({ evaluation }: { evaluation: Evaluation }) {
return (
<div className='flex flex-row items-center justify-between p-4 pb-0'>
<Text.H4B>{evaluation.name}</Text.H4B>
Expand Down
Loading

0 comments on commit d4bfb94

Please sign in to comment.