Today I learned the course of Claude Prompt Engineering on Github
This is my fork and python notebook : https://github.com/khanhicetea/prompt-eng-interactive-tutorial
Main ideas I learned for the courses
- Be Clear and Direct : system prompt (instruct AI how to behave) > user prompt (asking 5W for answer)
- Role Acting : change role => change POV of AI => change how it read the question => change how it think and calculate the prob to answer
- Separating Data and Instructions : Instruction like a barebone to filling data (so put data in xml tag with semantic tag name making good structure of prompts)
- Formating output, prefill : instruct AI to put desired answer data into a specified xml - json, or prefill seeding answer (feed the prefix answer to let it continue)
- Precognition : "Thinks only counts when it's out loud." => Instruct it write its thinking in a format step-by-step, then answer the conclusion (because LLM works by calculate next tokens by previous token so no previous tokens mean no thinking - no data). Btw, the ordering is matter (GOOD -> BAD = BAD ; BAD -> GOOD = GOOD), the later is matter.
- Few shots prompting : shots mean examples of question - answer pair, it provide context, how to answer, how to act, how to deal edge-cases by examples
- Avoid hallucinations : Give it an out (instruct AI how to behave when its data can fulfill the answer by denying reply) + Guide AI write out the quotes from long documents for evidences first the try to answer based on these evidences
- Complex prompting : Give AI a good structure about these components
- Task Context : Role + Goal (must have)
- Tone Context : AI tone when answer (optional)
- Task Description : Rules to follow (do + don't) + Outer way (out of scope)
- Examples : more examples more edge-cases (optional but should have)
- Input Data : additional data - user files, web search, documents, RAG (optional)
- Intermidate Task : user question, what to do (must have)
- Precognition : guide it thinking, step-by-step, make whiteboard, make scratchpad for complex tasks (thinking out loud)
- Output Formatting : how AI answer formating text (optional - should have)
- Prefill - talk for AI (should have)
Quote of the day
Thinks only counts when it's out loud.