AIDevKit - AI Suite for Unity
API ReferencesDiscordGlitch9
  • Introduction
    • AI Dev Kit 3.7.0
    • Troubleshooting
    • FAQ
    • Update Logs
      • AI Dev Kit v2
      • AI Dev Kit v1
  • Quick Start
    • API Key Setup
      • OpenAI
      • Google Gemini
      • ElevenLabs
      • OpenRouter
    • Adding Models & Voices
      • Quick Add Guide
      • Creating Snippets
    • Self-Hosting with Ollama
  • Editor Tools
    • Editor Chat
    • Asset Generators
    • Asset Managers
      • Prompt History
      • File Manager
      • Chatbot Manager
      • Assistant Manager
  • GEN Tasks
    • Overview
      • Prefixes
      • Sequence
    • Response
    • Image
    • Video
    • SoundFX
    • Speech
    • Transcript
    • Voice Change
    • Audio Isolation
  • Components
    • Chatbot
    • Chatbot (Assistants API)
    • Realtime Assistant
    • Modules
    • Event Receivers
  • Platform API
    • OpenAI
      • 💬Chat completions
      • 🖼️Image operations
      • 🗣️Text to speech
      • 🎙️Speech to text
        • Recording real-time in Unity
      • 💾Files
      • 🔎Embeddings
      • 🛡️Moderations
      • ⚙️Fine-tuning
      • Assistants API
        • How it works
        • Creating custom functions
        • Creating assistants API
    • Google Gemini
      • 📝System instructions
      • 💬Text generation
      • ⚙️Fine-tuning
      • ▶️Fucntion calling
      • 🔎Embeddings
      • 🛡️Safety
      • 💻Code execution
  • Legacy Documents
    • AI Dev Kit 1.0
      • Preperation
      • Scriptable Toolkits
        • Chat Streamer
        • Image Generator
        • Voice Transcriber
        • Voice Generator
      • Editor Tools
      • Troubleshooting (Legacy)
        • ❗Build Error: The name 'UnityMenu' does not exist in the current context
        • ❗The type or namespace name 'AndroidJavaObject' could not be found
        • ❗The type or namaspace name 'Plastic' does not exist
        • ❗Build Error: The name 'Asset Database' does not exist in the current context
        • ❗'ModelData.Create(Provider, string, UnixTime?, string)': not all code paths return a value
      • Code Generators
        • C# Script Generator
        • Unity Component Generator
    • AI Dev Kit 2.0
      • Event Handlers
      • Editor Chat
      • Editor Vision (TTI, ITI)
      • Editor Speech (TTS)
      • Management Tools
        • Prompt History Viewer
        • AI Model Manager
        • TTS Voice Manager
        • OpenAI File Manager
        • OpenAI Assistant Manager
        • ElevenLabs Voice Library
Powered by GitBook
On this page
  1. GEN Tasks

Response

Generate a response using a Large Language Model (LLM)

PreviousSequenceNextImage

Last updated 15 days ago

returns

Response generation is one of the core uses of generative AI. In the GENTask system, the is used to generate text (for example, completing a prompt or answering a question). This task sends a prompt to a Large Language Model (LLM) and returns a response.

Input Modalities
Output

Text Image Audio Video

Text Text (Streaming) Tool Calls Speech Image (Rarely) File (Rarely)

Basic Usage

string prompt = "Explain quantum computing in simple terms.";

string result = await prompt
    .GENResponse()
    .SetModel(OpenAIIModel.GPT4o)
    .ExecuteAsync();

Debug.Log(result);

Streaming

// Streaming
string prompt = "Explain quantum computing in simple terms.";

await prompt
    .GENResponse()
    .SetModel(OpenAIModel.GPT4o)
    .OnStreamText(chunk => Debug.Log(chunk))
    .OnStreamDone(() => Debug.Log("Finished."))
    .StreamAsync();

Vision Request (Image Recognition)

// Vision Request
Texture2D myTexture = myImage.sprite.texture;
string prompt = "Tell me about this image.";

string result = await prompt
    .GENResponse()
    .Attach(myTexture)
    .SetModel(OpenAIModel.GPT4o)
    .ExecuteAsync();

Debug.Log(result);

Structured Outputs

It's perfect for generating game data like:

  • 📦 Items

  • 🎮 Quests

  • 🗨️ NPC Dialogue Trees

  • 📋 Skill Definitions

  • 🧠 AI Configuration Profiles

Input Modalities
Output

Text Image Audio Video

Structured Outputs (JSON Mode)


Required Annotations:

These attributes are mandatory. Without them, the task will fail to register the schema.

Provider
Required Attributes

OpenAI, Ollama, OpenRouter

[StrictJsonSchema(...)] (on the class) [JsonSchema(...)] (on each property)

Gemini

[JsonSchema(...)] (on the class) [JsonSchema(...)] (on each property)

Generating an RPG Item

using Glitch9.AIDevKit.OpenAI;
using Glitch9.IO.Json.Schema;
using System.Collections.Generic;

[StrictJsonSchema("item_response", Description = "RPG-style inventory item", Strict = true)]
public class GameItem
{
    [JsonSchema("id", Description = "Unique item ID", Required = true)]
    public string Id { get; set; }

    [JsonSchema("name", Description = "Name of the item", Required = true)]
    public string Name { get; set; }

    [JsonSchema("rarity", Description = "Item rarity", Enum = new[] { "Common", "Uncommon", "Rare", "Epic", "Legendary" })]
    public string Rarity { get; set; }

    [JsonSchema("effects", Description = "List of effects applied when used")]
    public List<string> Effects { get; set; }
}


GameItem item = await "Generate a legendary sword with magical effects"
    .GENObject<GameItem>()
    .SetModel(OpenAIModel.GPT4o)
    .SetTemperature(0.4f)
    .ExecuteAsync();

Debug.Log(item.Name + " - " + item.Rarity); // "Blade of Eternity - Legendary"

Generating a Simple Quest

[StrictJsonSchema("quest_response", Description = "Basic RPG quest", Strict = true)]
public class Quest
{
    [JsonSchema("title", Description = "Quest name", Required = true)]
    public string Title { get; set; }

    [JsonSchema("description", Description = "What the player must do", Required = true)]
    public string Description { get; set; }

    [JsonSchema("objective", Description = "Main goal of the quest")]
    public string Objective { get; set; }

    [JsonSchema("rewardXP", Description = "XP rewarded upon completion")]
    public int RewardXP { get; set; }
}

Quest quest = await "Create a side quest for a fantasy game where a farmer asks you to find his lost chicken"
    .GENObject<Quest>()
    .SetModel(OpenAIModel.GPT4o)
    .ExecuteAsync();

returns

lets you turn natural language prompts into strongly-typed Unity C# objects by guiding the AI to return JSON that matches your class definition.

ChatCompletione
GENResponse
StructuredOutput<T>
GENStruct<T>