UG AI Engine for children
For a full working demo - please follow
Basic example
Start by calling:
UGSDK.Initialize();
This must be done one in you app’s life cycle - such as during the game splash screen. Make sure that settings file is present and has correct credentials.
Conversation manager handles end-to-end conversation logic. You can set conversation configuration, by calling SetConfiguration() like so:
UGSDK.ConversationManager.SetConfiguration(new ConversationConfiguration() { Prompt = “be polite, respond in 2 sentences”, Temperature = 0.5f, });
You can subscribe to conversation events in the following way:
UGSDK.ConversationManager.OnConversationEvent += HandleConversationEvent; private void HandleConversationEvent(ConversationEvent conversationEvent) { switch (conversationEvent.Type) { case ConversationEventType.TextReceived: _uiText.SetText((conversationEvent.Data as TextReceivedData).Text) break; case ConversationEventType.Error: Debug.Log("Error: " + (conversationEvent.Data as ErrorData).Message); break; case ConversationEventType.InteractionStarted: Debug.Log("Interaction started"); break; case ConversationEventType.PlayingAudio: // Set microphone UI component state to “Playing” break; } }
Read
ConversationEventType.TextReceived
to get the text of the response, react to audio/microphone state changes (Playing, Recording, PlayerSpoke, etc.) - or in advanced cases, when receiving values from operations.Check this page for the complete list of conversation events:
Use the following functions to control the conversation flow:
// Start conversation UGSDK.ConversationManager.StartConversation(); // Pause conversation UGSDK.ConversationManager.PauseConversation(); // Clear configuration UGSDK.ConversationManager.ClearConversation();
Once you call
UGSDK.ConversationManager.StartConversation()
you should hear the initial audio response, and get conversation events. Once you receive ConversationEventType.RecordingMicrophone
- microphone starts recording and you can talk back.Advanced usage
Utilities can be set in the conversation configuration:
UGSDK.ConversationManager.StartConversation(new ConversationConfiguration() { Prompt = "Talk about animals", Temperature = 0.5f, Utilities = new Dictionary<string, object>() { ["cats"] = new UG.Models.Classify { ClassificationQuestion = "Did the user mention cats in the last message?", Answers = new List<string> { "yes", "no" } } } });
Once defined, you enable or disable them using
SetOnInputUtilities/SetOnOutputUtilities
:// Utility will run on User Input UGSDK.ConversationManager.SetOnInputUtilities(new List<string> { "cats" }); // Utility will run on Assistant Output UGSDK.ConversationManager.SetOnOutputUtilities(new List<string> { "cats" });
To get the results, you need to read the data from
ConversationEventType.DataReceived
event:UGSDK.ConversationManager.OnConversationEvent += HandleConversationEvent; private void HandleConversationEvent(ConversationEvent conversationEvent) { case ConversationEventType.DataReceived: var dataMessage = (conversationEvent.Data as DataReceivedData).Data; dataMessage.TryGetValue("cats", out var cats); Debug.Log("Data result received: " + cats); break; }