如何写OpenAI Chat的prompt第一个技巧:表达

原则(一):写清楚和具体的说明

策略1、使用分隔符明确指出输入的不同部分
分隔符可以使用这样的:"""、```、---、<>、<tag></tag>
""":text delimited by triple quotes
```:text delimited by tripole backticks
---:text delimited by triple dashes
<>:text delimited by angle brackets
<tag></tag>:xml tags

例子:
summarize the text delimited by tripole backticks into a single sentence.translate to Chinese.
```您应该通过提供尽可能清晰和具体的说明来表达您希望模型执行的操作。
这将引导模型获得所需的输出,并减少收到不相关或不正确响应的机会。
不要将清晰的提示与简短的提示混淆。
在许多情况下,更长的提示可以为模型提供更多的清晰度和上下文,这可以导致更详细和相关的输出。```

策略2、要求结构化输出,指定输出格式
比如:JSON,HTML

例子:
生成三个虚构的书名及其作者和类型的列表
使用以下键以 JSON 格式提供它们:
book_id, title, author, genre.

策略3、要求模型检查条件是否满足(检查完成任务所需的假设)

例子:You will be provided with text delimited by triple quotes. If it contains a sequence of instructions, re-write those instructions in the following format:
Step 1 - ...
Step 2 - …

Step N - …
If the text does not contain a sequence of instructions, then simply write "No steps provided."
"""Making a cup of tea is easy! First, you need to get some water boiling. While that's happening, grab a cup and put a tea bag in it. Once the water is hot enough, just pour it over the tea bag. Let it sit for a bit so the tea can steep. After a few minutes, take out the tea bag. If you like, you can add some sugar or milk to taste. And that's it! You've got yourself a delicious cup of tea to enjoy."""

策略 4、“少量”提示,让AI取一反三(举出完成任务的成功例子,然后要求模型执行任务)

例子:
Your task is to answer in a consistent style.

<child>: 教我耐心。
<grandparent>: 雕刻最深山谷的河流来自一个谦虚的泉水; 最伟大的交响乐源于一个音符; 最复杂的挂毯始于一根单独的线。

<child>: 教我韧性。

原则(二):给模型时间“思考”
策略 1:指定完成任务所需的步骤
例子:
Perform the following actions:
1 - Summarize the following text delimited by triple backticks with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the following keys: french_summary, num_names.
Separate your answers with line breaks.
Text:
```In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck—Jack tripped on a stone and tumbled down the hill, with Jill following suit. Though slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight.```

请求指定格式的输出
例子:
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 the
following 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:
```In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck—Jack tripped on a stone and tumbled down the hill, with Jill following suit. Though slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight.```