But nearly every time I've asked ChatGPT for code, it gives me either plausible-but-wrong code, or total hallucinations (flags and APIs that could exist, but don't).
But nearly every time I've asked ChatGPT for code, it gives me either plausible-but-wrong code, or total hallucinations (flags and APIs that could exist, but don't).
1) GPT4 is a must, the code quality is so much better than GPT3
2) You can use a longer explanation than you think. Be detailed in exactly what you want. Clearly describe function inputs and outputs.
3) Provide GPT3 with the APIs to use, and break these down. If you want it to call an API and do some logic, you can prompt it twice - once to build a function to get data from the API and once to build a function that requests from the function in the first request. Do both of these as separate chat GPT sessions.
4) Give GPT a chance to fix errors - pipe the exact errors back in after you have run them so GPT can amend its code.
5) if you want the code to operate/be written in a particular way then tell GPT and even provide pseudo code if worthwhile. If you want error handling, request it. If you want the SQL statements to be run in a transaction, request it. It probably won’t do these things by default.
6) don’t use even slightly obscure languages.
And when it does go wrong, I've had good success telling it what it did do wrong. It will usually correct itself then.