I'm integrating several language model providers and finding their SDK examples and formatting inconsistent. I'm using asyncio for calls, but I'm not sure how to structure the provider-specific code or handle punctuation differences in the output.
How do you keep formatting and SDK differences manageable across LLM providers?
Answers
A small wrapper for each provider can keep the rest of your code from knowing which SDK it's calling. Give each wrapper the same method and return shape, then translate provider-specific requests and responses inside it.
Keep the interface focused on what your app actually needs. For example, return the generated text and any error information you use, rather than trying to make every provider feature look identical.
Reply to this answer
Asyncio helps when you want to run independent requests concurrently, but it won't make the SDK interfaces consistent by itself. I'd separate concurrency from the provider adapters so you can change one without rewriting the other.
Check whether each SDK method you're using is actually asynchronous. A synchronous call inside an async function can still block the event loop.
Reply to this answer
Are the punctuation problems in the generated text, or in the SDK documentation? Those need different fixes. A wrapper helps with inconsistent code interfaces, but it won't necessarily change how a model writes.
For output style, try giving each model the same explicit formatting instructions and compare the results. If you add cleanup afterward, be careful not to alter punctuation that matters in code or quoted text.
Reply to this answer
Consistent names and short docstrings go a long way here. Document what your own methods accept and return, including any provider-specific limitations, so you don't have to keep mentally translating between examples.
Reply to this answer
Add your answer
Answers are reviewed before publication.
5r~signalnotch_294:
That sounds more manageable than having SDK-specific calls scattered through the app. I'll try starting with the text response.