This is the repository for the LinkedIn Learning course OpenAI API: Introduction. The full course is available from LinkedIn Learning.
The OpenAI API gives you programmatic access to OpenAI’s GPT system for everything from chat (your own ChatGPT clone) to image processing through Dall-E, to audio processing with Whisper, to building custom assistants and more. In this course you’ll learn how the OpenAI API works, how to use it both in the OpenAI playground and in your own apps, and where to find up-to-date documentation and examples.
See the readme file in the main branch for updated instructions and information.
This repository provides basic examples of how to use the OpenAI API in both Python and Node.js. The Python examples are found in the /python
folder, the Node.js examples in the /node
folder. The examples perform identical tasks using the same API across the two different languages.
There is also a stand-alone web-based example of how to use the streaming feature in the /streaming
folder. The /streaming/request.js
file contains the request and stream handling code. To run this example, open ./index.html
in Live Server.
To use these exercise files you need an OpenAI API key. You get that key at platform.openai.com
- Click the "Code" button and select "Codespaces."
- Create a new Codespace or open one you've already created.
- Create a new file named
.env
in the root folder. - Add
OPENAI_API_KEY=
followed by your OpenAI API key to.env
- Note
.env
is not tracked by GitHub so the file will only exist in this Codespace. - To run the Python example in terminal, use the
python example-python.py
command. - To run the Node.js example in terminal, use the
node example-node.js
command.
- Rename the file
config-template.json
toconfig.json
. - Add your OpenAI API key to the JSON object.
- Use the Live Server extension to run
/streaming/index.html
in the browser. - Interact with the agent.
- The API interaction happens in
/streaming/request.js
. - IMPORTANT: Read the warning at the top of
/streaming/request.js
.