Challenge: Text Summarizer Using OpenAI
Take on the coding challenge to develop an API using Express.js for generating summarized text using OpenAI.
We'll cover the following
Problem statement
Text summarization generates a shortened version of a text document that captures the key points and conveys the essential meaning. It condenses lengthy pieces of text, such as articles, research papers, or emails, into a more digestible format while aiming to preserve the original content's core message. In this challenge, there will be a long piece of text that needs to be summarized using OpenAI.
Below are the functions that needs to be implemented in order to finish the challenge. A code editor is provided after the problem statement to complete the coding challenge. Make sure all the points are implemented. After the coding challenge, there is a solution provided in the next lesson.
Requirements
Implement the
fetchSummary()
function in theutils.js
file. Below are the requirements:The function will accept one parameter:
text
which needs to be read from the file data.txt.Use OpenAI and a write a suitable prompt to generate the summarized content.
Implement the
readData()
function inutils.js
file. Below are the requirements:Read the text data from the file
data.txt
and return the data. Use thefs
module to read the file data.
Implement the API route to get the summary in
index.js
file. Below are the requirements:An endpoint
/get-summary
is already created and please do not update the endpoint.Call the
fetchSummary()
function and make sure error-handling is implemented properly.In case of any error, return an object in the response containing
error
key and the error message as its value. Also, send the status code as 400.
You can directly access the variable
openai_api_key
to access your OpenAI key that was set up earlier.
Try it yourself
Below is the code block in which you can complete the coding challenge as per the requirements given.
Get hands-on with 1400+ tech skills courses.