Skip to content

Commit

Permalink
Revert "minor: DRY metadata hook (#222)"
Browse files Browse the repository at this point in the history
This reverts commit 6092aa9.
  • Loading branch information
csansoon committed Sep 19, 2024
1 parent 8d31450 commit 83e7706
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use client'

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

import { ConversationMetadata, readMetadata } from '@latitude-data/compiler'
import { promptConfigSchema } from '@latitude-data/core/browser'
import {
Button,
DocumentTextEditor,
DocumentTextEditorFallback,
} from '@latitude-data/web-ui'
import EditorHeader from '$/components/EditorHeader'
import { useMetadata } from '$/hooks/useMetadata'
import useEvaluations from '$/stores/evaluations'
import useProviderApiKeys from '$/stores/providerApiKeys'

Expand All @@ -30,16 +30,11 @@ export default function EvaluationEditor({
)
const { data: providers } = useProviderApiKeys()
const [value, setValue] = useState(defaultPrompt)
const [metadata, setMetadata] = useState<ConversationMetadata>()
const configSchema = useMemo(
() => promptConfigSchema({ providers: providers ?? [] }),
[providers],
)
const { metadata } = useMetadata({
prompt: value,
withParameters: EVALUATION_PARAMETERS,
configSchema,
})

const save = useCallback(
(val: string) => {
update({
Expand All @@ -57,6 +52,14 @@ export default function EvaluationEditor({
[setValue],
)

useEffect(() => {
readMetadata({
prompt: value,
withParameters: EVALUATION_PARAMETERS,
configSchema,
}).then(setMetadata)
}, [value, configSchema])

if (!evaluation) return null

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
'use client'

import path from 'path'
import { createContext, Suspense, useCallback, useMemo, useState } from 'react'
import {
createContext,
Suspense,
useCallback,
useEffect,
useMemo,
useState,
} from 'react'

import { Document as RefDocument } from '@latitude-data/compiler'
import {
ConversationMetadata,
readMetadata,
Document as RefDocument,
} from '@latitude-data/compiler'
import {
DocumentVersion,
promptConfigSchema,
Expand All @@ -17,7 +28,6 @@ import {
import { type AddMessagesActionFn } from '$/actions/sdk/addMessagesAction'
import type { RunDocumentActionFn } from '$/actions/sdk/runDocumentAction'
import EditorHeader from '$/components/EditorHeader'
import { useMetadata } from '$/hooks/useMetadata'
import useDocumentVersions from '$/stores/documentVersions'
import useProviderApiKeys from '$/stores/providerApiKeys'
import { useDebouncedCallback } from 'use-debounce'
Expand Down Expand Up @@ -58,6 +68,11 @@ export default function DocumentEditor({
)
const [value, setValue] = useState(document.content)
const [isSaved, setIsSaved] = useState(true)
const [metadata, setMetadata] = useState<ConversationMetadata>()
const configSchema = useMemo(
() => promptConfigSchema({ providers }),
[providers],
)

const debouncedSave = useDebouncedCallback(
(val: string) => {
Expand Down Expand Up @@ -113,17 +128,14 @@ export default function DocumentEditor({
[readDocumentContent, value],
)

const configSchema = useMemo(
() => promptConfigSchema({ providers }),
[providers],
)

const { metadata } = useMetadata({
prompt: value,
fullPath: document.path,
referenceFn: readDocument,
configSchema,
})
useEffect(() => {
readMetadata({
prompt: value,
fullPath: document.path,
referenceFn: readDocument,
configSchema,
}).then(setMetadata)
}, [readDocument, configSchema])

const isMerged = commit.mergedAt !== null
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client'

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

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 { useMetadata } from '$/hooks/useMetadata'
import { useNavigate } from '$/hooks/useNavigate'
import { ROUTES } from '$/services/routes'

Expand Down Expand Up @@ -42,11 +42,13 @@ export default function CreateBatchEvaluationModal({
goToDetail()
},
})

const { metadata } = useMetadata({
prompt: document.content ?? '',
fullPath: document.path,
})
const [metadata, setMetadata] = useState<ConversationMetadata>()
useEffect(() => {
readMetadata({
prompt: document.content ?? '',
fullPath: document.path,
}).then(setMetadata)
}, [document])

const form = useRunBatchForm({ documentMetadata: metadata })
const onRunBatch = useCallback(() => {
Expand Down
18 changes: 0 additions & 18 deletions apps/web/src/hooks/useMetadata.ts

This file was deleted.

0 comments on commit 83e7706

Please sign in to comment.