自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”

發(fā)布于 2024-8-28 14:35
瀏覽
0收藏

今天,帶大家從另一個角度認識Cursor。Cursor除了產(chǎn)品交互設計充分考慮開發(fā)者習慣,將AI有機的融入到開發(fā)過程外,作為一款大模型驅動的應用,其核心壁壘便是如何利用大模型實現(xiàn)其功能,這時候prompt工程水平高低就變成了壁壘。那么,Cursor的prompt是什么樣的呢?這就引起了很多人的好奇心,有這么一段prompt,據(jù)說是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已經(jīng)很強大了,但網(wǎng)友們還想讓它更強,有網(wǎng)友就建了一個網(wǎng)站(??https://cursor.directory/??),用來分類收集Cursor的提示,據(jù)說這些有針對性的提示會比默認的還好,想要在Cursor中使用它們也很簡單。

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)

具體做法為復制里面的rule文件命名為.cursorrules放置在項目根目錄即可,筆者嘗試了其中幾條,沒看出太大變化(或許我的指令太過簡單),表現(xiàn)都很不錯。(為了驗證其是否真的有效,甚至自己寫了一個很蠢的提示,也能正常生成代碼,如下圖確信配置成功生效了)。

  • 自定義cursorrules:

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)圖片

  • 生效的提示

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)圖片

除此之外,該網(wǎng)站有很多關于Cursor的使用教程,感興趣的可以參考學習。

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)圖片

不管這些和Cursor真實的提示是否一致,都從某個側面反映了Cursor在提示層面擁有獨到之處。早在去年6月,Cursor開發(fā)者Arvid就發(fā)表了一篇有關prompt的文章,他將prompt與網(wǎng)頁設計類比,給出了一個prompt工程的獨特認知和最佳實踐,值得我們借鑒學習。

下面就讓我們一起讀讀這篇文章《Prompt設計》。

我通常不太喜歡用舊世界的事物來類比新世界的現(xiàn)象。不過這次請容許我這么做:我認為應將提示(prompting)稱為提示設計(prompt design),并且可以將其比作網(wǎng)頁設計。

我認為提示就像是在與一個時間有限的人溝通。雖然大語言模型(LLM)的特定技術(例如鏈式思維)確實有其幫助,但我發(fā)現(xiàn),改善性能的最好方法之一是提供非常清晰、高質量的指令,就像清晰簡潔的指令可以幫助人類更好地理解一樣。

將提示視為清晰的交流使提示聽起來像是在寫作。然而,我進行的大部分提示都是參數(shù)化的:有多個輸入變量,并且需要動態(tài)地調(diào)整提示內(nèi)容。因此,將提示視為帶有動態(tài)輸入的清晰交流是最準確的描述。

有哪些領域需要在動態(tài)輸入的情況下進行清晰的交流呢?網(wǎng)頁設計就是其中之一。

讓我們來列舉一下它們的相似之處。提示和網(wǎng)頁設計都具備以下特點:

  • 需要清晰的表達,并且溝通是其主要目標;
  • 需要響應動態(tài)內(nèi)容,不像寫作或雜志排版;
  • 需要將內(nèi)容適應不同的大小——網(wǎng)頁設計中是屏幕大小,提示中是上下文窗口。

根據(jù)我在提示和網(wǎng)頁設計中的經(jīng)驗,我發(fā)現(xiàn)自己在這兩個領域有相似的開發(fā)偏好:

  • 查看實際的提示非常重要,就像查看已渲染的網(wǎng)站一樣重要。如果我必須在腦海中模擬HTML和CSS的渲染過程,我是無法設計網(wǎng)站的。同樣,在不查看所有輸入變量填充后的提示渲染結果的情況下,也很難寫出好的提示。例如,提示“Hiusername{message}”可能看起來合理,但渲染后你會發(fā)現(xiàn)用戶名和消息混在一起。
  • 組合組件在提示和網(wǎng)頁設計中都很有用。
  • 聲明式優(yōu)于命令式。像在網(wǎng)頁設計中,如果所有HTML元素都是用document.createElement調(diào)用創(chuàng)建的,那么修改它就會非常困難。同樣,閱讀和修改由一連串str += "..."組成的提示也很麻煩。
  • 在這兩者中,有時我想要達到“像素完美”。在處理較弱的模型(如GPT-3.5及更早版本)時,我希望沒有多余的換行符或其他不完美的格式;而在設計網(wǎng)站時,有時每個像素都很重要。

對于大語言模型智能體來說,這個類比可以更進一步:智能體提示可以被視為為智能體構建交互式網(wǎng)站,智能體可以通過調(diào)用函數(shù)來“點擊按鈕”,提示會響應函數(shù)調(diào)用重新渲染,就像網(wǎng)站響應按鈕點擊重新渲染一樣。

當然,提示設計和網(wǎng)頁設計之間還是有一些差異的:

  • 提示目前僅涉及文本內(nèi)容。
  • 緩存處理不同:特別是對于智能體,你需要確保重渲染成本低,僅更改提示部分內(nèi)容。這有點類似于網(wǎng)頁緩存優(yōu)化,但本質上是不同的挑戰(zhàn)。

盡管如此,這些相似之處讓我堅信提示應該被稱為提示設計,而不是提示工程。編寫提示感覺就像設計一個網(wǎng)站,因此也應如此命名。

提示設計的理念啟發(fā)了我創(chuàng)建了Priompt,這是一個類似React、基于JSX的提示設計庫。

Priompt v0.1:首次嘗試提示設計庫

Priompt(https://github.com/anysphere/priompt)是受現(xiàn)代網(wǎng)頁設計原則啟發(fā)的提示設計庫的首次嘗試。我們在Anysphere內(nèi)部使用它,感覺非常好。我認為它的所有抽象可能并不完全準確,但至少確信JSX比字符串模板更方便。即使是簡單地能注釋掉部分提示這件事,也能讓迭代過程更快。

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)圖片

What prompting as JSX looks like.

Priompt還附帶一個(匆忙制作的)預覽網(wǎng)站,你可以在上面預覽你的提示在真實數(shù)據(jù)上的效果。在開發(fā)應用程序時,可以記錄每個請求進入組件的序列化屬性(props)。然后,當你看到意外行為時,可以訪問Priompt預覽,查看具體的提示,并更改源代碼,從而更新提示,使其與實際請求的屬性一致。我們發(fā)現(xiàn)這樣更容易進行提示的迭代。

Cursor出彩的背后:“Prompt設計好比網(wǎng)頁設計...”-AI.x社區(qū)圖片

Previewing prompts.

如果你嘗試了,請告訴我你的想法!我愿意看到更多類似的想法,或者直接告訴我我錯了,提示設計是愚蠢的:)

注意事項 模型變化迅速,提示技術也必須隨之變化。我認為提示設計還存在一些問題:

  • 對于GPT-4,像素完美設計并不重要,GPT-4.5及更高版本的模型可能也不需要。
  • 如果長上下文模型發(fā)展的趨勢繼續(xù),上下文窗口限制可能會消失。不過對此我還存疑。
  • OpenAI似乎正在減少開發(fā)者對提示的控制;一年之內(nèi)可能不再需要提示,API調(diào)用僅需要提供原始輸入和指令。更少控制的趨勢始于聊天格式,并隨著最近宣布的函數(shù)調(diào)用繼續(xù)。
  • 緩存可能是提示中最重要的方面之一,在這種情況下,提示會更像工程而不是設計?;蛟S提示設計太基礎了,應該交給更高級的框架或編譯器(如langchain)。我認為這可能是真的,但考慮到大語言模型快速變化的性質,我個人更愿意盡可能靠近原始模型。


原文:https://www.cursor.com/blog/prompt-design#priompt-v01-a-first-attempt-at-a-prompt-design-library

本文轉載自 ??AI工程化??,作者: ully

收藏
回復
舉報
回復
相關推薦