Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: do not fail to create documents if no provider found #301

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/core/src/services/documents/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, expect, it } from 'vitest'

import { BadRequestError } from '../../lib'
import { DocumentVersionsRepository } from '../../repositories'
import { mergeCommit } from '../commits/merge'
import { createNewDocument } from './create'
Expand Down Expand Up @@ -95,7 +94,7 @@ model: gpt-4o-mini
)
})

it('fails when no provider is found', async (ctx) => {
it('creates the document without the frontmatter if no provider is found', async (ctx) => {
const { project, user } = await ctx.factories.createProject({
providers: [],
})
Expand All @@ -106,8 +105,7 @@ model: gpt-4o-mini
path: 'newdoc',
})

expect(result.error).toEqual(
new BadRequestError('No provider found when creating document'),
)
expect(result.ok).toBe(true)
expect(result.unwrap().content).toBe('')
})
})
13 changes: 4 additions & 9 deletions packages/core/src/services/documents/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,21 @@ export async function createNewDocument(

const providerScope = new ProviderApiKeysRepository(workspace!.id, tx)
const provider = await providerScope.findFirst().then((r) => r.unwrap())

if (!provider) {
return Result.error(
new BadRequestError('No provider found when creating document'),
)
}

const newDoc = await tx
.insert(documentVersions)
.values({
commitId: commit.id,
path,
content:
content ??
`
(provider
? `
---
provider: ${provider.name}
model: ${findFirstModelForProvider(provider.provider)}
---
`.trim(),
`.trim()
: ''),
})
.returning()

Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/services/evaluations/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
EvaluationMetadataType,
EvaluationResultableType,
} from '../../constants'
import { BadRequestError } from '../../lib'
import * as factories from '../../tests/factories'
import { createEvaluation } from './create'

Expand All @@ -21,7 +20,7 @@ describe('createEvaluation', () => {
})

describe('without existing provider', () => {
it('fails when there is no provider', async () => {
it('creates the evaluation without the frontmatter if no provider is found', async () => {
const name = 'Test Evaluation'
const description = 'Test Description'
const metadata = { prompt: 'Test prompt' }
Expand All @@ -36,9 +35,8 @@ describe('createEvaluation', () => {
metadata,
})

expect(result.error).toEqual(
new BadRequestError('No provider found when creating evaluation'),
)
expect(result.ok).toBe(true)
expect(result.unwrap().metadata.prompt).toBe(metadata.prompt)
})
})

Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/services/evaluations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ export async function createEvaluation(
const providerScope = new ProviderApiKeysRepository(workspace!.id, db)
const providerResult = await providerScope.findFirst()
const provider = providerResult.unwrap()

if (!provider) {
return Result.error(
new BadRequestError('No provider found when creating evaluation'),
)
}
const meta = metadata as { prompt: string; templateId?: number }
const promptWithProvider = `---
const promptWithProvider = provider
? `---
provider: ${provider.name}
model: ${findFirstModelForProvider(provider.provider)}
---
${meta.prompt}
`.trim()
: meta.prompt

return await Transaction.call(async (tx) => {
let metadataTable
Expand Down
Loading