Skip to content

Context

ContextProvider

ContextProvider()

A class that provides a context store.

Source code in src/refiners/fluxion/context.py
def __init__(self) -> None:
    """Initializes the ContextProvider."""
    self.contexts: Contexts = {}

create staticmethod

create(contexts: Contexts) -> ContextProvider

Create a ContextProvider from a dict of contexts.

Parameters:

Name Type Description Default
contexts Contexts

The contexts.

required

Returns:

Type Description
ContextProvider

A ContextProvider with the contexts.

Source code in src/refiners/fluxion/context.py
@staticmethod
def create(contexts: Contexts) -> "ContextProvider":
    """Create a ContextProvider from a dict of contexts.

    Args:
        contexts: The contexts.

    Returns:
        A ContextProvider with the contexts.
    """
    provider = ContextProvider()
    provider.update_contexts(contexts)
    return provider

get_context

get_context(key: str) -> Any

Retrieve a value from the context.

Parameters:

Name Type Description Default
key str

The key of the context.

required

Returns:

Type Description
Any

The context value.

Source code in src/refiners/fluxion/context.py
def get_context(self, key: str) -> Any:
    """Retrieve a value from the context.

    Args:
        key: The key of the context.

    Returns:
        The context value.
    """
    return self.contexts.get(key)

set_context

set_context(key: str, value: Context) -> None

Store a value in the context.

Parameters:

Name Type Description Default
key str

The key of the context.

required
value Context

The context.

required
Source code in src/refiners/fluxion/context.py
def set_context(self, key: str, value: Context) -> None:
    """Store a value in the context.

    Args:
        key: The key of the context.
        value: The context.
    """
    self.contexts[key] = value

update_contexts

update_contexts(new_contexts: Contexts) -> None

Update or set the contexts with new contexts.

Parameters:

Name Type Description Default
new_contexts Contexts

The new contexts.

required
Source code in src/refiners/fluxion/context.py
def update_contexts(self, new_contexts: Contexts) -> None:
    """Update or set the contexts with new contexts.

    Args:
        new_contexts: The new contexts.
    """
    for key, value in new_contexts.items():
        if key not in self.contexts:
            self.contexts[key] = value
        else:
            self.contexts[key].update(value)