An official Unity package that allows you to use the KoalaGPT API directly in the Unity game engine.
See [Video](https://youtu.be/htAeWQ5OaZE)
To import the package, follow these steps:
- Open Unity 2019 or later
- Go to
Window > Package Manager
- Click the
+
button and selectAdd package from git URL
- Paste the repository URL https://github.com/CyberKoalaStudios/KoalaGPT-Unity.git and click
Add
To use the KoalaGPT API, you need to have an CyberKoala account. Follow these steps to create an account and generate an API key:
- Go to https://beta.cyberkoala.ru/ and sign up for an account
- Once you have created an account, go to https://beta.cyberkoala.ru/main/dashboard
- Buy a new secret key and save it
To make requests to the KoalaGPT API, you need to use your API key and organization name (if applicable). To avoid exposing your API key in your Unity project, you can save it in your device's local storage.
To do this, follow these steps:
- Create a folder called .cyberkoala in your home directory (e.g.
C:Users\UserName\
for Windows or~\
for Linux or Mac) - Create a file called
auth.json
in the.cyberkoala
folder - Add an api_key field and a organization field (if applicable) to the auth.json file and save it
- Here is an example of what your auth.json file should look like:
{
"api_key": "ko-...er",
"organization": "org-...MOW"
}
IMPORTANT: Your API key is a secret. Do not share it with others or expose it in any client-side code (e.g. browsers, apps). If you are using KoalaGPT for production, make sure to run it on the server side, where your API key can be securely loaded from an environment variable or key management service.
You can use the KoalaGPTApi
class to make async requests to the KoalaGPT API.
All methods are asynchronous and can be accessed directly from an instance of the KoalaGPTApi
class.
Here is an example of how to make a request:
private async void SendRequest()
{
var _koalaGptApi = new KoalaGPTApi();
var _messages = new List<Part>();
var message = new Part();
message.Role = "user";
message.Content = prompt;
_messages.Add(message);
var request = new CreateChatCompletionRequestPrompt{
Model="gpt4",
Prompt="Hello!",
};
var response = await _koalaGptApi.CreateChatCompletionSimplePrompt(request);
}
Voices available: jane, filipp, omazh, madirus
private async void SpeakKoalaGPT()
{
List<Part> _messages;
var message = new Part();
message.Role = "user";
message.Content = "Hi! Help me to pick right wand";
_messages.Add(message);
var request = new CreateAudioCompletionRequest();
request.Messages = _messages;
request.Model = "gpt4";
request.Voice = "jane";
var response = await _koalaGptApi.CreateSpeechPrompt(request);
if (response != null)
{
var audioClip = response;
Debug.Log(audioClip.length);
_audioSource.clip = audioClip;
_audioSource.Play();
}
}
This package includes two sample scenes that you can import via the Package Manager:
- KoalaGPT sample: A simple KoalaGPT like chat example.
The following table shows the supported Unity versions for WebGL builds:
Unity Version | Supported |
---|---|
2022.2.8f1 | ✅ |
2021.3.5f1 | ⛔ |
2020.3.0f1 | ✅ |