banner
0xMech

0xMech

Focus on various AI application sharing, Blockchain learners, web3 new leeks
twitter

gptfromjupyter

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.

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 the three core programming languages it supports: 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 extension packages, 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#

From my understanding, there are many ways to install Jupyter:

  1. Install through Anaconda
  2. Install through tools like VScode
  3. Install using pip

Here, I will demonstrate the installation 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 Jupyter:

jupyter notebook

After running the code, a web interface will open in your browser, and you can perform further operations within this web page.

jupy.png

Connecting to ChatGPT#

Installing the Project#

There are many tutorials available on GitHub, but for the demonstration, I will use the repository of lixibi, who is a great contributor. One reason is that this project provides some prompt examples, and another reason is that it includes several servers that allow us to use it without the need for a VPN.

Clone the repository to your local machine:
Open the command prompt in the desired folder path, or press win+r to open the cmd command prompt, then use the cd command to navigate to the specified directory. In the command prompt, use the following command, and 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

clone.png

Creating the openai_key#

Open the API website of OpenAI and follow the steps shown in the images below to create the key.

  • Note that each key is only displayed once, so make sure to keep it safe. If you lose it, you can delete it and create a new one.

creat_key1.png

create_key2.png

create_key3.png

Configuration#

After opening Jupyter notebook, navigate to 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 making any changes, or you can use your own server. In the quotes after api_key = '{fill in the key here}', enter the copied key.

初始配置 1.png

配置 2.png

Usage and Prompt#

The usage is very simple, just run the first two code blocks. Below are some preset prompt examples that are easy to understand. If you want to modify the prompt, simply modify the corresponding text in the code block. You can also refer to Professor Andrew Ng's prompt engineering tutorial.

吴.png

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.