Hat’s off to the wonderful Dona for teaching us how to do this yesterday! 💖
So we’re going to need to install a few things before we get building or writing code out here! Go ahead and install these things on your computer…
- Visual Studio Code
- Node JS
- Create an OpenAI Account so you can fetch an API Key
Creating an OpenAI API Key
So we’ll need an API key for OpenAI first. To do this, in your OpenAI account head to view API keys. Then create and copy one. Save it somewhere temporarily until you’ve created it on your device as an environment variable.
Store the API key in an environment variable on your device
Now we’ll need to store the API key in an environment variable on our local device which we’ll then be able to reference in our code.
For Windows, MacOS and Linux guidance on creating an environment variable, check out this article on best practices for API key safety from OpenAI.
Copy some files
Now you’ll need to copy some files onto your local machine which will include the main .js file where the code for our command line bot will sit. There will also be files included that will be dependencies for our console app.
Now test out your code by running it either in VS Code using the terminal, or run it in a terminal window on your device.
Testing it out
So testing it out, as expected the first thing we are asked is what the bot should ask questions on. Then it’ll allow us to say hello to it and ask questions about it’s specified topic! Then when we ask the bot a question, as expected, we get a precise answer outlined in bullet points, then with sources as to how the bot answered the question.
Did you like this content? 💖
Did you like this content? Check out some of the other posts on my blog, and if you like those too, be sure to subscribe to get my posts directly in your inbox for free!