Jupyter Notebook can also import ChatGPT

What difficulties do you encounter when using AI coding assistants? Does it make you love or hate it? The Chapyter introduced in this article combines the currently popular ChatGPT code interpreter with Jupyter Notebook to make your coding more efficient.

Enter the NLP group —> join the NLP exchange group

There is no doubt that with the help of AI, developers' coding efficiency can be greatly improved.

Developers will be freed from simple, repetitive coding work. But the many problems that follow often make developers who use AI bald.

Chapyter incorporates a powerful code generation model such as GPT-4 into the Jupyter Notebook coding environment, opening up a new model of human-AI collaboration, and solving the problems that most programming assistants will have to a great extent.

Chapyter is a JupyterLab extension that seamlessly connects GPT-4 to your coding environment and has a code interpreter that translates natural language descriptions into Python code and executes them automatically. And Chapyter improves your productivity by enabling "natural language programming" in your most familiar IDE, and enables you to explore more untried new ideas.

f7af83ccdd2dab706963288b27f3270c.png

Project link: https://github.com/chapyter/chapyter

The figure below shows the difference between Chapyter and some existing coding assistants.

It can be found that Chapyter combines the advantages of coding assistants. It can help developers complete various complex coding tasks, automatically execute AI-generated code, and also allow developers to perform in-situ debugging, customize prompts, and even protect the privacy of developers and codes to prevent data from being used.

84ed3eb480616a0b917d83de94ccfffb.png

Features and Benefits of Chapyter

The main features of Chapyter are:

1. Generate code from natural language and execute it automatically

Just add the command "%% chat" at the beginning of the cell of the task natural language description, and the code will be generated in a very short time, only a few seconds.

34bb32995cff627a6bc6a83fefce8d20.gif

Don't underestimate this advantage of Chapyter.

Autocompletion has been a mainstream interaction with many AI-assisted coding tools, providing AI support in the coding environment and can significantly improve the productivity and satisfaction of developers' work. However, autocompletion is not perfect: interspersed with AI code suggestions can be distracting; generated code can contain hidden bugs that can be difficult to debug; function.

Chapyter overcomes these problems by providing cell-level code generation and automatic execution. You just type in a natural language description of what you want to do, and Chapyter will call the GPT-X model to generate the code and execute it for you. This is very different from code completion in systems like Copilot: it is designed to support microtasks that span only a few lines of code and are very relevant to the work at hand, for example, completing a function call. Whereas Chapyter is designed to take over complete tasks, which may sometimes differ from existing code.

The generated code is hidden by default because Chapyter wants to downplay the AI-generated code and focus on the results. Also, you don't need to worry about auto-execution, because Chapyter has a safe mode to prevent auto-execution of potentially dangerous code.

2. Use coding history and execution output to generate code

Chapyter can also leverage your code history and execution output to provide context-aware suggestions. It can also optionally load files to provide suggestions for further processing and analysis.

As shown in the figure below, by adding the --history or -h flag to the code generation, Chapyter can use the previous execution history and output to generate the corresponding visualization code for the loaded IRIS dataset.

1e5e1a3c36b9313fa875aa2e6d33112b.gif

3. In-situ debugging and editing code

The generated code may not be perfect and may contain bugs or errors. Since Chapter is fully integrated into Jupyter Notebook, you can easily inspect your code and fix any errors or bugs (for example, in this case installing missing dependencies) without leaving the IDE.

8b40e3788b8fb87717215faf17959e4f.gif

4. Prompt and AI configuration are transparent and allow customization

Chapyter publishes all the prompts used in the library and strives to make it easier to customize the prompts and settings used.

Available at: https://github.com/chapyter/chapyter/blob/main/chapyter/programs.py

5. When using AI, privacy comes first 

Chapyter is a tiny Python package that can be installed locally and used seamlessly with JupyterLab. It uses the OpenAI API to call the GPT-X model, and does not keep interaction data and code for training by default.

So unlike Copilot or ChatGPT, which cache your data and use it for training and analysis, all data sent to OpenAI by Chapyter will not be saved for training (see OpenAI API data usage policy).

Composition of Chapyter

Chapyter mainly consists of two parts:

  • Implement the ipython magic command to handle prompts and invoke GPT-X models;

  • The other is a front end that listens to the execution of Chapyter cells, which automatically executes newly generated cells and updates the styles of the cells.

The figure below shows the orchestration of the front end and ipython kernel after executing a Chapyter cell.

954923bfce26989c04cc9a844a767f99.png

Reference link:

https://www.reddit.com/r/MachineLearning/comments/15269v8/p_chapyter_chatgpt_code_interpreter_in_jupyter/

https://www.szj.io/posts/chapyter

https://github.com/chapyter/chapyter


Enter the NLP group —> join the NLP exchange group

Guess you like

Origin blog.csdn.net/qq_27590277/article/details/131874936