From 7625ffca6e266b2412ea42f73712dd943bdb3336 Mon Sep 17 00:00:00 2001 From: Skultrix Date: Tue, 28 Nov 2023 19:00:24 +0300 Subject: [PATCH 1/8] Init commit --- netlify/functions/handleMetadata.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index eff5401..04e67c1 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -49,6 +49,9 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { // Placeholder code const inferredMediaType = ["article"]; const extractedTopics = ["topic1", "topic2"]; + + //My work + return { inferredMediaType, extractedTopics }; } From 7c81a25f8c11c2102fd84e2efe4c569526bc31a7 Mon Sep 17 00:00:00 2001 From: Skultrix Date: Tue, 28 Nov 2023 19:13:11 +0300 Subject: [PATCH 2/8] First test --- netlify/functions/handleMetadata.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 04e67c1..645d2d7 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -50,9 +50,30 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { const inferredMediaType = ["article"]; const extractedTopics = ["topic1", "topic2"]; - //My work + const configuration = new Configuration({ + apiKey: apiKey, // Use the provided API key + baseURL: "https://openrouter.ai/api/v1" // Your custom API endpoint + }); - return { inferredMediaType, extractedTopics }; + const openai = new OpenAIApi(configuration); + + try { + // Using the specified prompt + const prompt = `Analyze the following text and provide the media type and key topics: ${content}`; + + const completion = await openai.createCompletion({ + model: "mistralai/mistral-7b-instruct", + prompt: prompt, + max_tokens: 150 // Adjust as needed + }); + + return completion.data.choices[0].text.trim(); + } catch (error) { + console.error('Error with OpenAI completion:', error); + throw error; + } + + //return { inferredMediaType, extractedTopics }; } // Placeholder function to map inferred values to predefined formats and topics From a861b439d690b96d9de0544c43d6b18a788a3282 Mon Sep 17 00:00:00 2001 From: Skultrix Date: Tue, 28 Nov 2023 19:28:04 +0300 Subject: [PATCH 3/8] Changed to simplified content --- 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 645d2d7..c82f1ca 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -59,7 +59,7 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { try { // Using the specified prompt - const prompt = `Analyze the following text and provide the media type and key topics: ${content}`; + const prompt = `Analyze the following text and provide the media type and key topics: ${simplifiedContent}`; const completion = await openai.createCompletion({ model: "mistralai/mistral-7b-instruct", From a8985bdd99c63bffd9c3eca1a155cef447fd3f67 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 28 Nov 2023 19:47:13 +0300 Subject: [PATCH 4/8] testing --- netlify/functions/handleMetadata.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index c82f1ca..10757fc 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -67,7 +67,8 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { max_tokens: 150 // Adjust as needed }); - return completion.data.choices[0].text.trim(); + const responseText = completion.data.choices[0].text.trim(); + return responseText; } catch (error) { console.error('Error with OpenAI completion:', error); throw error; @@ -129,7 +130,7 @@ export async function handler(event) { // Return the formatted response return { statusCode: 200, - body: JSON.stringify(simplifiedContent), + body: JSON.stringify(responseText), }; } catch (error) { console.error('Error occurred:', error.message); From e4b0ea0ba058249f5e2ac0f3c942aa47a19e2753 Mon Sep 17 00:00:00 2001 From: Skultrix Date: Tue, 28 Nov 2023 19:55:51 +0300 Subject: [PATCH 5/8] Quick fix --- netlify/functions/handleMetadata.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index c82f1ca..0bdabe1 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -67,7 +67,8 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { max_tokens: 150 // Adjust as needed }); - return completion.data.choices[0].text.trim(); + const responseText = completion.data.choices[0].text.trim(); + return responseText; } catch (error) { console.error('Error with OpenAI completion:', error); throw error; @@ -118,7 +119,7 @@ export async function handler(event) { const simplifiedContent = simplifyContent(fetchedContent); // Step 3: Perform GPT analysis for media type and topics - const { inferredMediaType, extractedTopics } = await performGPTAnalysis(simplifiedContent, apiKey); + const responseText = await performGPTAnalysis(simplifiedContent, apiKey); // Step 4: Map inferred values to predefined formats and topics const { predefinedMediaType, predefinedTopics } = mapInferredValues(inferredMediaType, extractedTopics); @@ -129,7 +130,7 @@ export async function handler(event) { // Return the formatted response return { statusCode: 200, - body: JSON.stringify(simplifiedContent), + body: JSON.stringify(responseText), }; } catch (error) { console.error('Error occurred:', error.message); From bfcb6e6544a9eb03cc3352877a65782d533b89b1 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 28 Nov 2023 20:11:31 +0300 Subject: [PATCH 6/8] testing --- 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 10757fc..72b3ab6 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -68,13 +68,13 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { }); const responseText = completion.data.choices[0].text.trim(); - return responseText; + //return responseText; } catch (error) { console.error('Error with OpenAI completion:', error); throw error; } - - //return { inferredMediaType, extractedTopics }; + const responseText = "Article"; + return responseText; } // Placeholder function to map inferred values to predefined formats and topics @@ -119,7 +119,7 @@ export async function handler(event) { const simplifiedContent = simplifyContent(fetchedContent); // Step 3: Perform GPT analysis for media type and topics - const { inferredMediaType, extractedTopics } = await performGPTAnalysis(simplifiedContent, apiKey); + const responseText = await performGPTAnalysis(simplifiedContent, apiKey); // Step 4: Map inferred values to predefined formats and topics const { predefinedMediaType, predefinedTopics } = mapInferredValues(inferredMediaType, extractedTopics); From 15e7346bd63cb6c819d54b847cd00926bb5bea2f Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 28 Nov 2023 20:14:52 +0300 Subject: [PATCH 7/8] updated the try/catch block --- netlify/functions/handleMetadata.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index 72b3ab6..e317058 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -50,14 +50,13 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { const inferredMediaType = ["article"]; const extractedTopics = ["topic1", "topic2"]; - const configuration = new Configuration({ - apiKey: apiKey, // Use the provided API key - baseURL: "https://openrouter.ai/api/v1" // Your custom API endpoint - }); - - const openai = new OpenAIApi(configuration); - try { + const configuration = new Configuration({ + apiKey: apiKey, // Use the provided API key + baseURL: "https://openrouter.ai/api/v1" // Your custom API endpoint + }); + + const openai = new OpenAIApi(configuration); // Using the specified prompt const prompt = `Analyze the following text and provide the media type and key topics: ${simplifiedContent}`; From ae1771c8990a70fa5cd665dffe423980fd82b840 Mon Sep 17 00:00:00 2001 From: Maria-Aidarus Date: Tue, 28 Nov 2023 20:18:04 +0300 Subject: [PATCH 8/8] testing with the old model --- netlify/functions/handleMetadata.js | 30 +++-------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/netlify/functions/handleMetadata.js b/netlify/functions/handleMetadata.js index e317058..eff5401 100644 --- a/netlify/functions/handleMetadata.js +++ b/netlify/functions/handleMetadata.js @@ -49,31 +49,7 @@ async function performGPTAnalysis(simplifiedContent, apiKey) { // Placeholder code const inferredMediaType = ["article"]; const extractedTopics = ["topic1", "topic2"]; - - try { - const configuration = new Configuration({ - apiKey: apiKey, // Use the provided API key - baseURL: "https://openrouter.ai/api/v1" // Your custom API endpoint - }); - - const openai = new OpenAIApi(configuration); - // Using the specified prompt - const prompt = `Analyze the following text and provide the media type and key topics: ${simplifiedContent}`; - - const completion = await openai.createCompletion({ - model: "mistralai/mistral-7b-instruct", - prompt: prompt, - max_tokens: 150 // Adjust as needed - }); - - const responseText = completion.data.choices[0].text.trim(); - //return responseText; - } catch (error) { - console.error('Error with OpenAI completion:', error); - throw error; - } - const responseText = "Article"; - return responseText; + return { inferredMediaType, extractedTopics }; } // Placeholder function to map inferred values to predefined formats and topics @@ -118,7 +94,7 @@ export async function handler(event) { const simplifiedContent = simplifyContent(fetchedContent); // Step 3: Perform GPT analysis for media type and topics - const responseText = await performGPTAnalysis(simplifiedContent, apiKey); + const { inferredMediaType, extractedTopics } = await performGPTAnalysis(simplifiedContent, apiKey); // Step 4: Map inferred values to predefined formats and topics const { predefinedMediaType, predefinedTopics } = mapInferredValues(inferredMediaType, extractedTopics); @@ -129,7 +105,7 @@ export async function handler(event) { // Return the formatted response return { statusCode: 200, - body: JSON.stringify(responseText), + body: JSON.stringify(simplifiedContent), }; } catch (error) { console.error('Error occurred:', error.message);