[docs]class Event(Generic[TSelected], ABC):
    inputs: Dict[str, Any]
    selected: Optional[TSelected]
[docs]    def __init__(self, inputs: Dict[str, Any], selected: Optional[TSelected] = None):
        self.inputs = inputs
        self.selected = selected
TEvent = TypeVar("TEvent", bound=Event)
[docs]class Policy(Generic[TEvent], ABC):
[docs]    def __init__(self, **kwargs: Any):
        pass
[docs]    @abstractmethod
    def predict(self, event: TEvent) -> Any:
        ...
[docs]    @abstractmethod
    def learn(self, event: TEvent) -> None:
        ...
[docs]    @abstractmethod
    def log(self, event: TEvent) -> None:
        ...
[docs]    def save(self) -> None:
        pass
[docs]class VwPolicy(Policy):
[docs]    def __init__(
        self,
        model_repo: ModelRepository,
        vw_cmd: List[str],
        feature_embedder: Embedder,
        vw_logger: VwLogger,
        *args: Any,
        **kwargs: Any,
    ):
        super().__init__(*args, **kwargs)
        self.model_repo = model_repo
        self.workspace = self.model_repo.load(vw_cmd)
        self.feature_embedder = feature_embedder
        self.vw_logger = vw_logger
[docs]    def predict(self, event: TEvent) -> Any:
        import vowpal_wabbit_next as vw
        text_parser = vw.TextFormatParser(self.workspace)
        return self.workspace.predict_one(
            parse_lines(text_parser, self.feature_embedder.format(event))
        )