From b2f09086c0c1ea85a0e48300046e7a15874202f4 Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Tue, 17 Sep 2024 17:11:51 +0200 Subject: [PATCH] Fix batch range line selector and also create batch logs on draft commits --- apps/web/src/actions/evaluations/runBatch.ts | 2 ++ apps/web/src/actions/procedures/index.ts | 2 +- .../DocumentEditor/Editor/index.tsx | 6 ++--- .../MetricsSummary/BigNumberPanels/index.tsx | 2 +- .../DatasetForm/index.tsx | 19 +++++++++++----- .../CreateBatchEvaluationModal/index.tsx | 1 + .../useRunBatchForm.ts | 2 +- .../evaluations/[evaluationId]/layout.tsx | 6 +++++ apps/web/src/app/layout.tsx | 4 ++-- .../web/src/components/EditorHeader/index.tsx | 9 ++++++-- .../layouts/AppLayout/Header/index.tsx | 5 +++-- packages/core/src/lib/readCsv.ts | 12 ++++++---- .../core/src/services/datasets/preview.ts | 2 +- packages/env/src/index.ts | 2 +- .../runBatchEvaluationJob.test.ts | 22 ++++++++++++++----- .../batchEvaluations/runBatchEvaluationJob.ts | 8 +++++-- 16 files changed, 73 insertions(+), 31 deletions(-) diff --git a/apps/web/src/actions/evaluations/runBatch.ts b/apps/web/src/actions/evaluations/runBatch.ts index e9cca6130..97f3200b0 100644 --- a/apps/web/src/actions/evaluations/runBatch.ts +++ b/apps/web/src/actions/evaluations/runBatch.ts @@ -102,6 +102,8 @@ export const runBatchEvaluationAction = withDataset evaluation, dataset: ctx.dataset, document: ctx.document, + projectId: ctx.project.id, + commitUuid: ctx.currentCommitUuid, fromLine: input.fromLine, toLine: input.toLine, parametersMap: input.parameters, diff --git a/apps/web/src/actions/procedures/index.ts b/apps/web/src/actions/procedures/index.ts index 4870e2250..f99b5ea2c 100644 --- a/apps/web/src/actions/procedures/index.ts +++ b/apps/web/src/actions/procedures/index.ts @@ -54,5 +54,5 @@ export const widthDocument = createServerActionProcedure(withProject) }) .then((r) => r.unwrap()) - return { ...ctx, document } + return { ...ctx, document, currentCommitUuid: input.commitUuid } }) diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/index.tsx index b656633de..15c6df11c 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/index.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/index.tsx @@ -120,6 +120,7 @@ export default function DocumentEditor({ }).then(setMetadata) }, [readDocument]) + const isMerged = commit.mergedAt !== null return (
diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/index.tsx index e318de7bd..400562f11 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/index.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/[evaluationId]/_components/MetricsSummary/BigNumberPanels/index.tsx @@ -165,7 +165,7 @@ export function BigNumberPanels({
- + max: number | undefined }) { - const [to, setTo] = useState(toDefaultValue) return ( setTo(Number(e.target.value))} - min={0} + onChange={(e) => { + onChangeToLine(Number(e.target.value)) + }} + min={fromDefaultValue} max={max} /> @@ -56,6 +60,7 @@ export default function DatasetForm({ wantAllLines, fromLine, toLine, + onChangeToLine, datasets, isLoadingDatasets, parametersList, @@ -68,6 +73,7 @@ export default function DatasetForm({ wantAllLines: boolean fromLine: number | undefined toLine: number | undefined + onChangeToLine: ReactStateDispatch headers: SelectOption[] selectedDataset: Dataset | null datasets: Dataset[] @@ -122,6 +128,7 @@ export default function DatasetForm({ disabled={wantAllLines} fromDefaultValue={fromLine} toDefaultValue={toLine} + onChangeToLine={onChangeToLine} max={selectedDataset?.fileMetadata?.rowCount} /> r.unwrap()) + const commit = await findCommitCached({ + projectId: Number(params.projectId), + uuid: params.commitUuid, + }) const evaluationResults = await computeEvaluationResultsWithMetadata({ workspaceId: evaluation.workspaceId, evaluation, documentUuid: params.documentUuid, + draft: commit, }).then((r) => r.unwrap()) return ( diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx index 0a144edd5..51a7c0ca5 100644 --- a/apps/web/src/app/layout.tsx +++ b/apps/web/src/app/layout.tsx @@ -30,8 +30,8 @@ export default function RootLayout({ {children} diff --git a/apps/web/src/components/EditorHeader/index.tsx b/apps/web/src/components/EditorHeader/index.tsx index 66b96d471..98b87e140 100644 --- a/apps/web/src/components/EditorHeader/index.tsx +++ b/apps/web/src/components/EditorHeader/index.tsx @@ -53,12 +53,14 @@ export default function EditorHeader({ metadata, onChangePrompt, rightActions, + disabledMetadataSelectors = false, }: { title: string metadata: ConversationMetadata | undefined prompt: string onChangePrompt: (prompt: string) => void rightActions?: ReactNode + disabledMetadataSelectors?: boolean }) { const promptMetadata = useMemo(() => { const config = metadata?.config @@ -204,13 +206,16 @@ export default function EditorHeader({ - + {/* Not good enough for Cesar */}
{sectionLinks.length > 0 ? ( diff --git a/packages/core/src/lib/readCsv.ts b/packages/core/src/lib/readCsv.ts index 7582b38cf..bcafbd424 100644 --- a/packages/core/src/lib/readCsv.ts +++ b/packages/core/src/lib/readCsv.ts @@ -1,3 +1,5 @@ +import { isNumber } from 'lodash-es' + import { CsvError, parse, type Options as CsvOptions } from 'csv-parse/sync' import { Result } from './Result' @@ -40,12 +42,14 @@ export async function syncReadCsv( info: true, } - if (toLine) { - opts = { ...opts, toLine } + if (isNumber(fromLine)) { + // from: https://csv.js.org/parse/options/from/ + opts = { ...opts, from: fromLine } } - if (fromLine) { - opts = { ...opts, fromLine } + if (toLine) { + // to: https://csv.js.org/parse/options/to/ + opts = { ...opts, to: toLine } } const records = parse(data, opts) as ParseResult[] diff --git a/packages/core/src/services/datasets/preview.ts b/packages/core/src/services/datasets/preview.ts index 84e25fa22..8fe355396 100644 --- a/packages/core/src/services/datasets/preview.ts +++ b/packages/core/src/services/datasets/preview.ts @@ -10,7 +10,7 @@ export async function previewDataset({ dataset, disk = diskFactory(), prependIndex, - fromLine = 0, + fromLine = 1, toLine = 100, }: { dataset: Dataset diff --git a/packages/env/src/index.ts b/packages/env/src/index.ts index a3fb58131..0b81e749c 100644 --- a/packages/env/src/index.ts +++ b/packages/env/src/index.ts @@ -37,7 +37,7 @@ if (environment !== 'production') { WEBSOCKET_REFRESH_SECRET_TOKEN_KEY: 'refresh-refresh-token-key', WORKERS_WEBSOCKET_SECRET_TOKEN: 'workers-secret-token', DRIVE_DISK: 'local', - DEFAULT_PROVIDER_ID: '1', + DEFAULT_PROVIDER_ID: '-1', // Crazy number to avoid conflicts DEFAULT_PROVIDER_MODEL: 'gpt-4o', FILE_PUBLIC_PATH, FILES_STORAGE_PATH, diff --git a/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.test.ts b/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.test.ts index acb49295a..6fae14859 100644 --- a/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.test.ts +++ b/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.test.ts @@ -28,12 +28,13 @@ vi.mock('@latitude-data/core/data-access', () => ({ findWorkspaceFromDocument: vi.fn(), })) +const commitReo = vi.hoisted(() => ({ + getCommitByUuid: vi.fn().mockResolvedValue({ + unwrap: () => ({ id: 'commit-1' }), + }), +})) vi.mock('@latitude-data/core/repositories', () => ({ - CommitsRepository: vi.fn().mockImplementation(() => ({ - find: vi.fn().mockResolvedValue({ - unwrap: () => ({ id: 'commit-1' }), - }), - })), + CommitsRepository: vi.fn().mockImplementation(() => commitReo), })) vi.mock('@latitude-data/core/services/datasets/preview', () => ({ @@ -70,6 +71,8 @@ describe('runBatchEvaluationJob', () => { evaluation: { id: 1 }, dataset: { fileMetadata: { rowCount: 3 } }, document: { documentUuid: 'fake-document-uuid', commitId: 'commit-1' }, + commitUuid: 'commit-uuid-1', + projectId: 1, parametersMap: { param1: 0, param2: 1 }, }, attemptsMade: 0, @@ -118,6 +121,15 @@ describe('runBatchEvaluationJob', () => { }) }) + it('find commit by uuid and project Id', async () => { + await runBatchEvaluationJob(mockJob) + + expect(commitReo.getCommitByUuid).toHaveBeenCalledWith({ + projectId: 1, + uuid: 'commit-uuid-1', + }) + }) + it('should process all rows and enqueue jobs', async () => { await runBatchEvaluationJob(mockJob) diff --git a/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.ts b/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.ts index 11ddf9bfd..f4d73290a 100644 --- a/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.ts +++ b/packages/jobs/src/job-definitions/batchEvaluations/runBatchEvaluationJob.ts @@ -20,6 +20,8 @@ type RunBatchEvaluationJobParams = { evaluation: EvaluationDto dataset: Dataset document: DocumentVersion + commitUuid: string + projectId: number fromLine?: number toLine?: number parametersMap?: Record @@ -33,7 +35,9 @@ export const runBatchEvaluationJob = async ( evaluation, dataset, document, - fromLine = 0, + projectId, + commitUuid, + fromLine, toLine, parametersMap, batchId = randomUUID(), @@ -43,7 +47,7 @@ export const runBatchEvaluationJob = async ( if (!workspace) throw new NotFoundError('Workspace not found') const commit = await new CommitsRepository(workspace.id) - .find(document.commitId) + .getCommitByUuid({ projectId, uuid: commitUuid }) .then((r) => r.unwrap()) const fileMetadata = dataset.fileMetadata // TODO: use streaming instead of this service in order to avoid loading the