C++
For a minimal use case example of Flora Engine in C++ the following steps can be used:
- Create a C++ Actor from the content browser
- In the
.Build.csof the C++ project add"FloraEngine"toPublicDependencyModuleNames - Add
#include "FloraEngineSubsystem"in your Actor's cpp or header file - In
BeginPlay()get a reference to theFloraEngineSubsystem, initialize it and initialize a model. An array of initial input lines may be included if the model requires it (models generated from a .csv do not require these inputs) - Create a
FModelAsyncPromptto use with the model. Prompt is the desired input to the model. The instruction line must be chosen from the available instructions for the model found in the .json template file. - Call
AsyncInferon the subsystem using theFModelAsyncPrompt. A function delegate must be provided that will run on the game thread after inference. - After inference is complete, call
GetOutputwith the created model to retrieve the output and reaction.
Example:
UFloraEngineSubsystem* FloraSubsystem = GetGameInstance()->GetSubsystem<UFloraEngineSubsystem>();
FloraSubsystem->Init();
UNLM* Model = FloraSubsystem->InitNLM(this, "ModelName", TArray<FString>{});
FModelAsyncPrompt* Prompt = new FModelAsyncPrompt{
.WorldContextObject = this,
.Model = Model,
.Prompt = "Input prompt",
.InstructionLine = "StateMachineInstruction"
};
FloraSubsystem->AsyncInfer(Prompt, [this, Prompt]() {
uint8 InstructionIndex, ReactionIndex;
FString Output, Reaction;
float TokenSpeed;
FloraSubsystem->GetOutput(this, Prompt->Model, Output, InstructionIndex, ReactionIndex, Reaction, TokenSpeed);
UE_LOG(LogTemp, Warning, TEXT("Output: %s"), Output);
UE_LOG(LogTemp, Warning, TEXT("Reaction: %s"), Reaction);
});
Databiomes