Home >Technology peripherals >AI >Cursor integrated with GPT-4 makes writing code as easy as chatting. A new era of coding in natural language has arrived.
Github Copilot X integrating GPT-4 is still in small-scale internal testing, while Cursor integrating GPT-4 has been publicly released. Cursor is an IDE that integrates GPT-4 and can write code in natural language, making writing code as easy as chatting.
There is still a big difference between GPT-4 and GPT-3.5 in their ability to process and write code. A test report from the official website.
The first two are GPT-4, one uses text input and the other uses image input; the third one is GPT3.5, which shows the coding capabilities of GPT-4 Compared with GPT-3.5, it has greater capabilities.
Github Copilot X integrating GPT-4 is still in small-scale testing, while Cursor integrating GPT-4 has been publicly released. Cursor is an IDE that integrates GPT-4 and can write code in natural language, making writing code as easy as chatting.
Integrated GPT-4 Cursor, shortcut keys: ctrl k on windows computer, comand k on mac computer to evoke the requirement input box to write code in natural language; ctrl l, comand l to evoke the chat window to write code and Chatting is just as easy.
First, press ctrl k. Write down a requirement: write a python program that converts pictures into characters and pictures and writes them into files. You need to use the pillow library. The araparse library
cursor is in a blank space. In the file, a complete python code is generated.
# Welcome to Cursor
# 1. Try generating with command K on a new line. Ask for a pytorch script of a feedforward neural network
# 2. Then, select the outputted code and hit chat. Ask if there's a bug. Ask how to improve.
# 3. Try selecting some code and hitting edit. Ask the bot to add residual layers.
# 4. To try out cursor on your own projects, go to the file menu (top left) and open a folder.
from PIL import Image
import argparse
# Command line input parameter processing
parser = argparse.ArgumentParser()
parser.add_argument('file') #Input file
parser.add_argument('-o', '--output' ) # Output file
parser.add_argument('--width', type = int, default = 80) # Output character width
parser.add_argument('--height', type = int, default = 80 ) # Output character drawing height
# Get parameters
args = parser.parse_args()
IMG = args.file
WIDTH = args.width
HEIGHT = args .height
OUTPUT = args.output
# The character set used for character painting, a total of 70 characters, can be extended by yourself
ascii_char = list("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&* ()_ -=[]{};':",./?\|`~ ")
# Map 256 grayscale to 70 characters
def get_char( r, g, b, alpha = 256):
if alpha == 0:
return ' '
length = len(ascii_char)
gray = int(0.2126 * r 0.7152 * g 0.0722 * b)
unit = (256.0 1)/length
return ascii_char[int(gray/unit)]
if __name__ == '__main__':
im = Image. open(IMG)
im = im.resize((WIDTH, HEIGHT), Image.NEAREST)
txt = ""
for i in range(HEIGHT):
for j in range(WIDTH):
txt = get_char(*im.getpixel((j, i)))
txt = 'n'
print(txt)
# Output character drawing to file
if OUTPUT:
with open(OUTPUT, 'w') as f:
f.write(txt)
else:
with open("output .txt", 'w') as f:
f.write(txt)
See if the automatically generated code can be run directly.
Select the following image for conversion:
(venv) PS C:UsershanweiPycharmProjectspythonProject> python .main.py -h
usage : main.py [-h] [-o OUTPUT] [--width WIDTH] [--height HEIGHT] file
positional arguments:
file
options:
-h, --helpshow this help message and exit
-o OUTPUT, --output OUTPUT
--width WIDTH
--height HEIGHT
(venv) PS C:UsershanweiPycharmProjectspythonProject> python .main .py .golang.png
After running the program, the conversion effect is as follows:
Let’s read the code below:
gray = int(0.2126 * r 0.7152 * g 0.0722 * b)
This code is so strange, ask what Cursor means. Press ctrl l to bring up the chat window and enter: What does this code mean
Cursor gave an explanation. It turns out that the gray value is calculated by weighting the values of r, g, and b, and then the characters are calculated through the gray value. A reference link is also given https://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
Press ctrl l to bring up the chat window and let AI explains the entire code, enter: Explain the entire code in Chinese
It can be seen that the AI explanation is very accurate and detailed.
The function of the above code is to convert the picture into a black and white ASCII character painting with gray scale. Let's transform it so that it can generate colorful character painting.
Press ctrl k to wake up the demand text box and enter: Please change this code from generating black and white characters to generating colored characters
See Animation: AI will scan each line of code line by line, mark the areas that need to be changed, and then provide the changed code below. And keep the original code for easy comparison.
The AI only changed 2 lines of code (actually only one line was changed, the second AI may have short-circuited its brain, completely equivalent changes), and achieved the The generation of black and white characters is changed to the generation of color characters. Test it below:
(venv) PS C:UsershanweiPycharmProjectspythonProject> python .main2.py .golang.png
The generated results are as follows. It is found that after the text file is opened, there is a lot more color information
Open the text file directly to view, but the original image cannot be seen. You need to view the color effect in the terminal:
It can be seen that the blue information of the original picture is displayed, and two different shades of blue are displayed. Perfect!
The above is the detailed content of Cursor integrated with GPT-4 makes writing code as easy as chatting. A new era of coding in natural language has arrived.. For more information, please follow other related articles on the PHP Chinese website!