Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🎮 Unity SDK to use the IBM Watson services.

License

NotificationsYou must be signed in to change notification settings

watson-developer-cloud/unity-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Deploy and Publishwdc-community.slack.comsemantic-releaseCLA assistant

Deprecation Notice

This repo and its associated release binaries are being deprecated. While this repo will no longer see active support from the IBM team, contributions by the community via PRs are still welcomed and will be reviewed. Keep in mind, updates will no longer be published into release binaries and changes made after this update will need to be compiled independently.

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

Announcements

Tone Analyzer Deprecation

As of this major release, 6.0.0, the Tone Analyzer API has been removed in preparation for deprecation. If you wish to continue using this sdk to make calls to Tone Analyzer until its final deprecation, you will have to use a previous version.On 24 February 2022, IBM announced the deprecation of the Tone Analyzer service. The service will no longer be available as of 24 February 2023. As of 24 February 2022, you will not be able to create new instances. Existing instances will be supported until 24 February 2023.

As an alternative, we encourage you to consider migrating to the Natural Language Understanding service on IBM Cloud. With Natural Language Understanding, tone analysis is done by using a pre-built classifications model, which provides an easy way to detect language tones in written text. For more information, seeMigrating from Watson Tone Analyzer Customer Engagement endpoint to Natural Language Understanding.

Natural Language Classifier Deprecation

As of this major release, 6.0.0, the NLC API has been removed in preparation for deprecation. If you wish to continue using this sdk to make calls to NLC until its final deprecation, you will have to use a previous version.On 9 August 2021, IBM announced the deprecation of the Natural Language Classifier service. The service will no longer be available from 8 August 2022. As of 9 September 2021, you will not be able to create new instances. Existing instances will be supported until 8 August 2022. Any instance that still exists on that date will be deleted.

As an alternative, we encourage you to consider migrating to the Natural Language Understanding service on IBM Cloud that uses deep learning to extract data and insights from text such as keywords, categories, sentiment, emotion, and syntax, along with advanced multi-label text classification capabilities, to provide even richer insights for your business or industry. For more information, seeMigrating to Natural Language Understanding.

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, seehttps://cloud.ibm.com/docs/watson?topic=watson-endpoint-change.

Before you begin

Ensure that you have the following prerequisites:

  • You need anIBM Cloud account.
  • Unity. You can use thefree 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 setScripting Runtime Version andApi 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 theseguidelines to configure microphone for Mojave.

Getting the Watson SDK and adding it to Unity

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

Installing the SDK source into your Unity project

Move theunity-sdk andunity-sdk-core directories into theAssets directory of your Unity project.Optional: rename the SDK directory fromunity-sdk toWatson and the Core directory fromunity-sdk-core toIBMSdkCore.

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 athttps://cloud.ibm.com.
    2. Click the service you would like to use.
    3. ClickService credentials.
    4. ClickView 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 athttps://cloud.ibm.com.
    2. Click theCreate service button.
    3. UnderWatson, 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 theCreate button on the bottom.
    5. ClickService Credentials.
    6. ClickView 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 ausername,password and endpointurlor anapikey and endpointurl.

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 a Watson Service in Unity, follow the link to see the code.

Authentication

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

  • With some service instances, you authenticate to the API by usingIAM.
  • In other instances, you authenticate by providing theusername 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 CloudDashboard page.
  2. Either click an existing Watson service instance or clickCreate.
  3. ClickShow to view your service credentials.
  4. Copy theurl and eitherapikey orusername andpassword.

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 serviceAPI key or anaccess 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, seeAuthenticating 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 objectHasIamTokenData() returnstrue.

Supplying the IAM API key

Authenticatorauthenticator;AssistantServiceassistant;stringversionDate="<service-version-date>";IEnumeratorTokenExample(){//  Create authenticator using the IAM token optionsauthenticator=newIamAuthenticator(apikey:"<iam-api-key>");while(!authenticator.CanAuthenticate())yieldreturnnull;assistant=newAssistantService(versionDate,authenticator);assistant.SetServiceUrl("<service-url>");assistant.ListWorkspaces(callback:OnListWorkspaces);}privatevoidOnListWorkspaces(DetailedResponse<WorkspaceCollection>response,IBMErrorerror){Log.Debug("OnListWorkspaces()","Response: {0}",response.Response);}

Supplying the access token

Authenticatorauthenticator;AssistantServiceassistant;stringversionDate="<service-version-date>";voidTokenExample(){//  Create authenticator using the Bearer Tokenauthenticator=newBearerTokenAuthenticator("<bearer-token>");assistant=newAssistantService(versionDate,authenticator);assistant.SetServiceUrl("<service-url>");assistant.ListWorkspaces(callback:OnListWorkspaces);}privatevoidOnListWorkspaces(DetailedResponse<WorkspaceCollection>response,IBMErrorerror){Log.Debug("OnListWorkspaces()","Response: {0}",response.Response);}

Username and password

Authenticatorauthenticator;AssistantServiceassistant;stringversionDate="<service-version-date>";voidUsernamePasswordExample(){Authenticatorauthenticator=newBasicAuthenticator("<username>","<password>","<url>");assistant=newAssistantService(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 theDownload button for the credentials in theManage tab of your service instance.

The file downloaded will be calledibm-credentials.env. This is the name the SDK will search for andmust be preserved unless you want to configure the file path (more on that later). The SDK will look for youribm-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:

publicIEnumeratorExampleAutoService(){AssistantassistantService=newAssistant("2019-04-03");//  Wait for authorization tokenwhile(!assistantService.Authenticator.CanAuthenticate())yieldreturnnull;varlistWorkspacesResult=assistantService.ListWorkspaces();}

And that's it!

If you're using more than one service at a time in your code and get two differentibm-credentials.env files, just put the contents together in oneibm-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 calledIBM_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.

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";DiscoveryServicediscovery;stringdiscoveryVersionDate="<discovery-version-date>";AuthenticatordiscoveryAuthenticator;privatevoidExample(){assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);assistant.SetServiceUrl("<service-url>");discovery=newDiscoveryService(discoveryVersionDate,discoveryAuthenticator);discovery.SetServiceUrl("<service-url>");//  Call with sepcific callbacksassistant.Message(callback:OnMessage,workspaceId:workspaceId);discovery.ListEnvironments(callback:OnGetEnvironments);}privatevoidOnMessage(DetailedResponse<MessageResponse>response,IBMErrorerror){Log.Debug("ExampleCallback.OnMessage()","Response received: {0}",response.Response);}privatevoidOnGetEnvironments(DetailedResponse<ListEnvironmentsResponse>response,IBMErrorerror){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.

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";DiscoveryServicediscovery;stringdiscoveryVersionDate="<discovery-version-date>";AuthenticatordiscoveryAuthenticator;privatevoidExample(){assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);assistant.SetServiceUrl("<service-url>");//  Call with generic callbacksJObjectinput=newJObject();input.Add("text","");assistant.Message(callback:OnSuccess,workspaceId:workspaceId,input:input);discovery=newDiscoveryService(discoveryVersionDate,discoveryAuthenticator);discovery.SetServiceUrl("<service-url>");discovery.ListEnvironments(callback:OnSuccess);}//  Generic success callbackprivatevoidOnSuccess<T>(DetailedResponse<T>resp,IBMErrorerror){Log.Debug("ExampleCallback.OnSuccess()","Response received: {0}",resp.Response);}

You can also use an anonymous callback

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";privatevoidExample(){assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);assistant.ListWorkspaces(callback:(DetailedResponse<WorkspaceCollection>response,IBMErrorerror)=>{Log.Debug("ExampleCallback.OnSuccess()","ListWorkspaces result: {0}",response.Response);},pageLimit:1,includeCount:true,sort:"-name",includeAudit:true);assistant.SetServiceUrl("<service-url>");}

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

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";privatevoidExample(){assistant=newAssistantService(versionDate,authenticator);assistant.Message(OnMessage,workspaceId);}privatevoidOnMessage(DetailedResponse<MessageResponse>response,IBMErrorerror){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.

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";voidExample(){assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);//  Add custom header to the REST callassistant.WithHeader("X-Watson-Metadata","customer_id=some-assistant-customer-id");assistant.Message(OnSuccess,"<workspace-id>");}privatevoidOnSuccess(DetailedResponse<MessageResponse>response,IBMErrorerror){Log.Debug("ExampleCallback.OnMessage()","Response received: {0}",response.Response);}

Response Headers

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

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";voidExample(){assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);assistant.Message(OnMessage,"<workspace-id>");}privatevoidOnMessage(DetailedResponse<MessageResponse>response,IBMErrorerror){//  List all headers in the response headers objectforeach(KeyValuePair<string,object>kvpinresponse.Headers){Log.Debug("ExampleCustomHeader.OnMessage()","{0}: {1}",kvp.Key,kvp.Value);}}

Transaction IDs

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

publicvoidExampleGetTransactionId(){AssistantServiceservice=newAssistantService("{version-date}");service.ListWorkspaces(callback:(DetailedResponse<Workspace>response,IBMErrorerror)=>{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.

publicvoidExampleSetTransactionId(){AssistantServiceservice=newAssistantService("{version-date}");service.WithHeader("X-Global-Transaction-Id","<my-unique-transaction-id>");service.ListWorkspaces(callback:(DetailedResponse<Workspace>response,IBMErrorerror)=>{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 setScripting 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.

AssistantServiceassistant;stringassistantVersionDate="<assistant-version-date>";AuthenticatorassistantAuthenticator;stringworkspaceId="<workspaceId>";voidExample(){authenticator.DisableSslVerification=true;assistant=newAssistantService(assistantVersionDate,assistantAuthenticator);//  disable ssl verificationassistant.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 theusername,password,icp4d_url andauthentication_type

The SDK will manage the token for the user

CloudPakForDataAuthenticatorauthenticator=newCloudPakForDataAuthenticator("<url>","<username>","<password>");while(!authenticator.CanAuthenticate()){yieldreturnnull;}service=newAssistantService(versionDate,authenticator);

2) Supplying the access token

BearerTokenAuthenticator=newBearerTokenAuthenticator("<accessToken>");while(!authenticator.CanAuthenticate()){yieldreturnnull;}service=newAssistantService(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 foundhere. 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 onYouTube.

Questions

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

Open Source @ IBM

Find more open source projects on theIBM Github Page.

License

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

Contributing

SeeCONTRIBUTING.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.


[8]ページ先頭

©2009-2025 Movatter.jp