Skip to content

Commit 2f220b8

Browse files
committed
feat(Examples): add examples for NLU, LT and Discovery
1 parent 3df4a99 commit 2f220b8

16 files changed

+873
-29
lines changed

Examples/ExampleDiscoveryV1.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using IBM.Watson.Discovery.V1;
2+
using IBM.Watson.Discovery.V1.Model;
3+
using IBM.Cloud.SDK.Utilities;
4+
using IBM.Cloud.SDK.Authentication;
5+
using IBM.Cloud.SDK.Authentication.Iam;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using UnityEngine;
9+
using IBM.Cloud.SDK;
10+
11+
public class ExampleDiscoveryV1 : MonoBehaviour
12+
{
13+
#region PLEASE SET THESE VARIABLES IN THE INSPECTOR
14+
[Space(10)]
15+
[Tooltip("The IAM apikey.")]
16+
[SerializeField]
17+
private string iamApikey;
18+
[Tooltip("The service URL (optional). This defaults to \"https://gateway.watsonplatform.net/discovery/api\"")]
19+
[SerializeField]
20+
private string serviceUrl;
21+
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
22+
[SerializeField]
23+
private string versionDate;
24+
#endregion
25+
26+
private DiscoveryService service;
27+
// Start is called before the first frame update
28+
void Start()
29+
{
30+
LogSystem.InstallDefaultReactors();
31+
Runnable.Run(CreateService());
32+
}
33+
34+
// Update is called once per frame
35+
public IEnumerator CreateService()
36+
{
37+
if (string.IsNullOrEmpty(iamApikey))
38+
{
39+
throw new IBMException("Plesae provide IAM ApiKey for the service.");
40+
}
41+
42+
// Create credential and instantiate service
43+
IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);
44+
45+
// Wait for tokendata
46+
while (!authenticator.CanAuthenticate())
47+
yield return null;
48+
49+
service = new DiscoveryService(versionDate, authenticator);
50+
51+
52+
Runnable.Run(ExampleCreateEnvironment());
53+
Runnable.Run(ExampleListEnvironments());
54+
}
55+
56+
private IEnumerator ExampleCreateEnvironment()
57+
{
58+
ModelEnvironment createEnvironmentResponse = null;
59+
service.CreateEnvironment(
60+
callback: (DetailedResponse<ModelEnvironment> response, IBMError error) =>
61+
{
62+
Log.Debug("DiscoveryServiceV1", "CreateEnvironment result: {0}", response.Response);
63+
createEnvironmentResponse = response.Result;
64+
// environmentId = createEnvironmentResponse.EnvironmentId;
65+
},
66+
name: "my_environment",
67+
description: "My environment"
68+
);
69+
70+
while (createEnvironmentResponse == null)
71+
yield return null;
72+
}
73+
74+
private IEnumerator ExampleListEnvironments()
75+
{
76+
Log.Debug("DiscoveryServiceV1", "ListEnvironments");
77+
ListEnvironmentsResponse listEnvironmentsResponse = null;
78+
service.ListEnvironments(
79+
callback: (DetailedResponse<ListEnvironmentsResponse> response, IBMError error) =>
80+
{
81+
Log.Debug("DiscoveryServiceV1", "ListEnvironments result: {0}", response.Response);
82+
listEnvironmentsResponse = response.Result;
83+
}
84+
);
85+
86+
while (listEnvironmentsResponse == null)
87+
yield return null;
88+
}
89+
}

Examples/ExampleDiscoveryV1.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/ExampleDiscoveryV1.unity

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!29 &1
4+
OcclusionCullingSettings:
5+
m_ObjectHideFlags: 0
6+
serializedVersion: 2
7+
m_OcclusionBakeSettings:
8+
smallestOccluder: 5
9+
smallestHole: 0.25
10+
backfaceThreshold: 100
11+
m_SceneGUID: 00000000000000000000000000000000
12+
m_OcclusionCullingData: {fileID: 0}
13+
--- !u!104 &2
14+
RenderSettings:
15+
m_ObjectHideFlags: 0
16+
serializedVersion: 9
17+
m_Fog: 0
18+
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
19+
m_FogMode: 3
20+
m_FogDensity: 0.01
21+
m_LinearFogStart: 0
22+
m_LinearFogEnd: 300
23+
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
24+
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
25+
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
26+
m_AmbientIntensity: 1
27+
m_AmbientMode: 0
28+
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
29+
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
30+
m_HaloStrength: 0.5
31+
m_FlareStrength: 1
32+
m_FlareFadeSpeed: 3
33+
m_HaloTexture: {fileID: 0}
34+
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
35+
m_DefaultReflectionMode: 0
36+
m_DefaultReflectionResolution: 128
37+
m_ReflectionBounces: 1
38+
m_ReflectionIntensity: 1
39+
m_CustomReflection: {fileID: 0}
40+
m_Sun: {fileID: 0}
41+
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
42+
m_UseRadianceAmbientProbe: 0
43+
--- !u!157 &3
44+
LightmapSettings:
45+
m_ObjectHideFlags: 0
46+
serializedVersion: 11
47+
m_GIWorkflowMode: 1
48+
m_GISettings:
49+
serializedVersion: 2
50+
m_BounceScale: 1
51+
m_IndirectOutputScale: 1
52+
m_AlbedoBoost: 1
53+
m_EnvironmentLightingMode: 0
54+
m_EnableBakedLightmaps: 1
55+
m_EnableRealtimeLightmaps: 1
56+
m_LightmapEditorSettings:
57+
serializedVersion: 12
58+
m_Resolution: 2
59+
m_BakeResolution: 40
60+
m_AtlasSize: 1024
61+
m_AO: 0
62+
m_AOMaxDistance: 1
63+
m_CompAOExponent: 1
64+
m_CompAOExponentDirect: 0
65+
m_ExtractAmbientOcclusion: 0
66+
m_Padding: 2
67+
m_LightmapParameters: {fileID: 0}
68+
m_LightmapsBakeMode: 1
69+
m_TextureCompression: 1
70+
m_FinalGather: 0
71+
m_FinalGatherFiltering: 1
72+
m_FinalGatherRayCount: 256
73+
m_ReflectionCompression: 2
74+
m_MixedBakeMode: 2
75+
m_BakeBackend: 1
76+
m_PVRSampling: 1
77+
m_PVRDirectSampleCount: 32
78+
m_PVRSampleCount: 512
79+
m_PVRBounces: 2
80+
m_PVREnvironmentSampleCount: 256
81+
m_PVREnvironmentReferencePointCount: 2048
82+
m_PVRFilteringMode: 1
83+
m_PVRDenoiserTypeDirect: 1
84+
m_PVRDenoiserTypeIndirect: 1
85+
m_PVRDenoiserTypeAO: 1
86+
m_PVRFilterTypeDirect: 0
87+
m_PVRFilterTypeIndirect: 0
88+
m_PVRFilterTypeAO: 0
89+
m_PVREnvironmentMIS: 1
90+
m_PVRCulling: 1
91+
m_PVRFilteringGaussRadiusDirect: 1
92+
m_PVRFilteringGaussRadiusIndirect: 5
93+
m_PVRFilteringGaussRadiusAO: 2
94+
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
95+
m_PVRFilteringAtrousPositionSigmaIndirect: 2
96+
m_PVRFilteringAtrousPositionSigmaAO: 1
97+
m_ExportTrainingData: 0
98+
m_TrainingDataDestination: TrainingData
99+
m_LightingDataAsset: {fileID: 0}
100+
m_UseShadowmask: 1
101+
--- !u!196 &4
102+
NavMeshSettings:
103+
serializedVersion: 2
104+
m_ObjectHideFlags: 0
105+
m_BuildSettings:
106+
serializedVersion: 2
107+
agentTypeID: 0
108+
agentRadius: 0.5
109+
agentHeight: 2
110+
agentSlope: 45
111+
agentClimb: 0.4
112+
ledgeDropHeight: 0
113+
maxJumpAcrossDistance: 0
114+
minRegionArea: 2
115+
manualCellSize: 0
116+
cellSize: 0.16666667
117+
manualTileSize: 0
118+
tileSize: 256
119+
accuratePlacement: 0
120+
debug:
121+
m_Flags: 0
122+
m_NavMeshData: {fileID: 0}
123+
--- !u!1 &444819960
124+
GameObject:
125+
m_ObjectHideFlags: 0
126+
m_CorrespondingSourceObject: {fileID: 0}
127+
m_PrefabInstance: {fileID: 0}
128+
m_PrefabAsset: {fileID: 0}
129+
serializedVersion: 6
130+
m_Component:
131+
- component: {fileID: 444819963}
132+
- component: {fileID: 444819961}
133+
m_Layer: 0
134+
m_Name: ExampleDiscoveryV1
135+
m_TagString: Untagged
136+
m_Icon: {fileID: 0}
137+
m_NavMeshLayer: 0
138+
m_StaticEditorFlags: 0
139+
m_IsActive: 1
140+
--- !u!114 &444819961
141+
MonoBehaviour:
142+
m_ObjectHideFlags: 0
143+
m_CorrespondingSourceObject: {fileID: 0}
144+
m_PrefabInstance: {fileID: 0}
145+
m_PrefabAsset: {fileID: 0}
146+
m_GameObject: {fileID: 444819960}
147+
m_Enabled: 1
148+
m_EditorHideFlags: 0
149+
m_Script: {fileID: 11500000, guid: c8cc5579d4a384f8ca87dccdf800981f, type: 3}
150+
m_Name:
151+
m_EditorClassIdentifier:
152+
iamApikey: S
153+
serviceUrl: S
154+
versionDate: 2019-09-16
155+
--- !u!4 &444819963
156+
Transform:
157+
m_ObjectHideFlags: 0
158+
m_CorrespondingSourceObject: {fileID: 0}
159+
m_PrefabInstance: {fileID: 0}
160+
m_PrefabAsset: {fileID: 0}
161+
m_GameObject: {fileID: 444819960}
162+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
163+
m_LocalPosition: {x: 0, y: 0, z: 0}
164+
m_LocalScale: {x: 1, y: 1, z: 1}
165+
m_Children: []
166+
m_Father: {fileID: 0}
167+
m_RootOrder: 0
168+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

Examples/ExampleDiscoveryV1.unity.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using IBM.Watson.LanguageTranslator.V3;
2+
using IBM.Watson.LanguageTranslator.V3.Model;
3+
using IBM.Cloud.SDK.Utilities;
4+
using IBM.Cloud.SDK.Authentication;
5+
using IBM.Cloud.SDK.Authentication.Iam;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using UnityEngine;
9+
using IBM.Cloud.SDK;
10+
11+
public class ExampleLanguageTranslatorV3 : MonoBehaviour
12+
{
13+
#region PLEASE SET THESE VARIABLES IN THE INSPECTOR
14+
[Space(10)]
15+
[Tooltip("The IAM apikey.")]
16+
[SerializeField]
17+
private string iamApikey;
18+
[Tooltip("The service URL (optional). This defaults to \"https://gateway.watsonplatform.net/discovery/api\"")]
19+
[SerializeField]
20+
private string serviceUrl;
21+
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
22+
[SerializeField]
23+
private string versionDate;
24+
#endregion
25+
26+
private LanguageTranslatorService service;
27+
// Start is called before the first frame update
28+
void Start()
29+
{
30+
LogSystem.InstallDefaultReactors();
31+
Runnable.Run(CreateService());
32+
}
33+
34+
// Update is called once per frame
35+
public IEnumerator CreateService()
36+
{
37+
if (string.IsNullOrEmpty(iamApikey))
38+
{
39+
throw new IBMException("Plesae provide IAM ApiKey for the service.");
40+
}
41+
42+
// Create credential and instantiate service
43+
IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);
44+
45+
// Wait for tokendata
46+
while (!authenticator.CanAuthenticate())
47+
yield return null;
48+
49+
service = new LanguageTranslatorService(versionDate, authenticator);
50+
service.SetServiceUrl("https://api.us-south.language-translator.test.watson.cloud.ibm.com");
51+
52+
53+
Log.Debug("LanguageTranslatorServiceV3", "ListModels result");
54+
}
55+
56+
private IEnumerator ExampleListModels()
57+
{
58+
TranslationModels listModelsResponse = null;
59+
service.ListModels(
60+
callback: (DetailedResponse<TranslationModels> response, IBMError error) =>
61+
{
62+
Log.Debug("LanguageTranslatorServiceV3", "ListModels result: {0}", response.Response);
63+
listModelsResponse = response.Result;
64+
},
65+
source: "en",
66+
target: "fr"
67+
);
68+
69+
while (listModelsResponse == null)
70+
yield return null;
71+
}
72+
}

Examples/ExampleLanguageTranslatorV3.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)