Save time prompting ChatGPT by spending a bit more time upfront writing a comprehensive prompt to help it understand what you need.
These are my ✨ 3 Top Tips ✨
1. Provide context
Paste in other parts of your code that are relevant and explain why you need an answer – “What problem am I trying to solve?”
2. Give expected input and output examples
Use a wide variety of examples to show ChatGPT what data is fixed vs variable. The more you provide the more accurate the answer will be. Describe what format the expected output is in, like a list, object or array.
3. Map the function flow
If you’re asking for a written function, plan how you want it to work. You’ll know best how it’s going to integrate with your system and what it needs to consider. Give ChatGPT some steps to follow.
Here’s what I did
Below is a recent example of prompting ChatGTP using these three top tips:
This is my 'splitTyreSize' function in my WordPress functions.php file: <PHP FUNCTION HERE> It takes an input string and outputs an array with 3 values. The second value may be missing from the string so we replace it with N/A. The third value should always start with an ‘R’. Any value may be a floating point number. These are example inputs and expected outputs: 145/65R15 = [145, 65, R15] 145/70R13 = [145, 70, R13] 145R10 = [145, N/A, R10] 30X9.50R15 = [30, 9.50, R15] 31X10.50-16 = [31, 10.50, R16] 24X12.50-13 = [24, 12.50, R13] 24X4.83R20 = [24, 4.83, R20] 145X17-16 = [145, 17, R16] 38.5X12.50-16 = [38.5, 12.50, R16] 30-9.5R15 = [30. 9.5, R15] 155R13C = [155, N/A, R13C] Please update the function to handle all of these types of inputs. Follow these steps: Check for a delimiter in this order: ‘/’, ‘X’, ‘-’, ‘R’ If an R was found first, then it means the second value is missing and should be ’N/A’. The first value is whatever comes before the R. If an R was not found first, then there are 3 values. The first value is whatever comes before the delimiter. To determine the second and third values, either an ‘R’ or ‘-’ separates them.
This prompt gave me 95% of what I needed, after one more prompt the job was done. By spending a bit more time upfront I saved a lot of back-and-forth between the browser, code, and testing.