You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use cel-cpp to write some rules for trigger the action when some condition matched. For some sophisticated rules,we need use some user-defined macros or functions, for example: compute the 3D IOU for two 3D objects(proto message), compute the included angle of two 3D vector and so on.
After search the codebase, we can not find examples about how to add user-defined macros or functions in cel-cpp.
The text was updated successfully, but these errors were encountered:
// Custom function to compute 3D IOU
cel::Status Compute3DIoU(cel::CelValue* result, const std::vectorcel::CelValue& args) {
// Implement the logic to compute 3D IOU
return cel::Status::OK;
}
// Custom function to compute included angle of two 3D vectors
cel::Status ComputeIncludedAngle(cel::CelValue* result, const std::vectorcel::CelValue& args) {
// Implement the logic to compute included angle
return cel::Status::OK;
}
int main() {
// Create a CEL function registry
auto registry = std::make_sharedcel::Registry();
// Register custom functions with the registry
registry->RegisterFunction("Compute3DIoU", Compute3DIoU);
registry->RegisterFunction("ComputeIncludedAngle", ComputeIncludedAngle);
// Create a CEL evaluator with custom function registry
cel::InterpreterOptions options;
options.mutable_function_registry()->Register(std::move(registry));
cel::Interpreter interpreter(options);
// Example expression with custom functions
std::string expression = "Compute3DIoU(obj1, obj2) > 0.5 && ComputeIncludedAngle(vec1, vec2) < 90";
// Evaluate the expression
cel::Activation activation;
auto status_or = interpreter.Evaluate(expression, activation);
if (status_or.ok()) {
// Handle result
} else {
// Handle error
}
return 0;
We use cel-cpp to write some rules for trigger the action when some condition matched. For some sophisticated rules,we need use some user-defined macros or functions, for example: compute the 3D IOU for two 3D objects(proto message), compute the included angle of two 3D vector and so on.
After search the codebase, we can not find examples about how to add user-defined macros or functions in cel-cpp.
The text was updated successfully, but these errors were encountered: