From 5478b7709f8d5ed02b41eb99b0be1a4bc1b116b9 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Wed, 29 Nov 2023 12:18:49 +0300 Subject: [PATCH] changed the structure of the imports --- netlify/functions/handleMetadata.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 964aac1..f1196f6 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -1,7 +1,15 @@ -import OpenAIApi from 'openai'; -import Configuration from 'openai/lib/configuration'; -// const { Configuration, OpenAIApi } = require('openai'); -const fetch = require('node-fetch'); +// import OpenAIApi from 'openai'; +// import Configuration from 'openai/lib/configuration'; +const { Configuration, OpenAIApi } = require('openai'); +// const fetch = require('node-fetch'); + +let fetch; + +async function loadFetch() { + if (!fetch) { + fetch = (await import('node-fetch')).default; + } +} // Function to fetch content from URL using a web scraping service async function fetchContentFromURL(url) { @@ -99,7 +107,7 @@ function formatResponse(predefinedMediaType, predefinedTopics) { return response; } -export async function handler(event) { +async function handler(event) { try { // Extract URL and API Key from the request body const { url, apiKey } = JSON.parse(event.body); @@ -139,4 +147,5 @@ export async function handler(event) { body: JSON.stringify({ error: 'Something went wrong', details: error.message }), }; } -} \ No newline at end of file +} +module.exports = { handler }; \ No newline at end of file