All Projects → watson-developer-cloud → Unity Sdk

watson-developer-cloud / Unity Sdk

Licence: apache-2.0
🎮 Unity SDK to use the IBM Watson services.

Projects that are alternatives of or similar to Unity Sdk

Infinity Square Space
Infinity Square/Space. The prototype of the game is open source. Unity Asset.
Stars: ✭ 122 (-77.66%)
Mutual labels:  artificial-intelligence, unity3d
Libplanet
Blockchain core in C#/.NET for persistent peer-to-peer online games
Stars: ✭ 293 (-46.34%)
Mutual labels:  hacktoberfest, unity3d
100daysofmlcode
My journey to learn and grow in the domain of Machine Learning and Artificial Intelligence by performing the #100DaysofMLCode Challenge.
Stars: ✭ 146 (-73.26%)
Mutual labels:  artificial-intelligence, hacktoberfest
Geneticsharp
GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
Stars: ✭ 813 (+48.9%)
Mutual labels:  artificial-intelligence, unity3d
Hsv Color Picker Unity
HSV color picker for Unity UI
Stars: ✭ 355 (-34.98%)
Mutual labels:  hacktoberfest, unity3d
Ciphey
⚡ Automatically decrypt encryptions without knowing the key or cipher, decode encodings, and crack hashes ⚡
Stars: ✭ 9,116 (+1569.6%)
Mutual labels:  artificial-intelligence, hacktoberfest
Free Ai Resources
🚀 FREE AI Resources - 🎓 Courses, 👷 Jobs, 📝 Blogs, 🔬 AI Research, and many more - for everyone!
Stars: ✭ 192 (-64.84%)
Mutual labels:  artificial-intelligence, hacktoberfest
Ffdl
Fabric for Deep Learning (FfDL, pronounced fiddle) is a Deep Learning Platform offering TensorFlow, Caffe, PyTorch etc. as a Service on Kubernetes
Stars: ✭ 640 (+17.22%)
Mutual labels:  artificial-intelligence, watson
Crystalai
A Utility AI for C# and Unity
Stars: ✭ 328 (-39.93%)
Mutual labels:  artificial-intelligence, unity3d
Vrtk
*Beta* - An example of how to use the Tilia packages to create great content with VRTK v4.
Stars: ✭ 3,422 (+526.74%)
Mutual labels:  unity3d, vr
Kfserving
Serverless Inferencing on Kubernetes
Stars: ✭ 809 (+48.17%)
Mutual labels:  artificial-intelligence, hacktoberfest
Gorgonia
Gorgonia is a library that helps facilitate machine learning in Go.
Stars: ✭ 4,295 (+686.63%)
Mutual labels:  artificial-intelligence, hacktoberfest
Querido Diario
📰 Brazilian government gazettes, accessible to everyone.
Stars: ✭ 681 (+24.73%)
Mutual labels:  artificial-intelligence, hacktoberfest
Reflexityai
Provide a basic framework to build an Utility IA in Unity using the xNode editor of Siccity
Stars: ✭ 109 (-80.04%)
Mutual labels:  artificial-intelligence, unity3d
Enclosure Picroft
Mycroft interface for Raspberry Pi environment
Stars: ✭ 649 (+18.86%)
Mutual labels:  artificial-intelligence, hacktoberfest
Pai
Resource scheduling and cluster management for AI
Stars: ✭ 2,223 (+307.14%)
Mutual labels:  artificial-intelligence, hacktoberfest
Node Sdk
☄️ Node.js library to access IBM Watson services.
Stars: ✭ 1,471 (+169.41%)
Mutual labels:  watson, hacktoberfest
Mycroft Core
Mycroft Core, the Mycroft Artificial Intelligence platform.
Stars: ✭ 5,489 (+905.31%)
Mutual labels:  artificial-intelligence, hacktoberfest
Ar Vrcourse
VR,AR,MR 开发入门教程
Stars: ✭ 298 (-45.42%)
Mutual labels:  unity3d, vr
Mindsdb
Predictive AI layer for existing databases.
Stars: ✭ 4,199 (+669.05%)
Mutual labels:  artificial-intelligence, hacktoberfest

IBM Watson SDK for Unity

Deploy and Publish wdc-community.slack.com semantic-release CLA assistant

Deprecated builds

Build Status

Use this SDK to build Watson-powered applications in Unity.

Table of Contents

ANNOUNCEMENTS!

Updating endpoint URLs from watsonplatform.net

Watson API endpoint URLs at watsonplatform.net are changing and will not work after 26 May 2021. Update your calls to use the newer endpoint URLs. For more information, see https://cloud.ibm.com/docs/watson?topic=watson-endpoint-change.

Personality Insights deprecation

IBM Watson™ Personality Insights is discontinued. For a period of one year from 1 December 2020, you will still be able to use Watson Personality Insights. However, as of 1 December 2021, the offering will no longer be available.

As an alternative, we encourage you to consider migrating to IBM Watson™ Natural Language Understanding, a service on IBM Cloud® that uses deep learning to extract data and insights from text such as keywords, categories, sentiment, emotion, and syntax to provide insights for your business or industry. For more information, see About Natural Language Understanding.

Visual Recognition deprecation

IBM Watson™ Visual Recognition is discontinued. Existing instances are supported until 1 December 2021, but as of 7 January 2021, you can't create instances. Any instance that is provisioned on 1 December 2021 will be deleted.

Compare and Comply deprecation

IBM Watson™ Compare and Comply is discontinued. Existing instances are supported until 30 November 2021, but as of 1 December 2020, you can't create instances. Any instance that exists on 30 November 2021 will be deleted. Consider migrating to Watson Discovery Premium on IBM Cloud for your Compare and Comply use cases. To start the migration process, visit https://ibm.biz/contact-wdc-premium.

Before you begin

Ensure that you have the following prerequisites:

  • You need an IBM Cloud account.
  • Unity. You can use the free Personal edition.

Configuring Unity

  • Change the build settings in Unity (File > Build Settings) to any platform except for web player/Web GL. The IBM Watson SDK for Unity does not support Unity Web Player.
  • If using Unity 2018.2 or later you'll need to set Scripting Runtime Version and Api Compatibility Level in Build Settings to .NET 4.x equivalent. We need to access security options to enable TLS 1.2.

Updating MacOS to Mojave may disable microphone for Unity. If you are running into this issue please see these guidelines to configure microphone for Mojave.

Getting the Watson SDK and adding it to Unity

You can get the latest SDK release by clicking here. You will also need to download the latest release of the IBM Unity SDK Core by clicking here.

Installing the SDK source into your Unity project

Move the unity-sdk and unity-sdk-core directories into the Assets directory of your Unity project. Optional: rename the SDK directory from unity-sdk to Watson and the Core directory from unity-sdk-core to IBMSdkCore.

Discovery v2 only on CP4D

Discovery v2 is only available on Cloud Pak for Data.

Configuring your service credentials

To create instances of Watson services and their credentials, follow the steps below.

Note: Service credentials are different from your IBM Cloud account username and password.

  1. Determine which services to configure.
  2. If you have configured the services already, complete the following steps. Otherwise, go to step 3.
    1. Log in to IBM Cloud at https://cloud.ibm.com.
    2. Click the service you would like to use.
    3. Click Service credentials.
    4. Click View credentials to access your credentials.
  3. If you need to configure the services that you want to use, complete the following steps.
    1. Log in to IBM Cloud at https://cloud.ibm.com.
    2. Click the Create service button.
    3. Under Watson, select which service you would like to create an instance of and click that service.
    4. Give the service and credential a name. Select a plan and click the Create button on the bottom.
    5. Click Service Credentials.
    6. Click View credentials to access your credentials.
  4. Your service credentials can be used to instantiate Watson Services within your application. Most services also support tokens which you can instantiate the service with as well.

The credentials for each service contain either a username, password and endpoint url or an apikey and endpoint url.

WARNING: You are responsible for securing your own credentials. Any user with your service credentials can access your service instances!

Watson Services

To get started with the Watson Services in Unity, click on each service below to read through each of their README.md's and their codes.

Authentication

Watson services are migrating to token-based Identity and Access Management (IAM) authentication.

  • With some service instances, you authenticate to the API by using IAM.
  • In other instances, you authenticate by providing the username and password for the service instance.

Getting credentials

To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:

  1. Go to the IBM Cloud Dashboard page.
  2. Either click an existing Watson service instance or click Create.
  3. Click Show to view your service credentials.
  4. Copy the url and either apikey or username and password.

In your code, you can use these values in the service constructor or with a method call after instantiating your service.

IAM

Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.

You supply either an IAM service API key or an access token:

  • Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
  • Use the access token if you want to manage the lifecycle yourself. For details, see Authenticating with IAM tokens. If you want to switch to API key, in a coroutine, override your stored IAM credentials with an IAM API key and yield until the credentials object HasIamTokenData() returns true.

Supplying the IAM API key

Authenticator authenticator;
AssistantService assistant;
string versionDate = "<service-version-date>";

IEnumerator TokenExample()
{
    //  Create authenticator using the IAM token options
    authenticator = new IamAuthenticator(apikey: "<iam-api-key>");
    while (!authenticator.CanAuthenticate())
        yield return null;

    assistant = new AssistantService(versionDate, authenticator);
    assistant.SetServiceUrl("<service-url>");
    assistant.ListWorkspaces(callback: OnListWorkspaces);
}

private void OnListWorkspaces(DetailedResponse<WorkspaceCollection> response, IBMError error)
{
    Log.Debug("OnListWorkspaces()", "Response: {0}", response.Response);
}

Supplying the access token

Authenticator authenticator;
AssistantService assistant;
string versionDate = "<service-version-date>";

void TokenExample()
{
    //  Create authenticator using the Bearer Token
    authenticator = new BearerTokenAuthenticator("<bearer-token>");

    assistant = new AssistantService(versionDate, authenticator);
    assistant.SetServiceUrl("<service-url>");
    assistant.ListWorkspaces(callback: OnListWorkspaces);
}

private void OnListWorkspaces(DetailedResponse<WorkspaceCollection> response, IBMError error)
{
    Log.Debug("OnListWorkspaces()", "Response: {0}", response.Response);
}

Username and password

Authenticator authenticator;
AssistantService assistant;
string versionDate = "<service-version-date>";

void UsernamePasswordExample()
{
    Authenticator authenticator = new BasicAuthenticator("<username>", "<password>", "<url>");
    assistant = new AssistantService(versionDate, authenticator);
    assistant.SetServiceUrl("<service-url>");
}

Supplying authenticator

There are two ways to supply the authenticator you found above to the SDK for authentication.

Credential file (easier!)

With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing it and authenticating. You can get this file by clicking the Download button for the credentials in the Manage tab of your service instance.

The file downloaded will be called ibm-credentials.env. This is the name the SDK will search for and must be preserved unless you want to configure the file path (more on that later). The SDK will look for your ibm-credentials.env file in the following places (in order):

  • Your system's home directory
  • The top-level directory of the project you're using the SDK in

As long as you set that up correctly, you don't have to worry about setting any authentication options in your code. So, for example, if you created and downloaded the credential file for your Discovery instance, you just need to do the following:

public IEnumerator ExampleAutoService()
{
    Assistant assistantService = new Assistant("2019-04-03");

    //  Wait for authorization token
    while (!assistantService.Authenticator.CanAuthenticate())
        yield return null;

    var listWorkspacesResult = assistantService.ListWorkspaces();
}

And that's it!

If you're using more than one service at a time in your code and get two different ibm-credentials.env files, just put the contents together in one ibm-credentials.env file and the SDK will handle assigning authenticator to their appropriate services.

If you would like to configure the location/name of your credential file, you can set an environment variable called IBM_CREDENTIALS_FILE. This will take precedence over the locations specified above. Here's how you can do that:

export IBM_CREDENTIALS_FILE="<path>"

where <path> is something like /home/user/Downloads/<file_name>.env.

Manually

If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of authenticator your service instance gives you.

Callbacks

A success callback is required. You can specify the return type in the callback.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

DiscoveryService discovery;
string discoveryVersionDate = "<discovery-version-date>";
Authenticator discoveryAuthenticator;

private void Example()
{
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);
    assistant.SetServiceUrl("<service-url>");

    discovery = new DiscoveryService(discoveryVersionDate, discoveryAuthenticator);
    discovery.SetServiceUrl("<service-url>");

    //  Call with sepcific callbacks
    assistant.Message(
        callback: OnMessage,
        workspaceId: workspaceId
    );

    discovery.ListEnvironments(
        callback: OnGetEnvironments
    );
}

private void OnMessage(DetailedResponse<MessageResponse> response, IBMError error)
{
    Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", response.Response);
}

private void OnGetEnvironments(DetailedResponse<ListEnvironmentsResponse> response, IBMError error)
{
    Log.Debug("ExampleCallback.OnGetEnvironments()", "Response received: {0}", response.Response);
}

Since the success callback signature is generic and the failure callback always has the same signature, you can use a single set of callbacks to handle multiple calls.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

DiscoveryService discovery;
string discoveryVersionDate = "<discovery-version-date>";
Authenticator discoveryAuthenticator;

private void Example()
{
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);
    assistant.SetServiceUrl("<service-url>");

    //  Call with generic callbacks
    JObject input = new JObject();
    input.Add("text", "");
    assistant.Message(
        callback: OnSuccess,
        workspaceId: workspaceId,
        input: input
    );

    discovery = new DiscoveryService(discoveryVersionDate, discoveryAuthenticator);
    discovery.SetServiceUrl("<service-url>");

    discovery.ListEnvironments(
        callback: OnSuccess
    );
}

//  Generic success callback
private void OnSuccess<T>(DetailedResponse<T> resp, IBMError error)
{
    Log.Debug("ExampleCallback.OnSuccess()", "Response received: {0}", resp.Response);
}

You can also use an anonymous callback

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

private void Example()
{
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);

    assistant.ListWorkspaces(
        callback: (DetailedResponse<WorkspaceCollection> response, IBMError error) =>
        {
            Log.Debug("ExampleCallback.OnSuccess()", "ListWorkspaces result: {0}", response.Response);
        },
        pageLimit: 1,
        includeCount: true,
        sort: "-name",
        includeAudit: true
    );
    assistant.SetServiceUrl("<service-url>");
}

You can check the error response to see if there was an error in the call.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

private void Example()
{
    assistant = new AssistantService(versionDate, authenticator);

    assistant.Message(OnMessage, workspaceId);
}

private void OnMessage(DetailedResponse<MessageResponse> response, IBMError error)
{
    if (error == null)
    {
        Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", response.Response);
    }
    else
    {
        Log.Debug("ExampleCallback.OnMessage()", "Error received: {0}, {1}, {3}", error.StatusCode, error.ErrorMessage, error.Response);
    }
}

Custom Request Headers

You can send custom request headers by adding them to the service.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

void Example()
{
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);

    //  Add custom header to the REST call
    assistant.WithHeader("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
    assistant.Message(OnSuccess, "<workspace-id>");
}

private void OnSuccess(DetailedResponse<MessageResponse> response, IBMError error)
{
    Log.Debug("ExampleCallback.OnMessage()", "Response received: {0}", response.Response);
}

Response Headers

You can get response headers in the headers object in the DetailedResponse.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

void Example()
{
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);

    assistant.Message(OnMessage, "<workspace-id>");
}

private void OnMessage(DetailedResponse<MessageResponse> response, IBMError error)
{
    //  List all headers in the response headers object
    foreach (KeyValuePair<string, object> kvp in response.Headers)
    {
        Log.Debug("ExampleCustomHeader.OnMessage()", "{0}: {1}", kvp.Key, kvp.Value);
    }
}

Transaction IDs

Every SDK call returns a response with a transaction ID in the X-Global-Transaction-Id header. Together the service instance region, this ID helps support teams troubleshoot issues from relevant logs.

public void ExampleGetTransactionId()
{
    AssistantService service = new AssistantService("{version-date}");
    service.ListWorkspaces(
        callback: (DetailedResponse<Workspace> response, IBMError error) =>
        {
            if(error != null)
            {
                Log.Debug("AssistantServiceV1", "Transaction Id: {0}", error.ResponseHeaders["X-Global-Transaction-Id"]);
            }
            else
            {
                Log.Debug("AssistantServiceV1", "Transaction Id: {0}", response.Headers["X-Global-Transaction-Id"]);
            }
        }
    );
}

However, the transaction ID isn't available when the API doesn't return a response for some reason. In that case, you can set your own transaction ID in the request. For example, replace <my-unique-transaction-id> in the following example with a unique transaction ID.

public void ExampleSetTransactionId()
{
    AssistantService service = new AssistantService("{version-date}");
    service.WithHeader("X-Global-Transaction-Id", "<my-unique-transaction-id>");
    service.ListWorkspaces(
        callback: (DetailedResponse<Workspace> response, IBMError error) =>
        {
            if(error != null)
            {
                Log.Debug("AssistantServiceV1", "Transaction Id: {0}", error.ResponseHeaders["X-Global-Transaction-Id"]);
            }
            else
            {
                Log.Debug("AssistantServiceV1", "Transaction Id: {0}", response.Headers["X-Global-Transaction-Id"]);
            }
        }
    );
}

TLS 1.0 support

Watson services have upgraded their hosts to TLS 1.2. The Dallas location has a TLS 1.0 endpoint that works for streaming. To stream in other regions, use Unity 2018.2 and set Scripting Runtime Version in Build Settings to .NET 4.x equivalent. To support Speech to Text in earlier versions of Unity, create the instance in the Dallas location.

Disabling SSL verification

You can disable SSL verifciation when making a service call.

AssistantService assistant;
string assistantVersionDate = "<assistant-version-date>";
Authenticator assistantAuthenticator;
string workspaceId = "<workspaceId>";

void Example()
{
    authenticator.DisableSslVerification = true;
    assistant = new AssistantService(assistantVersionDate, assistantAuthenticator);

    //  disable ssl verification
    assistant.DisableSslVerification = true;
}

IBM Cloud Pak for Data(ICP4D)

If your service instance is of ICP4D, below are two ways of initializing the assistant service.

1) Supplying the username, password, icp4d_url and authentication_type

The SDK will manage the token for the user

    CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("<url>", "<username>", "<password>");
    while(!authenticator.CanAuthenticate())
    {
        yield return null;
    }
    service = new AssistantService(versionDate, authenticator);

2) Supplying the access token

    BearerTokenAuthenticator = new BearerTokenAuthenticator("<accessToken>");
    while(!authenticator.CanAuthenticate())
    {
        yield return null;
    }
    service = new AssistantService(versionDate, authenticator);

IBM Cloud Private

The Watson Unity SDK does not support IBM Cloud Private because connection via proxy is not supported in UnityWebRequest.

Documentation

Documentation can be found here. You can also access the documentation by selecting API Reference the Watson menu (Watson -> API Reference).

Getting started videos

You can view Getting Started videos for the IBM Watson SDK for Unity on YouTube.

Questions

If you have issues with the APIs or have a question about the Watson services, see Stack Overflow.

Open Source @ IBM

Find more open source projects on the IBM Github Page.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

Featured projects

We'd love to highlight cool open-source projects that use this SDK! If you'd like to get your project added to the list, feel free to make an issue linking us to it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].