From 2fb8a3c8dc427a8f6f208c7f23a36b054df6580f Mon Sep 17 00:00:00 2001 From: rafaelmmiller <150964962+rafaelsideguide@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:04:42 -0300 Subject: [PATCH] fix schema --- apps/api/requests.http | 16 ++++++++++++++++ .../scraper/scrapeURL/transformers/llmExtract.ts | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/apps/api/requests.http b/apps/api/requests.http index 9fe36aa7..0e3b9206 100644 --- a/apps/api/requests.http +++ b/apps/api/requests.http @@ -58,4 +58,20 @@ content-type: application/json { "url": "firecrawl.dev", "sitemapOnly": true +} + +### Extract +# @name extract +POST {{baseUrl}}/v1/extract HTTP/1.1 +Authorization: Bearer {{$dotenv TEST_API_KEY}} +content-type: application/json + +{ + "urls": ["firecrawl.dev"], + "prompt": "What is the title, description and main product of the page?", + "schema": { + "title": "string", + "description": "string", + "mainProduct": "string" + } } \ No newline at end of file diff --git a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts index 1a5abd66..ab619423 100644 --- a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts +++ b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts @@ -108,6 +108,15 @@ export async function generateOpenAICompletions(logger: Logger, options: Extract required: ["items"], additionalProperties: false, }; + } else if (schema && typeof schema === 'object' && !schema.type) { + schema = { + type: "object", + properties: Object.fromEntries( + Object.entries(schema).map(([key, value]) => [key, { type: value }]) + ), + required: Object.keys(schema), + additionalProperties: false + }; } schema = normalizeSchema(schema);