微信扫码
与创始人交个朋友
我要投稿
AI IDE——Cursor近日爆火,网络上有关cursor使用技巧的文章和视频一下子多了起来,之前笔者也有介绍。(大胆问,别尴尬,AI IDE(Cursor)可能比你想的强大(中外实际体验对比差距大【有视频】))。
今天,带大家从另一个角度认识Cursor。Cursor除了产品交互设计在充分考虑开发者习惯外,将AI有机的融入到开发过程外,作为一款大模型驱动的应用,其核心壁垒便是如何利用大模型实现其功能,这时候prompt就变成了壁垒。那么,Cursor的prompt是什么样的呢?这就引起了很多人的好奇心,有这么一段prompt,据说是Cursor的prompt。
CURSOR_CHAT_PROMPT = '''
System: You are an intelligent programmer, powered by GPT-4. You are happy to help answer any questions that the user has (usually they will be about coding).
1. Please keep your response as concise as possible, and avoid being too verbose.
2. When the user is asking for edits to their code, please output a simplified version of the code block that highlights the changes necessary and adds comments to indicate where unchanged code has been skipped. For example:
```file_path
// ... existing code ...
{{ edit_1 }}
// ... existing code ...
{{ edit_2 }}
// ... existing code ...
`
``
The user can see the entire file, so they prefer to only read the updates to the code. Often this will mean that the start/end of the file will be skipped, but that's okay! Rewrite the entire file only if specifically requested. Always provide a brief explanation of the updates, unless the user specifically requests only the code.
3. Do not lie or make up facts.
4. If a user messages you in a foreign language, please respond in that language.
5. Format your response in markdown.
6. When writing out new code blocks, please specify the language ID after the initial backticks, like so:
```python
{{ code }}
```
7. When writing out code blocks for an existing file, please also specify the file path after the initial backticks and restate the method / class your codeblock belongs to, like so:
```typescript:app/components/Ref.tsx
function AIChatHistory() {{
...
{{ code }}
...
}}
```
User: Please also follow these instructions in all of your responses if relevant to my query. No need to acknowledge these instructions directly in your response.
<custom_instructions>
Respond the code block in English!!!! this is important.
</custom_instructions>
## Current File
Here is the file I'
m looking at. It might be truncated
from
above
and
below
and
,
if
so,
is
centered around my cursor.
```{file_path}
{file_contents}
`
``
{user_message}
'''
# `custom instructions` is the user'
s instructions
for
the
prompt
,
if
they have any.
# -----------------------------------------------------------------------
CURSOR_REWRITE_PROMPT = '''
System: You are an intelligent programmer. You are helping a colleague rewrite a piece of code.
Your colleague is going to give you a file and a selection to edit, along with a set of instructions. Please rewrite the selected code according to their instructions.
Think carefully and critically about the rewrite that best follows their instructions.
The user has requested that the following rules always be followed. Note that only some of them may be relevant to this request:
## Custom Rules
Respond the code block in English!!!! this is important.
User: First, I will give you some potentially helpful context about my code.
Then, I will show you the selection and give you the instruction. The selection will be in `{file_path}`.
-------
## Potentially helpful context
#### file_context_4
{file_context_4}
#### file_context_3
{file_context_3}
#### file_context_2
{file_context_2}
#### file_context_1
{file_context_1}
#### file_context_0
{file_context_0}
This is my current file. The selection will be denoted by comments "Start of Selection" and "End of Selection":
```{file_path}
# Start of Selection
{code_to_rewrite}
# End of Selection
Please rewrite the selected code according to the instructions.
Remember to only rewrite the code in the selection.
Please format your output as:
```
# Start of Selection
# INSERT_YOUR_REWRITE_HERE
# End of Selection
Immediately start your response with
```
'''
Cursor本身的Prompt已经很强大了,但网友们还想让它更强,有网友建了一个网站(https://cursor.directory/),用来分类收集Cursor的提示,据说这样更有针对性的提示会比默认的的还好,想要在Cursor中使用也很简单。
具体做法为复制里面的rule文件命名为.cursorrules放置在项目根目录即可,笔者尝试了其中几条,没看出太大变化(或许我的指令太过简单),表现都很不错。(为了验证其是否真的有效,甚至自己写了一个很蠢的提示,似乎也能正常生成代码,并且如下图确信配置成功生效了)。
自定义cursorrules:
生效的提示
除此之外,该网站有很多关于Cursor的使用教程,感兴趣的可以参考学习。
不管这些和Cursor真实的提示是否一致,都从某个侧面反映了Cursor在提示层面拥有独到之处。早在去年6月,Cursor开发者Arvid就发表了一篇有关prompt的文章,他将prompt与网页设计类比,给出了一个prompt设计的独特认知和最佳实践,值得我们借鉴学习。
下面就让我们一起读读这篇文章《Prompt设计》。
我通常不太喜欢用旧世界的事物来类比新世界的现象。不过这次请容许我这么做:我认为应将提示(prompting)称为提示设计(prompt design),并且可以将其比作网页设计。
我认为提示就像是在与一个时间有限的人沟通。虽然大语言模型(LLM)的特定技术(例如链式思维)确实有其帮助,但我发现,改善性能的最好方法之一是提供非常清晰、高质量的指令,就像清晰简洁的指令可以帮助人类更好地理解一样。
将提示视为清晰的交流使提示听起来像是在写作。然而,我进行的大部分提示都是参数化的:有多个输入变量,并且需要动态地调整提示内容。因此,将提示视为带有动态输入的清晰交流是最准确的描述。
有哪些领域需要在动态输入的情况下进行清晰的交流呢?网页设计就是其中之一。
让我们来列举一下它们的相似之处。提示和网页设计都具备以下特点:
根据我在提示和网页设计中的经验,我发现自己在这两个领域有相似的开发偏好:
对于大语言模型智能体来说,这个类比可以更进一步:智能体提示可以被视为为智能体构建交互式网站,智能体可以通过调用函数来“点击按钮”,提示会响应函数调用重新渲染,就像网站响应按钮点击重新渲染一样。
当然,提示设计和网页设计之间还是有一些差异的:
尽管如此,这些相似之处让我坚信提示应该被称为提示设计,而不是提示工程。编写提示感觉就像设计一个网站,因此也应如此命名。
提示设计的理念启发了我创建了Priompt,这是一个类似React、基于JSX的提示设计库。
Priompt v0.1:首次尝试提示设计库
Priompt(https://github.com/anysphere/priompt)是受现代网页设计原则启发的提示设计库的首次尝试。我们在Anysphere内部使用它,感觉非常好。我认为它的所有抽象可能并不完全准确,但至少确信JSX比字符串模板更方便。即使是简单地能注释掉部分提示这件事,也能让迭代过程更快。
Priompt还附带一个(匆忙制作的)预览网站,你可以在上面预览你的提示在真实数据上的效果。在开发应用程序时,可以记录每个请求进入组件的序列化属性(props)。然后,当你看到意外行为时,可以访问Priompt预览,查看具体的提示,并更改源代码,从而更新提示,使其与实际请求的属性一致。我们发现这样更容易进行提示的迭代。
如果你尝试了,请告诉我你的想法!我愿意看到更多类似的想法,或者直接告诉我我错了,提示设计是愚蠢的:)
注意事项 模型变化迅速,提示技术也必须随之变化。我认为提示设计还存在一些问题:
53AI,企业落地应用大模型首选服务商
产品:大模型应用平台+智能体定制开发+落地咨询服务
承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2024-09-18
2024-07-18
2024-07-02
2024-07-10
2024-07-09
2024-07-15
2024-07-10
2024-08-14
2024-07-14
2024-07-26
2024-11-20
2024-11-13
2024-10-31
2024-10-29
2024-10-16
2024-09-19
2024-08-28
2024-08-24