Skip to content

Commit

Permalink
Fix: Run batch modal
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed Sep 18, 2024
1 parent 244cb83 commit a816cc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client'

import { useCallback } from 'react'
import { useCallback, useEffect, useState } from 'react'

import { ConversationMetadata } from '@latitude-data/compiler'
import { ConversationMetadata, readMetadata } from '@latitude-data/compiler'
import { DocumentVersion, EvaluationDto } from '@latitude-data/core/browser'
import { Button, CloseTrigger, Modal } from '@latitude-data/web-ui'
import { useNavigate } from '$/hooks/useNavigate'
Expand All @@ -15,15 +15,13 @@ import { useRunBatchForm } from './useRunBatchForm'
export default function CreateBatchEvaluationModal({
document,
evaluation,
documentMetadata,
projectId,
commitUuid,
}: {
projectId: string
commitUuid: string
document: DocumentVersion
evaluation: EvaluationDto
documentMetadata: ConversationMetadata
}) {
const navigate = useNavigate()
const documentUuid = document.documentUuid
Expand All @@ -44,7 +42,15 @@ export default function CreateBatchEvaluationModal({
goToDetail()
},
})
const form = useRunBatchForm({ documentMetadata })
const [metadata, setMetadata] = useState<ConversationMetadata>()
useEffect(() => {
readMetadata({
prompt: document.content ?? '',
fullPath: document.path,
}).then(setMetadata)
}, [document])

const form = useRunBatchForm({ documentMetadata: metadata })
const onRunBatch = useCallback(() => {
runBatch({
datasetId: form.selectedDataset?.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function buildEmptyParameters(parameters: string[]) {
export function useRunBatchForm({
documentMetadata,
}: {
documentMetadata: ConversationMetadata
documentMetadata?: ConversationMetadata
}) {
const parametersList = useMemo(
() => Array.from(documentMetadata.parameters),
[documentMetadata.parameters],
() => Array.from(documentMetadata?.parameters ?? []),
[documentMetadata?.parameters],
)
const { data: datasets, isLoading: isLoadingDatasets } = useDatasets()
const [selectedDataset, setSelectedDataset] = useState<Dataset | null>(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readMetadata } from '@latitude-data/compiler'
import { EvaluationsRepository } from '@latitude-data/core/repositories'
import { getDocumentByUuidCached } from '$/app/(private)/_data-access'
import { getCurrentUser } from '$/services/auth/getCurrentUser'
Expand Down Expand Up @@ -28,15 +27,10 @@ export default async function ConnectionEvaluationModal({
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}
/>
Expand Down

0 comments on commit a816cc3

Please sign in to comment.