Tutorial: how to make an interactive discussion

In this tutorial, we are going to learn how to use Llama Plugin to make an interactive discussion between us and the machine. This means to have a discussion with the theme we  have chosen! To achieve this, we make use of a basic user interface with one input box to get the prompt for the user and a textbox to display the answer of the machine.

Step 1: Create a GameState

This GameState allows us to initialize the model and the contexts. Using the GameState allows us to store all your contexts within global variables that can be used in the blueprint code of your actors or the blueprint code of a level. 

We define as many contexts as we need in our application in the GameState and put their visibility to public.

Step 2: Initialize your model in the level blueprint

After being created, you need to initialize variables. In the level blueprint, we load a model and a context. Then we initialize the context we have created in the GameState, so we can access it in the user interface.

Step 3: Implement the user interface logic

Now that we have initialized Llama variables, we are ready to implement the discussion and how we will discuss with the machine.

Let's create an interface component (UMG_Chat). Then, let's add some child components: a button, a text input and a text output. Then, we can find them in the variables menu at the left of the screen.

To finish, let's follow the screenshot. We can replace the Get AIAnswer with callback node by the Get AIAnswer node. Using the callback version allows us to have a more interactive discussion. Instead of waiting for the computation to be done, it displays the stream of text that is being generated.

Now let's go back to the level blueprint and add the interface to the viewport, so the user can see it and play with it. Run the game, and enjoy.