Question Answering
SkillfulAPI.QuestionAnswering
SkillfulAPI.QuestionAnsweringOverview
The QuestionAnsweringfunction is a simple example of how to interact with the SkillfulAI API to get answers based on a given context and question. This functionality can be used to enhance NPC interactions, provide dynamic game feedback, and more.
Function Example
using SkillfulAI.API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestionAnswering : MonoBehaviour
{
    /// <summary>
    /// Unity's Start method, called when the script is initialized. Initiates the question answering process.
    /// </summary>
    private void Start()
    {
        Question();
    }
    /// <summary>
    /// Initiates question answering based on a specified question and context.
    /// </summary>
    public void Question()
    {
        // Context information for answering the question
        string context = "The grass is green";
        // Question to be answered based on the provided context
        string question = "What colour is grass?";
        // Perform question answering
        SkillfulAPI.QuestionAnswering(question, context, response =>
        {
            // Log the answer obtained from the API
            Debug.Log(response.answer);
        });
    }
}Detailed Explanation
Start Method
Description: Unity's Start method is called once when the script is initialized. This method initiates the question answering process.
Code:
private void Start()
{
    Question();
}Functionality:
- Calls the - Questionmethod to begin the process.
Question Method
Description: The Question method handles the question answering logic, using the SkillfulAI API to get a response based on a given context and question.
Code:
public void Question()
{
    // Context information for answering the question
    string context = "The grass is green";
    // Question to be answered based on the provided context
    string question = "What colour is grass?";
    // Perform question answering
    SkillfulAPI.QuestionAnswering(question, context, response =>
    {
        // Log the answer obtained from the API
        Debug.Log(response.answer);
    });
}Functionality:
- Defines a - contextstring providing the information needed to answer the question.
- Defines a - questionstring that queries specific information based on the context.
- Calls - SkillfulAPI.QuestionAnswering, passing the- question,- context, and a callback function to handle the response.
- The callback logs the API's response to the Unity console. 
Usage Example
- Add the Script to a GameObject: - Attach the - QuestionAnsweringscript to any GameObject in your Unity scene.
 
- Run the Scene: - When you start the scene, the - Startmethod is called, which in turn calls the- Questionmethod.
- The - Questionmethod sends a question and context to the SkillfulAI API and logs the answer to the console.
 
Conclusion
The QuestionAnswering function provides a straightforward example of how to leverage the SkillfulAI Gaming SDK to integrate AI-powered question answering into your Unity project. This can be expanded and customized to suit more complex scenarios and interactions in your game.
Last updated
