This plugin allows you to interact with OpenAI's ChatGPT.
This plugin allows you to interact with OpenAI's ChatGPT.
Setup
3. In Unreal Engine, use the Set API Key (OpenAI) node to register your API Key for the plugin. Preferably you should do it in the Game Instance since it just need to be called once.
Generate Response
1) Start by calling the Generate Response node
2) Get familiar with the Best Practices for using Chat GPT documentation.
Notice the Role is set to System. This is how you set the behavior of the AI.
4) Then use another Create Message node to capture the user's input.
Notice the Role is also set to User which means that the message is from a user.
5) Add the callbacks.
Click and hold on the callback pins and drag on an empty spot.
To get the Message from the response, right click on the "Response" pin in the callback and select "Split Struct Pin" to get the Role and Message.
Alternatively, you can extract the response by using the GetResponse node.
Output
Continuous Chat While Keeping the Context
So far, in the previous section, you learned how to use the plugin to generate a response once. Sometimes it may be good to have a continuous chat going back and forth with the AI.
To create a chain with GPT,
Note: You should do this with an interaction like clicking on a button.
2) Add a new Message to the new Array by using the Add Message node again.
3) Call the Generate Response again using the new Array.
By adding the previous messages to the original array, it'll save the context and the AI will save the progress. But if there are too many back and forth between the user and GPT, you may get an error that says the Maximum Token was exceeded.