diff --git a/packages/core/src/services/documents/create.test.ts b/packages/core/src/services/documents/create.test.ts index 8d137510e..42e11188e 100644 --- a/packages/core/src/services/documents/create.test.ts +++ b/packages/core/src/services/documents/create.test.ts @@ -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' @@ -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: [], }) @@ -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('') }) }) diff --git a/packages/core/src/services/documents/create.ts b/packages/core/src/services/documents/create.ts index 0f65a86f9..b153ca65e 100644 --- a/packages/core/src/services/documents/create.ts +++ b/packages/core/src/services/documents/create.ts @@ -47,13 +47,6 @@ 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({ @@ -61,12 +54,14 @@ export async function createNewDocument( path, content: content ?? - ` + (provider + ? ` --- provider: ${provider.name} model: ${findFirstModelForProvider(provider.provider)} --- - `.trim(), + `.trim() + : ''), }) .returning() diff --git a/packages/core/src/services/evaluations/create.test.ts b/packages/core/src/services/evaluations/create.test.ts index 7051d9cbe..1f5df8e26 100644 --- a/packages/core/src/services/evaluations/create.test.ts +++ b/packages/core/src/services/evaluations/create.test.ts @@ -5,7 +5,6 @@ import { EvaluationMetadataType, EvaluationResultableType, } from '../../constants' -import { BadRequestError } from '../../lib' import * as factories from '../../tests/factories' import { createEvaluation } from './create' @@ -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' } @@ -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) }) }) diff --git a/packages/core/src/services/evaluations/create.ts b/packages/core/src/services/evaluations/create.ts index 25034a218..dc83ede8a 100644 --- a/packages/core/src/services/evaluations/create.ts +++ b/packages/core/src/services/evaluations/create.ts @@ -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