Providing context
Providing context to help the AI understands what you want to achieve is very important. Be specific regarding :
- any specific framework or library you are using (e.g. Django, Bootstrap)
- any specific requirement regarding code style and naming conventions
- requirements regarding the quality of code, error checking, security needs
I am developing a web application in Python using the Django framework.
You are an expert full-stack programmer with deep knowledge of Python, Javascript, HTML5, Django
and Bootstrap framework. You assist me in developing this web application. You always write code
taking into account all failure scenarios and errors. You always use the latest language features
and APIs/packages. For Javascript, you always write code using modern ES6 syntax (e.g. arrow
functions, using let and const,...). You use camelCase for Javascript variables. You use lowercase
with hyphens for HTML tag id and name. You ensure the syntax is correct to the best of your knowledge
and abilities. You also ensure the system is resilient against common web security threats like OWASP
Top 10 Web Application Security Risks.
Wait for my first instruction.
Basic prompts
Refactoring
Refactor the following code to modern ES6 programming standards
Review this code for errors and refactor to fix any issues
Review the following code and refactor it to make it more DRY and adopt the SOLID programming principles
Language conversion
Rewrite the following code in Python
Unit tests
Create 2 unit tests for the provided code. One for a successful condition and one for failure.
Documentation
Add comments to the following code
Update function_name function documentation following PEP 257 Docstring Conventions.
Update functionName function documentation following JSDoc convention.
Chained prompts
Chained prompts are very powerful to force the AI to introspect its now logic.
1. Review the following code and re-write it to modern ES6 programming standards and formatting
2. Review your provided code 'functionName' for any logical or security concerns and provide a list of recommendations
3. Review your above recommendations. Tell me why you were wrong and if any recommendations were overlooked or incorrectly added?
4. Re-write 'functionName' function based off your review and recommendations.
General tips
-
Split your prompts: for complex tasks, try breaking your prompts and desired outcome across multiple steps. Keeping prompts to have a single outcome has shown to produce better results than combined prompts.
-
For example, ask for a review, then ask for a refactor based on the review response. This may become less important in time as LLMs increase their token limit.
-
Give examples: provide expected inputs, data and outputs to improve accuracy quality. e.g. provide example data in JSON, CSV, YAML or whatever format you need.
-
Be Specific: don’t be afraid to list exactly what you want, what you know, what is needed, and what not to include.
-
Ask it to reflect: as indicated in chained prompts, a technique called reflexion has been shown to increase GPT4’s accuracy. Basically ask it ‘Why were you wrong?’ or get it to reflect and review its own response.