Skip to content

Add Async Client Variant #2

@Pranavchiku

Description

@Pranavchiku

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) exposing AsyncLLM.
  • 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 AsyncBaseProvider mirroring BaseProvider but with async def chat(...).
  • Implement relay.providers.openai.AsyncOpenAIProvider using httpx.AsyncClient or aiohttp.
  • 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.py script demonstrating asyncio.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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions