-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Add Async Client Variant
Summary
Provide an asynchronous API surface (AsyncLLM) so Relay can integrate cleanly with asyncio applications. Mirror the synchronous client’s ergonomics and ensure providers expose async equivalents of their current methods.
Motivation
- Async frameworks (FastAPI, LangChain integrations, etc.) expect non-blocking I/O.
- Paves the way for concurrent batched requests and streaming without threads.
- Keeps Relay competitive with vendor SDKs that offer async support.
Scope
Core client
- Introduce
relay/async_client.py(or similar) exposingAsyncLLM. - Reuse existing parsing/validation logic; only network calls should differ.
- Consider shared base classes or mixins to avoid duplicating default param handling.
Provider layer
- Define
AsyncBaseProvidermirroringBaseProviderbut withasync def chat(...). - Implement
relay.providers.openai.AsyncOpenAIProviderusinghttpx.AsyncClientoraiohttp. - Decide whether to colocate sync/async providers or split into separate modules for clarity.
Testing
- Add pytest-asyncio to dev dependencies if not already present.
- Cover success and failure flows for async OpenAI interactions using mocked responses.
- Ensure sync tests remain unaffected.
Documentation & Examples
- Add an async usage section to
README.md. - Provide an
examples/openai_async_chat.pyscript demonstratingasyncio.run.
Acceptance Criteria
- Async client can execute chat completions without blocking.
- Unit tests cover async provider behavior, including exception translation.
- Documentation and examples teach developers how to opt into async mode.
- Synchronous APIs continue to operate exactly as before.
References
Metadata
Metadata
Assignees
Labels
No labels