I am creating a web extension which “scans” the page and uses results to form a response, here is my code:
function scanAndSummarizeWebpage() {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
const activeTab = tabs[0];
chrome.scripting.executeScript({
target: { tabId: activeTab.id },
function: getWebsiteContent
}, function(results) {
const websiteContent = results[0].result;
console.log(websiteContent);
alert (websiteContent);
const endpoint = 'https://api.openai.com/v1/chat/completions';
const data = {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: websiteContent },
{ role: 'assistant', content: 'Summarise this webpage.'}
],
max_tokens: 282,
temperature: 0.3,
model: 'gpt-3.5-turbo',
n: 1,
};
I’ve tried running it through postman and it only shows an error message: “We could not parse the JSON body of your request. (HINT: This likely means you aren’t using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)”
Asheepiedino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.