Skip to content

Commit

Permalink
Fix YAML compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed Sep 18, 2024
1 parent 8d5ba29 commit 286e45f
Show file tree
Hide file tree
Showing 50 changed files with 951 additions and 609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createDocumentVersion,
createDraft,
createProject,
helpers,
} from '@latitude-data/core/factories'
import { DocumentVersionsRepository } from '@latitude-data/core/repositories'
import { apiKeys } from '@latitude-data/core/schema'
Expand All @@ -28,7 +29,7 @@ describe('GET documents', () => {

describe('authorized', () => {
it('succeeds', async () => {
const { workspace, user, project } = await createProject()
const { workspace, user, project, providers } = await createProject()
// TODO: move to core
const apikey = await database.query.apiKeys.findFirst({
where: eq(apiKeys.workspaceId, workspace.id),
Expand All @@ -38,7 +39,11 @@ describe('GET documents', () => {
project,
user,
})
const document = await createDocumentVersion({ commit, path })
const document = await createDocumentVersion({
commit,
path,
content: helpers.createPrompt({ provider: providers[0]! }),
})

await mergeCommit(commit).then((r) => r.unwrap())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
createDocumentVersion,
createDraft,
createProject,
helpers,
} from '@latitude-data/core/factories'
import { Result } from '@latitude-data/core/lib/Result'
import { apiKeys } from '@latitude-data/core/schema'
Expand Down Expand Up @@ -74,7 +75,12 @@ describe('POST /run', () => {

describe('authorized', () => {
beforeEach(async () => {
const { workspace: wsp, user, project: prj } = await createProject()
const {
workspace: wsp,
user,
project: prj,
providers,
} = await createProject()
project = prj
workspace = wsp
// TODO: move to core
Expand All @@ -90,14 +96,7 @@ describe('POST /run', () => {
const document = await createDocumentVersion({
commit: cmt,
path,
content: `
---
provider: openai
model: gpt-4o
---
Ignore all the rest and just return "Hello".
`,
content: helpers.createPrompt({ provider: providers[0]! }),
})

commit = await mergeCommit(cmt).then((r) => r.unwrap())
Expand Down
19 changes: 12 additions & 7 deletions apps/web/src/actions/commits/publishDraftCommit.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type {
Commit,
DocumentVersion,
Project,
User,
Workspace,
import {
Providers,
type Commit,
type DocumentVersion,
type Project,
type User,
type Workspace,
} from '@latitude-data/core/browser'
import * as factories from '@latitude-data/core/factories'
import { helpers } from '@latitude-data/core/factories'
import { updateDocument } from '@latitude-data/core/services/documents/update'
import { publishDraftCommitAction } from '$/actions/commits/publishDraftCommitAction'
import { beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -33,7 +35,10 @@ describe('publishDraftCommitAction', () => {
project: prj,
documents: docs,
} = await factories.createProject({
documents: { doc1: 'content' },
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
doc1: helpers.createPrompt({ provider: 'openai', content: 'content' }),
},
})
user = usr
workspace = wp
Expand Down
17 changes: 14 additions & 3 deletions apps/web/src/actions/documents/destroyDocumentAction/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import {
Commit,
DocumentVersion,
Project,
Providers,
User,
} from '@latitude-data/core/browser'
import { database } from '@latitude-data/core/client'
import { createDraft, createProject } from '@latitude-data/core/factories'
import {
createDraft,
createProject,
helpers,
} from '@latitude-data/core/factories'
import { documentVersions } from '@latitude-data/core/schema'
import { and, eq } from 'drizzle-orm'
import { beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -34,7 +39,10 @@ describe('destroyDocumentAction', async () => {
commit: cmt,
documents: allDocs,
} = await createProject({
documents: { doc1: 'Doc 1' },
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
doc1: helpers.createPrompt({ provider: 'openai', content: 'Doc 1' }),
},
})
const { commit } = await createDraft({ project: prj, user })
merged = cmt
Expand Down Expand Up @@ -67,7 +75,10 @@ describe('destroyDocumentAction', async () => {
commit: otherCommit,
documents: allDocs,
} = await createProject({
documents: { doc1: 'Doc 1' },
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
doc1: helpers.createPrompt({ provider: 'openai', content: 'Doc 1' }),
},
})
const otherWorkspaceDocument = allDocs[0]!
const [_, error] = await destroyDocumentAction({
Expand Down
19 changes: 16 additions & 3 deletions apps/web/src/actions/documents/updateContent.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { DocumentVersion, Project, User } from '@latitude-data/core/browser'
import {
DocumentVersion,
Project,
Providers,
User,
} from '@latitude-data/core/browser'
import * as factories from '@latitude-data/core/factories'
import { updateDocument } from '@latitude-data/core/services/documents/update'
import { findCommitById } from 'node_modules/@latitude-data/core/src/data-access/commits'
Expand All @@ -24,8 +29,12 @@ describe('updateDocumentAction', async () => {
const { workspace } = await factories.createWorkspace()
const { documents, project } = await factories.createProject({
workspace,
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
doc1: 'foo',
doc1: factories.helpers.createPrompt({
provider: 'openai',
content: 'foo',
}),
},
})
doc1 = documents.filter((d) => d.path === 'doc1')[0]!
Expand Down Expand Up @@ -57,8 +66,12 @@ describe('updateDocumentAction', async () => {
const { documents, project: projectData } = await factories.createProject(
{
workspace,
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
doc1: 'foo',
doc1: factories.helpers.createPrompt({
provider: 'openai',
content: 'foo',
}),
},
},
)
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/actions/evaluations/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ describe('connectEvaluationsAction', () => {

beforeEach(async () => {
const setup = await factories.createProject({
documents: { 'test-doc': 'Test content' },
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
'test-doc': factories.helpers.createPrompt({
provider: 'openai',
content: 'Test content',
}),
},
})
workspace = setup.workspace
user = setup.user
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/actions/evaluations/runBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DocumentVersion,
EvaluationDto,
Project,
Providers,
User,
Workspace,
} from '@latitude-data/core/browser'
Expand Down Expand Up @@ -67,7 +68,13 @@ describe('runBatchAction', () => {
vi.clearAllMocks()

const setup = await factories.createProject({
documents: { 'test-doc': 'Test content' },
providers: [{ type: Providers.OpenAI, name: 'openai' }],
documents: {
'test-doc': factories.helpers.createPrompt({
provider: 'openai',
content: 'Test content',
}),
},
})
workspace = setup.workspace
user = setup.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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 useEvaluations from '$/stores/evaluations'
import useProviderApiKeys from '$/stores/providerApiKeys'

import Playground from './Playground'
import { EVALUATION_PARAMETERS } from './Playground/Chat'
Expand All @@ -26,8 +28,13 @@ export default function EvaluationEditor({
() => data.find((e) => e.uuid === evaluationUuid),
[evaluationUuid, data],
)
const { data: providers } = useProviderApiKeys()
const [value, setValue] = useState(defaultPrompt)
const [metadata, setMetadata] = useState<ConversationMetadata>()
const configSchema = useMemo(
() => promptConfigSchema({ providers: providers ?? [] }),
[providers],
)
const save = useCallback(
(val: string) => {
update({
Expand All @@ -49,8 +56,9 @@ export default function EvaluationEditor({
readMetadata({
prompt: value,
withParameters: EVALUATION_PARAMETERS,
configSchema,
}).then(setMetadata)
}, [value])
}, [value, configSchema])

if (!evaluation) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Suspense,
useCallback,
useEffect,
useMemo,
useState,
} from 'react'

Expand All @@ -14,7 +15,10 @@ import {
readMetadata,
Document as RefDocument,
} from '@latitude-data/compiler'
import { DocumentVersion } from '@latitude-data/core/browser'
import {
DocumentVersion,
promptConfigSchema,
} from '@latitude-data/core/browser'
import {
DocumentTextEditor,
DocumentTextEditorFallback,
Expand All @@ -25,6 +29,7 @@ import { type AddMessagesActionFn } from '$/actions/sdk/addMessagesAction'
import type { RunDocumentActionFn } from '$/actions/sdk/runDocumentAction'
import EditorHeader from '$/components/EditorHeader'
import useDocumentVersions from '$/stores/documentVersions'
import useProviderApiKeys from '$/stores/providerApiKeys'
import { useDebouncedCallback } from 'use-debounce'

import Playground from './Playground'
Expand All @@ -50,6 +55,7 @@ export default function DocumentEditor({
}) {
const { commit } = useCurrentCommit()
const { project } = useCurrentProject()
const { data: providers } = useProviderApiKeys()

const { data: _documents, updateContent } = useDocumentVersions(
{
Expand All @@ -63,6 +69,10 @@ 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 @@ -123,8 +133,9 @@ export default function DocumentEditor({
prompt: value,
fullPath: document.path,
referenceFn: readDocument,
configSchema,
}).then(setMetadata)
}, [readDocument])
}, [readDocument, configSchema])

const isMerged = commit.mergedAt !== null
return (
Expand Down
Loading

0 comments on commit 286e45f

Please sign in to comment.