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
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
Rewrite the following code in Python
Create 2 unit tests for the provided code. One for a successful condition and one for failure.
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 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.
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.