Integrating the Answers endpoint
Now we'll go back and add some code to our routes/answer.js
file so that it calls the OpenAI Answers endpoint to answer the user's question, rather than returning the placeholder text:
- Open the
routes/answer.js
file and do the following. - Delete all of the code after line 5.
- Starting on line 5, add the following code followed by a line return:
const apiKey = process.env.OPENAI_API_KEY; const client = axios.create({ headers: { 'Authorization': 'Bearer ' + apiKey } });
- Next, add the following code with a line return after it:
const documents = [ "I am a day older than I was yesterday.<|endoftext|>", "I build applications that use GPT-3.<|endoftext|>", "My preferred programming is Python.<|endoftext|>" ]
- Add the following code starting on line 16 followed by a line return:
const endpoint = 'https://api...