SkillfulAI
  • Skillful AI
    • Welcome
    • About us
    • Ecosystem
  • Web SDK
    • Overview
    • Getting Started
      • Installation
      • Quick Start
      • Authentication
    • SDK Reference
    • Templates
      • Telegram Bot Template
      • Express Server Template
        • API Reference
      • Discord Bot Template
        • ProActive Mode
      • Kick Stream Bot
        • Getting Started
          • Installation
          • Quick Start
        • Create Commands
        • Advanced Configurations
  • Unity Gaming SDK
    • Overview
    • Getting Started
      • Installation
      • Authentication
    • Services
      • Skillful Agents
        • Overview
        • Quick Start
        • Service Reference
      • Smart NPCs
        • Overview
        • Quick Start
        • Service Reference
      • Skillful Inference
        • Overview
        • Quick Start
        • Service Reference
          • Question Answering
          • Sentence Similarity
          • Speech Recognition
          • Text Classification
          • Text Generation
          • Text Summary
          • Text-To-Image
          • Zero Shot Classification
          • Translation (Localization)
    • Audio Recorder
    • Additional Utilities
Powered by GitBook
On this page
  1. Unity Gaming SDK
  2. Services
  3. Skillful Inference
  4. Service Reference

Question Answering

SkillfulAPI.QuestionAnswering

Overview

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 Question method 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 context string providing the information needed to answer the question.

  • Defines a question string 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

  1. Add the Script to a GameObject:

    • Attach the QuestionAnswering script to any GameObject in your Unity scene.

  2. Run the Scene:

    • When you start the scene, the Start method is called, which in turn calls the Question method.

    • The Question method 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.

PreviousService ReferenceNextSentence Similarity

Last updated 10 months ago