๐๐ ๐ฃ๐ฅ๐ข๐ฉ๐๐ก๐ ๐๐ ๐๐ข๐๐ ๐๐๐ก๐๐ฅ๐๐ง๐๐ข๐ก I built a dozen API endpoints for a new microservice last month. I knew the patterns, but typing out all that boilerplate felt soul-crushing. I turned to AI, hoping it would save me hours. What followed was a rollercoaster of bad outputs and frustration. But after a week of failed attempts, I found a prompting approach that actually produced reliable code.
Here's what worked for me:
- Provide explicit input/output format
- Give few-shot examples
- Set the role with a system message
I built a prompt generator in Python. It takes a schema description and produces a prompt with examples. The key was to treat the AI like a diligent intern who needs detailed instructions.
What I learned:
- You still need to review everything
- Few-shot works best for repetitive patterns
- Temperature matters
- Context length is a limit
- It's not free
When to avoid AI code generation:
- When security is critical
- When you need to adhere to a very specific code style
- When the pattern is trivial
What works for you? Do you rely on prompts or have you built a custom tool around AI-generated code? Source: https://dev.to/__c1b9e06dc90a7e0a676b/i-struggled-to-get-ai-to-write-useful-code-heres-what-finally-worked-432c