Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

1.1 KB
Raw Blame
import json
from dataclasses import dataclass
from typing import Final

from typing_extensions import LiteralString


@dataclass
class SettingsDatabase:
    """In-memory ``LiteLLM_Config`` holding the telemetry instance id, hash secret and stored groups"""

    stored_groups: str | None = None
    fail_reads: bool = False
    instance_id: str = "persisted-install"
    hash_secret: str = "persisted-secret"
    inserted: tuple[str, ...] = ()

    async def query_raw(self, query: LiteralString, *args: object) -> object:
        if self.fail_reads:
            raise OSError("db down")
        if "AS value" in query:
            return ({"value": self.instance_id if args[0] == "telemetry_instance_id" else self.hash_secret},)
        stored: Final = self.stored_groups
        return () if stored is None else ({"param_value": json.loads(stored)},)

    async def execute_raw(self, query: LiteralString, *args: object) -> int:
        self.inserted = (*self.inserted, str(args[0]) if args else "")
        if args and args[0] == "telemetry_settings":
            self.stored_groups = str(args[1])
        return 1