Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Predibase Lorax Client Init

From Leeroopedia


Knowledge Sources
Domains Client_SDK, Networking
Last Updated 2026-02-08 02:00 GMT

Overview

Concrete tool for establishing HTTP connections to a LoRAX server provided by the Python Client and AsyncClient classes.

Description

The Client class provides synchronous HTTP access to LoRAX using the requests library with session management and retry logic. The AsyncClient class provides asynchronous access using aiohttp with ClientTimeout support. Both configure base URL, headers, cookies, and timeout settings.

Usage

Use Client for synchronous scripts and AsyncClient for async frameworks (FastAPI, aiohttp apps). Initialize with the LoRAX server URL before making any inference calls.

Code Reference

Source Location

  • Repository: LoRAX
  • File: clients/python/lorax/client.py
  • Lines: 62-95 (Client), 610-633 (AsyncClient)

Signature

class Client:
    def __init__(
        self,
        base_url: str,
        headers: Optional[Dict[str, str]] = None,
        cookies: Optional[Dict[str, str]] = None,
        timeout: int = 60,
        session: Optional[requests.Session] = None,
        max_session_retries: int = 2,
    ):
        """
        Args:
            base_url: LoRAX instance base URL
            headers: Additional HTTP headers
            cookies: Cookies for requests
            timeout: Request timeout in seconds (default 60)
            session: Reusable HTTP session
            max_session_retries: Max retries on session errors (default 2)
        """

class AsyncClient:
    def __init__(
        self,
        base_url: str,
        headers: Optional[Dict[str, str]] = None,
        cookies: Optional[Dict[str, str]] = None,
        timeout: int = 60,
    ):

Import

from lorax import Client, AsyncClient

I/O Contract

Inputs

Name Type Required Description
base_url str Yes LoRAX server URL (e.g., "http://localhost:3000")
headers Optional[Dict[str, str]] No Additional HTTP headers
cookies Optional[Dict[str, str]] No Cookies to include
timeout int No Request timeout in seconds (default 60)
session Optional[requests.Session] No Reusable HTTP session (Client only)
max_session_retries int No Max retries (default 2, Client only)

Outputs

Name Type Description
client Client or AsyncClient Initialized client instance ready for inference calls

Usage Examples

Synchronous Client

from lorax import Client

# Connect to local LoRAX server
client = Client("http://localhost:3000")

# With authentication
client = Client(
    "https://lorax.example.com",
    headers={"Authorization": "Bearer my-token"},
    timeout=120,
)

Asynchronous Client

from lorax import AsyncClient

async def main():
    client = AsyncClient("http://localhost:3000", timeout=120)
    response = await client.generate("Hello, world!")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment