-
Notifications
You must be signed in to change notification settings - Fork 60
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
1 parent
0727f21
commit 20bf409
Showing
19 changed files
with
457 additions
and
270 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,126 @@ | ||
import { | ||
DocumentVersion, | ||
Project, | ||
ProviderApiKey, | ||
Providers, | ||
User, | ||
Workspace, | ||
} from '@latitude-data/core/browser' | ||
import * as factories from '@latitude-data/core/factories' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { connectEvaluationsAction } from './connect' | ||
|
||
const mocks = vi.hoisted(() => { | ||
return { | ||
getSession: vi.fn(), | ||
} | ||
}) | ||
|
||
vi.mock('$/services/auth/getSession', () => ({ | ||
getSession: mocks.getSession, | ||
})) | ||
|
||
describe('connectEvaluationsAction', () => { | ||
describe('unauthorized', () => { | ||
it('errors when the user is not authenticated', async () => { | ||
const [_, error] = await connectEvaluationsAction({ | ||
projectId: 1, | ||
documentUuid: 'fake-document-uuid', | ||
templateIds: [1], | ||
evaluationUuids: ['fake-evaluation-uuid'], | ||
}) | ||
|
||
expect(error!.name).toEqual('UnauthorizedError') | ||
}) | ||
}) | ||
|
||
describe('authorized', () => { | ||
let workspace: Workspace, | ||
user: User, | ||
document: DocumentVersion, | ||
provider: ProviderApiKey, | ||
project: Project | ||
|
||
beforeEach(async () => { | ||
const setup = await factories.createProject({ | ||
documents: { 'test-doc': 'Test content' }, | ||
}) | ||
workspace = setup.workspace | ||
user = setup.user | ||
document = setup.documents[0]! | ||
project = setup.project | ||
|
||
provider = await factories.createProviderApiKey({ | ||
workspace, | ||
type: Providers.OpenAI, | ||
name: 'Test Provider', | ||
user, | ||
}) | ||
|
||
mocks.getSession.mockReturnValue({ | ||
user, | ||
workspace: { id: workspace.id, name: workspace.name }, | ||
}) | ||
}) | ||
|
||
it('connects evaluations and templates to a document', async () => { | ||
const evaluation = await factories.createLlmAsJudgeEvaluation({ | ||
workspace, | ||
name: 'Test Evaluation', | ||
prompt: factories.helpers.createPrompt({ provider }), | ||
}) | ||
|
||
const template = await factories.createEvaluationTemplate({ | ||
name: 'Test Template', | ||
description: 'Test description', | ||
prompt: 'Test prompt', | ||
}) | ||
|
||
const [result, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: document.documentUuid, | ||
templateIds: [template.id], | ||
evaluationUuids: [evaluation.uuid], | ||
}) | ||
|
||
expect(error).toBeNull() | ||
expect(result).toHaveLength(2) | ||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
documentUuid: document.documentUuid, | ||
evaluationId: evaluation.id, | ||
}), | ||
expect.objectContaining({ | ||
documentUuid: document.documentUuid, | ||
evaluationId: expect.any(Number), | ||
}), | ||
]), | ||
) | ||
}) | ||
|
||
it('returns an empty array when no evaluations or templates are provided', async () => { | ||
const [result, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: document.documentUuid, | ||
templateIds: [], | ||
evaluationUuids: [], | ||
}) | ||
|
||
expect(error).toBeNull() | ||
expect(result).toHaveLength(0) | ||
}) | ||
|
||
it('fails when the document does not exist', async () => { | ||
const [_, error] = await connectEvaluationsAction({ | ||
projectId: project.id, | ||
documentUuid: 'non-existent-uuid', | ||
templateIds: [], | ||
evaluationUuids: [], | ||
}) | ||
|
||
expect(error!.name).toEqual('NotFoundError') | ||
}) | ||
}) | ||
}) |
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,26 @@ | ||
'use server' | ||
|
||
import { connectEvaluations } from '@latitude-data/core/services/evaluations/connect' | ||
import { z } from 'zod' | ||
|
||
import { withProject } from '../procedures' | ||
|
||
export const connectEvaluationsAction = withProject | ||
.createServerAction() | ||
.input( | ||
z.object({ | ||
documentUuid: z.string(), | ||
templateIds: z.array(z.number()), | ||
evaluationUuids: z.array(z.string()), | ||
}), | ||
) | ||
.handler(async ({ ctx, input }) => { | ||
const connectedEvaluations = await connectEvaluations({ | ||
workspace: ctx.workspace, | ||
documentUuid: input.documentUuid, | ||
evaluationUuids: input.evaluationUuids, | ||
templateIds: input.templateIds, | ||
}).then((r) => r.unwrap()) | ||
|
||
return connectedEvaluations | ||
}) |
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
File renamed without changes.
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
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
...ns/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/create-batch/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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { readMetadata } from '@latitude-data/compiler' | ||
import { | ||
getDocumentByUuidCached, | ||
getEvaluationByUuidCached, | ||
} from '$/app/(private)/_data-access' | ||
|
||
import CreateBatchEvaluationModal from './_components/CreateBatchEvaluationModal' | ||
|
||
export default async function ConnectionEvaluationModal({ | ||
params, | ||
}: { | ||
params: { | ||
projectId: string | ||
commitUuid: string | ||
documentUuid: string | ||
evaluationUuid: string | ||
} | ||
}) { | ||
const evaluation = await getEvaluationByUuidCached(params.evaluationUuid) | ||
const projectId = Number(params.projectId) | ||
const documentUuid = params.documentUuid | ||
const commitUuid = params.commitUuid | ||
const document = await getDocumentByUuidCached({ | ||
projectId, | ||
commitUuid, | ||
documentUuid, | ||
}) | ||
const metadata = await readMetadata({ | ||
prompt: document.content ?? '', | ||
fullPath: document.path, | ||
}) | ||
return ( | ||
<CreateBatchEvaluationModal | ||
evaluation={evaluation} | ||
document={document} | ||
documentMetadata={metadata} | ||
projectId={params.projectId} | ||
commitUuid={commitUuid} | ||
/> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
...ectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EvaluationsRepository } from '@latitude-data/core/repositories' | ||
import { getCurrentUser } from '$/services/auth/getCurrentUser' | ||
|
||
export default async function EvaluationPage({ | ||
params: { evaluationId }, | ||
}: { | ||
params: { evaluationId: string } | ||
}) { | ||
const { workspace } = await getCurrentUser() | ||
const evaluationScope = new EvaluationsRepository(workspace.id) | ||
const evaluation = await evaluationScope | ||
.find(evaluationId) | ||
.then((r) => r.unwrap()) | ||
return ( | ||
<div> | ||
<h1>{evaluation.name}</h1> | ||
<p>{evaluation.description || 'No description for this evaluation'}</p> | ||
</div> | ||
) | ||
} |
15 changes: 0 additions & 15 deletions
15
...tId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationUuid]/page.tsx
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
Oops, something went wrong.