ChatGPT Prompt Engineering for Developers
从Andrew Ng和Isa Fulford的联合课程中学习所获。
更加适合开发者使用,对于目前ChatGPT、Claude这样trained模型,可以不使用特别复杂的prompt校正。
1 Guidelines for Prompting
1.1 Principles of Prompting
Principle 1. Write clear and specific instructions.
clear ≠ \neq =short
-
Use delimiters
- Triple quotes: “”"
- Triple backticks: ```
- Triple dashes: ---
- Angle brackets: <>
- XML tages: <tag></tag>
作用:
- Make it clear t the model that this is a seperate section.
- Avoid prompt injections.
- Ask for structured output
HTML, JSON
- Check whether conditions are satisfied
Check assumptions required to do the task.
- Few-shot prompting
Give successful examples of completing tasks.
Then ask model to perform the task.
Principle 2. Give the model time to think.
- Specify the steps to complete a task
Step 1 - …
Step 2 - …
…
Step N - …
- Instruct the model to work out its own solution before rushing to a conclusion.
1.2 Model Limitations
Hallucination
Makes statements that sound plausible but are not true
Reducing hallucinations:
First find relevant information,
then answer the question based on the relevant information.
2 Iterative Prompt Development
Iterative Process
- Try something
- Analyze where the result does not give what you want
- Clarify instructions, give more time to think
- Refine prompts with a batch of examples
3 Summarizing
4 Inferring
5 Transforming
6 Expanding
Temperature
- Temperature = 0: For tasks that require reliability, predictability
- Temperature = 0.3 (0.7, or even higher): For tasks that require variety
7 Conclusion
Role
messages =
[
{"role": "system"
"content": "You are an assistant… "},
{"role": "user"
"content": "tell me a joke "},
{"role": "assistant"
"content": "Why did the chicken… "},
…
]
- system: Sets behavior of assitant
- assistant: Chat model
- user: You