This is a very basic Python bot that uses OpenAI API to query the PyTorch website. You can modify the script to query any other website. This is a very simple example just to get a taste of how easy it is to use OpenAI API. This example is inspired by the OpenAI documentation.
qa-bot-quick-demo.mov
NOTE: You can run this bot in this Google Colab. Clone the Colab to your own Google Drive to avoid leaking your token.
- A GitHub Account
- An Open AI token (can be obtained in your Open AI Account Settings)
You can run this as a script or use the notebook instead. To learn how to run the notebook, see
-
Fork this repo by clicking Fork in the upper-right corner of the home page.
-
One your computer, open a terminal.
-
Clone your fork to your computer by running:
If you are using SSH:
git clone git@github.com:<path to your fork>.git
If you are using HTTPs:
git clone https://github.com/<path-to-your-fork>.git
-
Change directory to your fork:
cd path-to-your-fork
-
Install dependencies:
pip3 install -r requirements.txt
-
Open the script file for editing, for example using
vim
:vi qa-bot-test.py
-
In the script, replace
YOUR_API_KEY
with the token you have obtained from your OpenAI account. -
Save the file:
:x!
-
Run the script:
python3 qa-bot-test.py
Response:
What would you like to learn? (type "exit" to quit):
- Type your question and receive an answer. For example: How to install PyTorch?
- To terminate the bot, type
exit
.
We have a Jupyter notebook in addition to Python script that you can test. You need to have Jupyter labs installed. You can install it by running the following command:
pip install jupyterlab
pip install notebook
After that, navigate to the directory of this repo and run:
jupyter notebook
This opens the Jupyter labs UI in your browser from where you can select the qa-bot-test.ipynb
notebook to open in a new window.
Run all the cells in the notebook one after another and ask the bot questions as needed.
After you are done, go back to the terminal and click CTRL-D to interrupt the process.
Here is a quick demo of how it works:
qa-bot-notebook-demo.mp4
openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.
If you see the error above, it means exactly that - you have execeed your current limit and need to either wait or upgrade your account.