The Unity Eden AI Plugin provides easy integration with the Eden AI API to perform various AI tasks such as text-to-speech conversion, chatbot interactions, and more within your Unity applications.
Table of Contents
- Installation
- Getting Started
- Usage
To use the Unity Eden AI Plugin in your Unity project, follow these steps:
- Open your Unity Package Manager
- Add package from git url : https://github.com/edenai/unity-plugin.git
To get started with the Unity EdenAI Plugin, you should:
- Install the Plugin.
- Obtain an Eden AI API Key if you haven't already.
- You need to provide your EdenAI API Key to use this plugin. You can set it in your script or
add a file
auth.json
to your user folder (path:~/.edenai
(Linux/Mac) or%USERPROFILE%/.edenai/
(Windows)) as follows:
{
"api_key": "YOUR_EDENAI_API_KEY"
}
- Follow the usage instructions provided below.
You can create an instance of the EdenAIApi
class by passing your API key as a parameter.
If the API key is not provided, it will attempt to read it from the auth.json file in your user folder.
using EdenAI;
EdenAIApi edenAI = new EdenAIApi("YOUR_EDENAI_API_KEY");
You can use the plugin to chat with natural language processing models in your Unity project.
This function is designed to send a request for chat and retrieve the generated text.
In case of errors, a System.Exception
will be raised.
- provider (string) : The data will be redirected to a single provider to obtain the processed results (ex : "openai"). For a list of available providers, please refer to our documentation.
- text (string) : The input text for the chat conversation.
- chatBotGlobalAction (string) (optional): A system message that helps set the behavior of the assistant. For example, "You are a helpful assistant".
- previousHistory (List) (optional): A list containing all the previous conversations between the user and the chatbot AI.
Each item in the list should be a ChatMessage object, which contains Role (
user
orassistant
) and Message (the text of the conversions from the respective role). For example : new List(new ChatMessage() { Role = "assistant", Message = "Hi, how can I help You ?"}). - model (string) (optional) : The specific model to use for the given provider (ex : "gpt-3.5-turbo").
This function returns a ChatResponse
object, which contains :
- status (string) :
fail
orsuccess
- provider (string) : The provider used to process the data.
- generated_text (string) : The generated text by the chatbot AI.
- message (List) : The messages between the
user
and theassistant
. - cost (double) : The cost of the api call.
using EdenAI;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string provider = "openai";
string text = "Hello I'm fine and you ?";
ChatMessage chatMessage = new ChatMessage()
{
Role = "assistant",
Message = "Hello how are you ?"
};
List<ChatMessage> previousHistory = new List<ChatMessage>{ chatMessage };
EdenAIpi edenAI = new EdenAIApi();
ChatResponse response = await edenAI.SendChatRequest(provider, text, previousHistory: previousHistory);
}
};
You can use the plugin to convert text to speech in your Unity project.
In case of errors, a System.Exception
will be raised.
This function is designed to send a request for text-to-speech conversion and retrieve the generated audio output.
- provider (string) : The data will be redirected to a single provider to obtain the processed results (ex : "amazon"). For a list of available providers, please refer to our documentation.
- text (string) : The text to analyze.
- audioFormat (string) : The audio format in which the audio will be generated (ex : "mp3").
- option (TextToSpeechOption) : Specifies the voice for the generated speech. You can choose from the following
options:
TextToSpeechOption.FEMALE
orTextToSpeechOption.MALE
- language (string) : The language code (ex : "en"). For a list of available languages, please refer to our documentation.
- rate (int) (optional) : Increase or decrease the speaking rate by expressing a positif or negatif number ranging between 100 and -100 (a relative value as percentage varying from -100% to 100%)
- pitch (int) (optional) : Increase or decrease the speaking pitch by expressing a positif or negatif number ranging between 100 and -100 (a relative value as percentage varying from -100% to 100%)
- volume (int) (optional) : Increase or decrease the audio volume by expressing a positif or negatif number ranging between 100 and -100 (a relative value as percentage varying from -100% to 100%)
- voiceModel (string) (optional) : The specific model to use for the given provider (ex : "en-US_Justin_Standard").
This function returns a TextToSpeechResponse
object, which contains :
- status (string) :
fail
orsuccess
- provider (string) : The provider used to process the data.
- cost (double) : The cost of the api call.
- audio (AudioClip) : The audio generated.
- audio_base64 (string) : The audio generated in base64.
using EdenAI;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string provider = "amazon";
string text = "Hello how are you ?";
string audioFormat = "mp3";
TextToSpeechOption option = TextToSpeechOption.FEMALE;
string language = "en";
string voiceModel = "en-US_Justin_Standard";
EdenAIApi edenAI = new EdenAIApi();
TextToSpeechResponse response = await edenAI.SendTextToSpeechRequest(provider,
text, audioFormat, option, language, voiceModel: voiceModel);
}
}
You can use the plugin to interact with your data using AskYoda in your Unity project.
Visit Yoda on Eden AI and initiate your initial project.
This function is designed to send a request to interact with your data and retrieve the generated text.
In case of errors, a System.Exception
will be raised.
- projectID (string) : The ID your AskYoda project.
- query (string) : The question or query about the data.
- history (List<Dictionary<string, string>>) (optional) : A list containing all the previous conversations between the user and the chatbot AI. Each dictionary item in the list should contain alternating "user" and "assistant" messages, with their associated roles and text. For example : new List<Dictionary<string, string>>{new Dictionary<string, string> { { "user", "Hi!" }, { "assistant", "Hi, how can I help you?" }}};.
- k (int) (optional) : The number of result chunk to return.
- llmModel (string) (optional) : The model to use for language processing.
- llmProvider (string) (optional) : The provider for the large language model (LLM) for processing. For a list of available providers, please refer to our documentation.
This function returns a YodaResponse
object, which contains :
- result (string) : The large language model (LLM) response.
using EdenAI;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string projectID = "YOUR_YODA_PROJECT_ID";
string query = "Which product is the most expensive?";
EdenAIApi edenAI = new EdenAIApi();
YodaResponse response = await edenAI.SendYodaRequest(projectID, query);
}
}