Skip to content

globals

GlobalVars

GlobalVars()

Global variables.

Source code in src/appl/core/globals.py
def __init__(self):
    """Initialize the global variables."""
    self.now = pendulum.instance(datetime.datetime.now())
    self.lock = threading.Lock()
    self.gen_cnt = 0
    self.num_requests = defaultdict(int)
    self.api_cost = defaultdict(float)
    self.func_run_cnt = defaultdict(int)
    self.llm_cache = None
    self.current_func = contextvars.ContextVar("current_func", default=None)
    self.trace_engine = None
    self.resume_trace = None
    self.live = None
    self.live_lock = threading.Lock()
    self._configs = None
    self._metadata = None

configs property writable

configs: APPLConfigs

Get the configs.

metadata property writable

metadata: MetaData

Get the metadata.

get

get(name: str, default: Any = None) -> Any

Get the value of a global variable.

Source code in src/appl/core/globals.py
def get(self, name: str, default: Any = None) -> Any:
    """Get the value of a global variable."""
    with self.lock:
        return getattr(self, name, default)

inc

inc(
    name: str,
    delta: Union[int, float] = 1,
    key: Optional[str] = None,
) -> Any

Increment a global variable by a delta and return the new value.

Source code in src/appl/core/globals.py
def inc(
    self, name: str, delta: Union[int, float] = 1, key: Optional[str] = None
) -> Any:
    """Increment a global variable by a delta and return the new value."""
    with self.lock:
        value = getattr(self, name, 0)
        if isinstance(value, dict) and key is not None:
            value[key] = value.get(key, 0) + delta
            return value[key]
        else:
            if key is not None:
                raise ValueError(
                    f"Cannot increment a non-dict variable {name} with a key"
                )
            value += delta
            setattr(self, name, value)
            return value

set

set(name: str, value: Any) -> None

Set the value of a global variable.

Source code in src/appl/core/globals.py
def set(self, name: str, value: Any) -> None:
    """Set the value of a global variable."""
    with self.lock:
        setattr(self, name, value)

get_thread_local

get_thread_local(name: str, default: Any = None) -> Any

Get the value of a thread-local variable.

Source code in src/appl/core/globals.py
def get_thread_local(name: str, default: Any = None) -> Any:
    """Get the value of a thread-local variable."""
    return getattr(thread_local, name, default)

inc_thread_local

inc_thread_local(
    name: str, delta: Union[int, float] = 1
) -> Any

Increment a thread-local variable by a delta and return the new value.

Source code in src/appl/core/globals.py
def inc_thread_local(name: str, delta: Union[int, float] = 1) -> Any:
    """Increment a thread-local variable by a delta and return the new value."""
    value = get_thread_local(name, 0)
    value += delta
    setattr(thread_local, name, value)
    return value

set_thread_local

set_thread_local(name: str, value: Any) -> None

Set the value of a thread-local variable.

Source code in src/appl/core/globals.py
def set_thread_local(name: str, value: Any) -> None:
    """Set the value of a thread-local variable."""
    setattr(thread_local, name, value)