Skip to content

Index

cam

The cam memory backend: a client for the separate CAM program over HTTP.

Classes

CamBackend

CamBackend(config)

memory-backend/1.1 over CAM's HTTP API (declare, recall, health).

Source code in src/marianne/memory/backends/cam/backend.py
def __init__(self, config: CamBackendConfig) -> None:
    self._cfg = config
    parts = urllib.parse.urlsplit(config.base_url)
    self._https = parts.scheme == "https"
    self._host = parts.hostname or ""
    self._port = parts.port
    self._prefix = parts.path.rstrip("/")

CamBackendConfig dataclass

CamBackendConfig(base_url, api_key_env='', api_key_file='', timeout_seconds=DEFAULT_TIMEOUT_SECONDS, allow_remote=False)

One CAM attachment. Holds the NAME of the key source, never the key.

Functions:

cam_backend_factory

cam_backend_factory(settings)

Build a :class:CamBackend from an attachment's settings:. Does no I/O.

Keys: base_url (required), api_key_env | api_key_file (exactly one; the NAME of a variable or a path, never the key), timeout_seconds, allow_remote.

Source code in src/marianne/memory/backends/cam/backend.py
def cam_backend_factory(settings: Mapping[str, Any]) -> CamBackend:
    """Build a :class:`CamBackend` from an attachment's ``settings:``. Does no I/O.

    Keys: ``base_url`` (required), ``api_key_env`` | ``api_key_file`` (exactly
    one; the NAME of a variable or a path, never the key), ``timeout_seconds``,
    ``allow_remote``.
    """
    allowed = {"base_url", "api_key_env", "api_key_file", "timeout_seconds", "allow_remote"}
    unknown = sorted(set(settings) - allowed)
    if unknown:
        raise _config_error(f"unknown cam setting(s) {unknown}; legal: {sorted(allowed)}")
    if not isinstance(settings.get("base_url"), str):
        raise _config_error("cam settings need base_url")
    for name in ("api_key_env", "api_key_file"):
        if name in settings and not isinstance(settings[name], str):
            raise _config_error(f"{name} must be a string")
    if "allow_remote" in settings and not isinstance(settings["allow_remote"], bool):
        raise _config_error("allow_remote must be true or false")
    return CamBackend(CamBackendConfig(
        base_url=settings["base_url"],
        api_key_env=settings.get("api_key_env", ""),
        api_key_file=settings.get("api_key_file", ""),
        timeout_seconds=settings.get("timeout_seconds", DEFAULT_TIMEOUT_SECONDS),
        allow_remote=settings.get("allow_remote", False),
    ))