Created
February 3, 2023 10:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 } ] }