Text Generation

SkillfulAPI.TextGeneration

The TextGeneration function demonstrates how to use the SkillfulAI Gaming SDK to perform text generation tasks in your Unity project. This guide will walk you through the process of setting up and using the TextGeneration class.

Overview

The TextGeneration class provides functionality to generate text based on a specified prompt. This can be useful for creating dynamic content, generating dialogues, or providing creative inputs in your game.

Class Definition

using SkillfulAI.API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextGeneration : MonoBehaviour
{
    /// <summary>
    /// Unity's Start method, called when the script is initialized. Initiates the text generation process.
    /// </summary>
    void Start()
    {
        GenerateText();
    }

    /// <summary>
    /// Initiates text generation using a specified prompt.
    /// </summary>
    public void GenerateText()
    {
        // Specify a prompt for text generation
        string prompt = "A murder mystery";

        // Generate text based on the provided prompt
        SkillfulAPI.TextGeneration(prompt, result =>
        {
            Debug.Log(result);
        });
    }
}

Detailed Explanation

Start Method

Description: Unity's Start method is called when the script is first initialized. This method triggers the text generation process.

Code:

void Start()
{
    GenerateText();
}

Functionality:

  • Automatically invokes the GenerateText method when the script starts.

  • This method is typically used to initiate processes or set up functionalities as soon as the script is initialized.

GenerateText Method

Description: The GenerateText method sends a specified prompt to the SkillfulAI API to generate text and logs the result.

Code:

public void GenerateText()
{
    // Specify a prompt for text generation
    string prompt = "A murder mystery";

    // Generate text based on the provided prompt
    SkillfulAPI.TextGeneration(prompt, result =>
    {
        Debug.Log(result);
    });
}

Functionality:

  • Sends the specified prompt to the SkillfulAI API for text generation.

  • Logs the generated text received from the API response.

  • Provides a simple way to create or retrieve content dynamically based on user-defined inputs.

Usage Example

  1. Add the Script to a GameObject:

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

  2. Run the Scene:

    • Upon starting the scene, the GenerateText method will be invoked automatically.

    • The specified prompt will be sent to the SkillfulAI API, and the generated text will be logged to the console.

Conclusion

The TextGeneration function demonstrates a basic implementation of text generation using the SkillfulAI Gaming SDK. By leveraging a prompt, you can generate creative or dynamic content, making it a valuable tool for enhancing gameplay and narrative experiences in your Unity project.

Last updated