modified fetchContentFromURL() to use node-fetch now that import is working

pull/73/head
Huda Joad 2023-11-24 23:38:02 +03:00
rodzic 2bad128834
commit 535ccfaefe
1 zmienionych plików z 11 dodań i 16 usunięć

Wyświetl plik

@ -2,23 +2,18 @@ const https = require('https'); // Import for webscraping (fetchContentFromURL(u
import { OpenAIApi, Configuration } from 'openai'; import { OpenAIApi, Configuration } from 'openai';
import { fetch } from 'node-fetch'; import { fetch } from 'node-fetch';
// Placeholder function to fetch content from URL using a web scraping service // Function to fetch content from URL using a web scraping service
async function fetchContentFromURL(url) { async function fetchContentFromURL(url) {
return new Promise((resolve, reject) => { try {
https.get(url, (response) => { const response = await fetch(url);
let data = ''; if (!response.ok) {
// A chunk of data has been received. throw new Error(`HTTP error! status: ${response.status}`);
response.on('data', (chunk) => { }
data += chunk; return await response.text();
}); } catch (error) {
// The whole response has been received. console.error(`Could not fetch content from URL: ${error}`);
response.on('end', () => { throw error;
resolve(data); }
});
}).on("error", (error) => {
reject(`Error fetching URL: ${error.message}`);
});
});
} }
function simplifyContent(content) { function simplifyContent(content) {