In some cases, we want to have models that not only handle training and inference, but can also react to events from the platform.
An example might be a model that is used to determine which documents should be inferred in a project for example. These are not traditional models, but are really event handlers that are triggered by events in the platform. To support this, we need to do two things:
- Add a flag to our model metadata to indicate that we want to handle events
- Include a new method that will receive
Setting up a model to handle events
To set up a model to handle events, we need to add a new flag to the model metadata called eventAware
and set it to true
.
slug: my-model
version: 1.0.0
orgSlug: kodexa
type: store
storeType: MODEL
name: My Event Model
metadata:
atomic: true
state: TRAINED
eventAware: true
modelRuntimeRef: kodexa/base-model-runtime
type: model
contents:
- model/*
Then in our model, we must add a new method called handle_event
that will be called by the model runtime when an event is triggered.
def handle_event(event):
logger.info(f"Received event {event}")
← Previous
Next →
On this page