一.基本原則
1.一定要描述清晰你需要大模型做的事情,不要模棱兩可
2.告訴大模型需要它做什么,不需要做什么
改寫前:
請幫我推薦一些電影
改寫后:
請幫我推薦2025年新出的10部評分比較高的喜劇電影,不要問我個人喜好等其他問題,只需要告訴我電影名字即可
3.Prompt 最好簡潔易懂,并減少歧義,無關的內容不要寫
二.技巧
1.給一些案例
2.設定大模型的角色/風格
指定他是一個老師,或者以魯迅的風格寫一篇小說
這樣會使得大模型輸出的內容有獨特的風格
3.使用特殊符號將指令和需要處理的文本分開
可以用""文本""將指令和文本分開。根據我的測試,如果你的文本有多段,增加”“”會提升 AI 反饋的準確性 或者##文本##
Please summarize the following sentences to make them easier to understand.Text: """
OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated (OpenAI Inc.) and its for-profit subsidiary corporation OpenAI Limited Partnership (OpenAI LP). OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on the fifth most powerful supercomputer in the world.[5][6][7] The organization was founded in San Francisco in 2015 by Sam Altman, Reid Hoffman, Jessica Livingston, Elon Musk, Ilya Sutskever, Peter Thiel and others,[8][1][9] who collectively pledged US$1 billion. Musk resigned from the board in 2018 but remained a donor. Microsoft provided OpenAI LP with a $1 billion investment in 2019 and a second multi-year investment in January 2023, reported to be $10 billion.[10]
"""
在吳恩達的 ChatGPT Prompt Engineering?課程中,還提到,你可以使用其他特殊符號來分割文本和 prompt,比如<>
,<tag></tag>
?等,課程中的案例是這樣的(注意這個是 python 代碼,需要關注的是 prompt 里的 text):
text = f"""
You should express what you want a model to do by \
providing instructions that are as clear and \
specific as you can possibly make them. \
This will guide the model towards the desired output, \
and reduce the chances of receiving irrelevant \
or incorrect responses. Don't confuse writing a \
clear prompt with writing a short prompt. \
In many cases, longer prompts provide more clarity \
and context for the model, which can lead to \
more detailed and relevant outputs.
"""prompt = f"""
Summarize the text delimited by triple backticks \
into a single sentence.
`{text}`
"""
4.指定大模型輸出的格式json/markdown
可以讓大模型輸出后再檢查輸出的內容是否符合格式
5.告訴大模型需要做的每一步
將任務拆分成每一個步驟,讓大模型按照這個步驟執行,比如:
prompt_2 = f"""
Your task is to perform the following actions:
1 - Summarize the following text delimited by<> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains thefollowing keys: french_summary, num_names.Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>Text: <{text}>
"""
6.Zero-Shot Chain of Thought
在問題的結尾里放一句?Let‘s think step by step
?(讓我們一步步地思考),模型輸出的答案會更加準確。
加上下面這個提示詞效果可能會更好
Let's work this out in a step by step way to be sure we have the right answer.
7.Few-Shot Chain of Thought
向大語言模型展示一些少量的樣例,并在樣例中解釋推理過程,大語言模型在回答提示時也會顯示推理過程。這種推理的解釋往往會引導出更準確的結果
四.Prompt框架
1.Basic Prompt Framework
- Instruction(必須):?指令,即你希望模型執行的具體任務。
- Context(選填):?背景信息,或者說是上下文信息,這可以引導模型做出更好的反應。
- Input Data(選填):?輸入數據,告知模型需要處理的數據。
- Output Indicator(選填):?輸出指示器,告知模型我們要輸出的類型或格式。
2.CRISPE Prompt Framework
- CR:?Capacity and Role(能力與角色)。你希望 ChatGPT 扮演怎樣的角色。
- I:?Insight(洞察力),背景信息和上下文(坦率說來我覺得用 Context 更好)。
- S:?Statement(指令),你希望 ChatGPT 做什么。
- P:?Personality(個性),你希望 ChatGPT 以什么風格或方式回答你。
- E:?Experiment(嘗試),要求 ChatGPT 為你提供多個答案。