Callback function prototype. Defines how the engine pushes asynchronous generation results to the host application. Implements context retention using the User Pointer pattern.
Since the C-API cannot recognize C++ class member functions, a static function or Lambda like LiteRtLmCallback, combined with user_ptr, must be used to retrieve the C++ object context.
typedef void (*LiteRtLmCallback)(LiteRtLm_Result result, void* user_ptr);
Parameter: result
Contains the incremental text fragments and status info for this turn. See details in LiteRtLm_Result.Parameter: user_ptr
Original pointer passed by the caller inRunInference. Usually points to a C++ class instance (e.g., this).
// Static callback adapter
static void OnStaticResult(LiteRtLm_Result Result, void* UserPtr) {
// Cast to the corresponding C++ class
UMyAiSubsystem* Subsystem = static_cast<UMyAiSubsystem*>(UserPtr);
if (Subsystem) {
Subsystem->HandleAsyncText(Result);
}
}
// Call site
LiteRtLm_RunInference(Conv, Params, OnStaticResult, this); // Pass this pointer