๐ช๐ต๐ ๐ ๐ฆ๐๐ผ๐ฝ๐ฝ๐ฒ๐ฑ ๐๐ฎ๐ฟ๐ฑ๐ฐ๐ผ๐ฑ๐ถ๐ป๐ด ๐๐ ๐๐ฃ๐ ๐๐ฎ๐น๐น๐
It was 11 PM. I built a tool for developers. OpenAI worked. Then a client asked for Claude.
My code had one function. It called OpenAI directly. To add Claude, I had to copy and paste. This created bad code.
I used if-else blocks first. It worked for two providers. The third provider broke everything. The code became a mess.
I built a simple interface. Now the app asks for a prompt. It does not care which AI answers.
Here is the logic:
- Create a base class for all providers.
- Build separate classes for OpenAI and Claude.
- Use a client to call the interface.
- Use a config file to switch providers.
This approach has limits:
- Do not do this for one provider.
- Unique AI features get hidden.
- Errors vary by provider.
Start simple. Write one provider. Refactor when you need a second one.
How do you handle multiple AI providers? Do you use tools or build your own?