Jupyter major upgrade! Various large models can be connected, and codes can be generated and errors corrected by chatting!

Article source: Get up early Python

Hello everyone, I am Brother Tao. Today I will share with you a major upgrade of Jupyter: various large models can be connected, code can be generated and errors can be corrected by chatting; the full text is 1800, and it takes about 7 minutes to read.

Large language models (LLM) are connected with Jupyter! This is mainly due to a project called Jupyter AI, which is an officially supported sub-project of Project Jupyter. At present, the project is completely open source, and its connected models are mainly from major star companies and institutions such as AI21, Anthropic, AWS, Cohere, and OpenAI.

05338f9a7176f7da933aaa27765682e7.png

Project address: https://github.com/jupyterlab/jupyter-ai

With the support of large models, Jupyter's functions have also undergone great changes. Now you can generate code, summarize documentation, create comments, fix bugs, and more in this environment. You can even use text prompts to generate notebooks.

The installation process of Jupyter AI is also very simple. The installation code is as follows:

pip install 'jupyter-ai>=1.0,<2.0' # If you use JupyterLab 3
pip install jupyter-ai # If you use JupyterLab 4

In addition, Jupyter AI provides two different interfaces for interacting with LLM. In JupyterLab, you can use the chat interface to talk to the LLM to help work with your code. Additionally, in any environment that supports notebooks or IPython, including JupyterLab, Notebook, IPython, Colab, and Visual Studio Code, you can use the %% ai magic command to call LLM.

0c91659cbf557bea5cfbf0cf65234af4.png

Jupyter powered by large models

Next let's see how it works.

Programming Assistant

The Jupyter chat interface is shown in the figure below, and users can talk to Jupyternaut (programming assistant). In the Jupyternaut function bar, we can see this sentence "Hello everyone, I am Jupyternaut, your programming assistant. You can use the text box to ask me questions, or you can use commands to ask me questions."

e4b01d0f24878cfed83e54e6e973ee3e.png

Next, the user asked Jupyternaut a question: "In Python, what is the difference between tuples and lists?" Jupyternaut gave the key differences between the two, and answered it very correctly, and finally gave an example thoughtfully. :

bc7b800f836f1415816d2a5d22c26213.png

If there is a part of the code that you don't understand very well, you can select this part of the code and use it as a prompt, and then ask Jupyternaut to explain the code. In addition, Jupyternaut can also modify the code, identify code errors, etc.

a277af17aa049633632c708676bc6eff.png

If you are not satisfied with the code, you can also ask Jupyternaut to rewrite the code as required:

9dc51f117025bd132f4d86e5e78b114d.png

After rewriting the code, Jupyternaut will resend the code back to the user-selected language model for replacement:

13bb33d35f384b537593f3c8196c361f.png

Generate notebook from text prompt

Jupyter AI's chat interface can generate a complete notebook based on text prompts. To achieve this, the user needs to run the "/generate" command, plus a text description.

cc0adbde5946d304f1852cd82c068798.png

After Jupyternaut generates the notebook, it will send a message containing the file name to the user, and the user can open the file to view:

7af07771565d130f926dc7e5115a3fab.png

Access local files

You can use the "/learn" command to tell Jupyternaut to learn local files, and then use the "/ask" command to ask questions about the local files. For example, using the "/learn" command, you can tell Jupyternaut to learn about the Jupyter AI documentation:

f761a58546460e14a3d9e239018694d7.png

Once you've finished learning Jupyternaut, you can ask questions using the "/ask" command:

666ebb5f590c7ae032a6ddef9c0bfd44.png

magic function

Jupyter AI also provides ai commands that can be run in notebook cells and the IPython command line interface. Each ai command requires a model, usually specified as provider‑id:model‑id:

de9a1b676016c444324f9e1aa5837b5f.png

Another researcher experienced the %% ai magic command and asked it to call ChatGPT:

555f2455bcbb84e3015a2463978c54bf.png

In addition, you can use the -f or --format parameter to customize the format of the output, including HTML, mathematics, source code, and images, which is very useful for researchers and educators.

0ae7616973a757543cb12ebcbc192051.png

After some demonstration, Jupyter with the support of large models is indeed much more convenient. Friends who want to try it can go and give it a try.

Reference link: https://blog.jupyter.org/generative-ai-in-jupyter-3f7174824862

干货笔记整理

  100个爬虫常见问题.pdf ,太全了!
Python 自动化运维 100个常见问题.pdf
Python Web 开发常见的100个问题.pdf

124个Python案例,完整源代码!
PYTHON 3.10中文版官方文档
耗时三个月整理的《Python之路2.0.pdf》开放下载
最经典的编程教材《Think Python》开源中文版.PDF下载

Guess you like

Origin blog.csdn.net/wuShiJingZuo/article/details/133191405