本文最后更新于:2024年1月14日 晚上

编辑器 Cursor 集成了openai的GPT-4,而且还是免费的,本文记录使用方法和示例。

简介

自从 OpenAI 推出了 ChatGPT 系列语言模型,技术和知识的门槛不断降低,未来人们的生活和工作方式也很可能发生重要转变。

现在又一个工具出现,一个叫Cursor的编辑器已经集成了openai的GPT-4,而且还是免费的,它将彻底改变我们写代码的方式。 可以根据需求直接写出代码,可以修校 bug,可以写注释,可以提问题 ……

使用方法

下载安装

Cursor 编辑器提供了Windows、MacOS、Linux 三个平台的安装包, 可以从官方直接下载:

官网链接:https://www.cursor.so/

下载后直接安装即可。

启动 Cursor

下载安装完成后,会引导你进行初始化设置,你即可以选择VIM或者Emacs的操作习惯,也可以保持默认设置,另外它还支持绑定Copilot。

使用方法

Cursor 是一个极简的编辑器,集成了编程支持的 ChatGPT4,核心命令只有两个 Generate / EditChat,分别表示生成代码和聊天,快捷键分别为 CTRL+KCTRL+L

Edit / CTRL+K

代码编辑/生成功能快捷键是 CTRL+K,可以直接描述需求,中英文皆可

初始给出的代码有 bug,让他修也没有修好,我添加了两行初始化的代码能跑了

ChatGPT 遗漏的代码,很简单的问题

1
2
snake_x_change = 0
snake_y_change = 0

修改后的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Python 贪食蛇
import pygame
import random

# 初始化 Pygame
pygame.init()

# 设置窗口大小
window_width = 800
window_height = 600
window = pygame.display.set_mode((window_width, window_height))

# 设置游戏标题
pygame.display.set_caption('Python 贪食蛇')

# 定义颜色
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
green = (0, 255, 0)

# 定义蛇的初始位置和大小
snake_block_size = 10
snake_speed = 15
snake_list = []
snake_length = 1
snake_x = window_width / 2
snake_y = window_height / 2
snake_x_change = 0
snake_y_change = 0

# 定义食物的初始位置和大小
food_block_size = 10
food_x = round(random.randrange(0, window_width - food_block_size) / 10.0) * 10.0
food_y = round(random.randrange(0, window_height - food_block_size) / 10.0) * 10.0

# 定义字体
font_style = pygame.font.SysFont(None, 30)

# 定义分数
def score(score):
value = font_style.render('Score: ' + str(score), True, black)
window.blit(value, [0, 0])

# 定义蛇的形状
def draw_snake(snake_block_size, snake_list):
for x in snake_list:
pygame.draw.rect(window, green, [x[0], x[1], snake_block_size, snake_block_size])

# 显示消息
def message(msg, color):
mesg = font_style.render(msg, True, color)
window.blit(mesg, [window_width / 6, window_height / 3])

# 游戏循环
game_over = False
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True

# 定义蛇的移动
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
snake_x_change = -snake_block_size
snake_y_change = 0
elif event.key == pygame.K_RIGHT:
snake_x_change = snake_block_size
snake_y_change = 0
elif event.key == pygame.K_UP:
snake_y_change = -snake_block_size
snake_x_change = 0
elif event.key == pygame.K_DOWN:
snake_y_change = snake_block_size
snake_x_change = 0
# 判断蛇是否撞到边界
if snake_x >= window_width or snake_x < 0 or snake_y >= window_height or snake_y < 0:
game_over = True

# 移动蛇的位置
snake_x += snake_x_change
snake_y += snake_y_change

# 绘制背景
window.fill(white)

# 绘制食物
pygame.draw.rect(window, red, [food_x, food_y, food_block_size, food_block_size])

# 绘制蛇
snake_head = []
snake_head.append(snake_x)
snake_head.append(snake_y)
snake_list.append(snake_head)
if len(snake_list) > snake_length:
del snake_list[0]

for x in snake_list[:-1]:
if x == snake_head:
game_over = True

draw_snake(snake_block_size, snake_list)
score(snake_length - 1)

pygame.display.update()

# 判断蛇是否吃到食物
if snake_x == food_x and snake_y == food_y:
food_x = round(random.randrange(0, window_width - food_block_size) / 10.0) * 10.0
food_y = round(random.randrange(0, window_height - food_block_size) / 10.0) * 10.0
snake_length += 1

# 刷新屏幕
pygame.display.update()

# 设置游戏速度
clock = pygame.time.Clock()
clock.tick(snake_speed)

# 退出 Pygame
pygame.quit()

# 退出程序
quit()

放到 Python 中运行效果

Chat / CTRL+L

可以聊天,提问题

新时代已经到来了 …

参考资料



文章链接:
https://www.zywvvd.com/notes/tools/cursor/cursor-gpt4/cursor-gpt4/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

集成 GPT-4 的编辑器 Cursor
https://www.zywvvd.com/notes/tools/cursor/cursor-gpt4/cursor-gpt4/
作者
Yiwei Zhang
发布于
2023年3月23日
许可协议