From 5de5e5073c3080f61d6e8f095c9745b32e0e1769 Mon Sep 17 00:00:00 2001 From: rama0711 Date: Tue, 5 Dec 2023 18:20:15 +0300 Subject: [PATCH 1/5] imported the filesystem module to read the topics.json --- netlify/functions/handleMetadata.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index e35f22f..1a52fc3 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -1,6 +1,8 @@ const fetch = require('node-fetch'); // Import for webscraping in fetchContentFromURL() import { OpenAIApi, Configuration } from 'openai'; // const { Configuration, OpenAIApi } = require('openai'); +// Import the filesystem module to read the topics.json file +const fs = require('fs'); // Function to fetch content from URL using a web scraping service async function fetchContentFromURL(url) { @@ -104,6 +106,7 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { return { inferredMediaType, extractedTopics }; } + // Placeholder function to map inferred values to predefined formats and topics function mapInferredValues(mediaType, topics) { // Implement logic to map inferred media type and topics to predefined formats and topics From 6f0538cd1e433c63145112cd755481457ad77c8d Mon Sep 17 00:00:00 2001 From: rama0711 Date: Tue, 5 Dec 2023 18:21:32 +0300 Subject: [PATCH 2/5] updated the mapInferredValues function --- netlify/functions/handleMetadata.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 1a52fc3..3f77ae3 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -106,17 +106,28 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { return { inferredMediaType, extractedTopics }; } - // Placeholder function to map inferred values to predefined formats and topics function mapInferredValues(mediaType, topics) { // Implement logic to map inferred media type and topics to predefined formats and topics // Match inferred values with predefined taxonomy - // Placeholder code + + // Load predefined topics from topics.json + // const predefinedTopicsList = loadTopics(); + + // Map inferred topics to predefined topics + // const predefinedTopics = topics.map(topic => { + // const matchedTopic = predefinedTopicsList.find(predefinedTopic => predefinedTopic.name === topic); + // return matchedTopic ? matchedTopic.hname || matchedTopic.name : topic; + // }); + + // Assuming the media type is always 'Article' + // const predefinedMediaType = "Article"; + + // Placeholder return value until we can fix the openai import issue const predefinedMediaType = "Article"; const predefinedTopics = ["Topic 1", "Topic 2"]; return { predefinedMediaType, predefinedTopics }; } - // Placeholder function to format the response function formatResponse(predefinedMediaType, predefinedTopics) { // Implement logic to format the extracted metadata into the desired response structure From 0b5c0e2e23c3fb0fc28d946bb973ec14a94616f0 Mon Sep 17 00:00:00 2001 From: rama0711 Date: Tue, 5 Dec 2023 18:22:20 +0300 Subject: [PATCH 3/5] added helper function to mapInferredValues --- netlify/functions/handleMetadata.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 3f77ae3..457e954 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -106,6 +106,11 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { return { inferredMediaType, extractedTopics }; } +// Function to load topics from the topics.json file +function loadTopics() { + const topicsData = fs.readFileSync('path/to/topics.json', 'utf8'); + return JSON.parse(topicsData); +} // Placeholder function to map inferred values to predefined formats and topics function mapInferredValues(mediaType, topics) { // Implement logic to map inferred media type and topics to predefined formats and topics From f8ac44d2b68c166086bb0d573e245fec996f91e5 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 5 Dec 2023 18:27:35 +0300 Subject: [PATCH 4/5] fixed the style in handleMetadata.js --- netlify/functions/handleMetadata.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 457e954..f4284d6 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -1,6 +1,6 @@ -const fetch = require('node-fetch'); // Import for webscraping in fetchContentFromURL() +// Import for webscraping in fetchContentFromURL() +const fetch = require('node-fetch'); import { OpenAIApi, Configuration } from 'openai'; -// const { Configuration, OpenAIApi } = require('openai'); // Import the filesystem module to read the topics.json file const fs = require('fs'); @@ -63,7 +63,7 @@ function simplifyContent(content) { return simplifiedContent; } -// Placeholder function to perform GPT analysis for media type and topics using Mistral-7b via OpenRouter +// Function to perform GPT analysis for media type and topics using Mistral-7b via OpenRouter async function performGPTAnalysis(simplifiedContent, apiKey) { // Implement logic to send content to Mistral-7b via OpenRouter for GPT analysis // Send content and receive GPT analysis response @@ -111,7 +111,7 @@ function loadTopics() { const topicsData = fs.readFileSync('path/to/topics.json', 'utf8'); return JSON.parse(topicsData); } -// Placeholder function to map inferred values to predefined formats and topics +// Function to map inferred values to predefined formats and topics function mapInferredValues(mediaType, topics) { // Implement logic to map inferred media type and topics to predefined formats and topics // Match inferred values with predefined taxonomy From f9773394e073b457f47cf011fce60070de0e5790 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 5 Dec 2023 18:30:51 +0300 Subject: [PATCH 5/5] updated the file path --- netlify/functions/handleMetadata.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index f4284d6..a46b05f 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -108,7 +108,7 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { // Function to load topics from the topics.json file function loadTopics() { - const topicsData = fs.readFileSync('path/to/topics.json', 'utf8'); + const topicsData = fs.readFileSync('db/topics.json', 'utf8'); return JSON.parse(topicsData); } // Function to map inferred values to predefined formats and topics