Intro#
When studying Professor Andrew Ng's prompt engineering course, I learned about the Jupyter tool and Markdown syntax. I am writing this article to document how to use Jupyter to call ChatGPT and also to record my first time using Markdown to write a blog.
1/ Thrilled to announce: Our new course ChatGPT Prompt Engineering for Developers, created together with @OpenAI, is available now for free! Access it here: deeplearning.ai/short-courses/…
Introduction to Jupyter#
What is Jupyter:
Jupyter is a web-based interactive computing environment that supports multiple programming languages such as Python, R, Julia, etc. The name Jupyter comes from its support for three core programming languages: Ju(lia), Py(thon), R, which it is built upon.
Features:
The main function of Jupyter is to provide an interactive coding environment where you can edit and run code, as well as integrate code, explanatory text, mathematical formulas, images, and other content into a notebook file. Jupyter notebook files (.ipynb files) can be easily shared and distributed, making Jupyter a common tool in development, testing, teaching, data analysis, and other fields.
Advantages:
Jupyter supports various plugins and extensions, which can provide richer functionality. For example, nbconvert can convert notebook files into various document formats and display slideshows. In addition, Jupyter also supports JupyterLab, a new interface that organizes multiple notebooks in tab form, improving work efficiency.
Installing Jupyter#
According to my understanding, there are many ways to install Jupyter:
- Install through Anaconda
- Install through tools like VScode
- Install using pip
Here, I will demonstrate the installation method using pip:
Open the Run dialog by pressing win+r
, type cmd
, and enter the following code in the command prompt:
pip install jupyter
Once the installation is complete, you can use the following code in the command prompt to start using it:
jupyter notebook
After running it, a web interface will open in your browser, and you can perform subsequent operations within this web page.
Connecting to ChatGPT#
Installing the Project#
There are many tutorials on GitHub, but of course, you can also write your own. Here, I will use the repository of lixibi as a demonstration. One reason is that this project lists some prompt examples, and another reason is that this project includes several servers that allow us to use it without a VPN.
Clone the repository to your local machine:
Open cmd in the folder path where you want to install, or press win+r
to open the cmd
command prompt, then use the cd
command to switch to the specified directory. After that, use the following command in the cmd command prompt. Once it finishes running, you can open the aforementioned jupyter notebook
and find the project file in your browser.
git clone https://github.com/lixibi/CHATGPT-In-Jupyter.git
Creating the openai_key#
Open the API website of OpenAI and follow the instructions in the following images to create the key.
- Note that each key will only be displayed once, so keep it safe. If you lose it, you can delete it and create a new one.
Configuration#
After opening Jupyter notebook, find the cloned project directory for configuration. Open the Chapter01-Main.ipynb
file, and in the image, the url
is the preset server for this project. You can use this without changing it, or you can use your own server. In the quotes after api_key = '{fill in the key here}'
, enter the copied key
.
Usage and Prompt#
The usage is very simple, just run the first two code blocks. Below are some preset prompt examples, which are easy to understand. If you want to modify the prompt, just modify the corresponding text in the code block. You can also refer to Professor Andrew Ng's prompt engineering tutorial.