Skip to content

Instantly share code, notes, and snippets.

@CodeLeom
Created February 3, 2023 10:57
Show Gist options
  • Save CodeLeom/877aa4d8089d261e6e85bd0a5372e629 to your computer and use it in GitHub Desktop.
Save CodeLeom/877aa4d8089d261e6e85bd0a5372e629 to your computer and use it in GitHub Desktop.
A code to generate novel/book summary using Chat GPT. This code uses the Axios library to make a POST request to the OpenAI GPT-3 API and returns the generated summary
const axios = require('axios');
async function summarizeNovel(text) {
const response = await axios.post('https://api.openai.com/v1/engines/text-davinci-002/jobs', {
prompt: 'Please summarize this text:',
max_tokens: 100,
temperature: 0.5,
n: 1,
stop: ['Thank you.'],
text,
}, {
headers: {
'Authorization': 'Bearer <API_KEY>',
'Content-Type': 'application/json',
},
});
return response.data.choices[0].text;
}
const novelText = '<INSERT_YOUR_NOVEL_TEXT_HERE>';
summarizeNovel(novelText).then((summary) => {
console.log(summary);
});
@CodeLeom
Copy link
Author

CodeLeom commented Feb 3, 2023

The response from the OpenAI GPT-3 API will be a JSON object with the following format
{ "id": "JOB_ID", "model": "text-davinci-002", "status": "completed", "created_at": "TIMESTAMP", "choices": [ { "text": "SUMMARY_TEXT", "response_time": NUMBER, "logprobs": NUMBER } ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment