Inference result wrapper structure. Passes incremental text, complete JSON data, and engine status within the callback function.
The text_chunk and full_json_chunk members point to internal circular buffers within the DLL. Once the callback function finishes execution and returns, these memory addresses may be overwritten immediately.
| Member | Type | Description |
|---|---|---|
text_chunk |
const char* |
Incremental text fragment. Contains only the characters generated in this step. Used for streaming typewriter effects. |
full_json_chunk |
const char* |
Complete response JSON. Contains full information including tool_calls, content, and stats. Recommended to parse this field at the end of generation for structured data. |
bIsDone |
int |
Termination flag. 1 indicates inference is complete (or interrupted); 0 means generation is still in progress. |
tokens_per_sec |
float |
Instantaneous generation rate. Tokens generated per second, used for real-time UI performance monitoring. |
void OnInferenceResult(LiteRtLm_Result Result, void* UserPtr) {
// 1. Memory Safety: Convert to engine-safe type immediately (Deep Copy)
FString ChunkString(UTF8_TO_TCHAR(Result.text_chunk));
// 2. Schedule to Game Thread UI
AsyncTask(ENamedThreads::GameThread, [ChunkString, bDone = Result.bIsDone]() {
// Update UI Text Block...
if (bDone) {
UE_LOG(LogTemp, Log, TEXT("Generation Finished"));
}
});
}