From d49f62fb5641ea123fcbba8d9eb41bcfeef74f1e Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 20 Nov 2024 11:50:14 -0800 Subject: [PATCH] Nick: extract fixes --- apps/api/src/__tests__/e2e_extract/index.test.ts | 3 ++- apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/api/src/__tests__/e2e_extract/index.test.ts b/apps/api/src/__tests__/e2e_extract/index.test.ts index 31f14f4a..346958da 100644 --- a/apps/api/src/__tests__/e2e_extract/index.test.ts +++ b/apps/api/src/__tests__/e2e_extract/index.test.ts @@ -86,7 +86,8 @@ describe("E2E Tests for Extract API Routes", () => { type: "array", items: { type: "string" - } + }, + required: ["items"] }, }); expect(response.statusCode).toBe(200); diff --git a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts index 7c2a6696..41d76779 100644 --- a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts +++ b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts @@ -165,7 +165,9 @@ export async function generateOpenAICompletions(logger: Logger, options: Extract } } - if (options.schema && options.schema.type === "array") { + // If the users actually wants the items object, they can specify it as 'required' in the schema + // otherwise, we just return the items array + if (options.schema && options.schema.type === "array" && !schema?.required?.includes("items")) { extract = extract?.items; } return { extract, warning };