Skip to content

Commit 9c0f2a2

Browse files
authored
Merge pull request #457 from watson-developer-cloud/5532-update-sdk
5532 update sdk
2 parents a2b7941 + 4e8217b commit 9c0f2a2

File tree

13 files changed

+514
-428
lines changed

13 files changed

+514
-428
lines changed

Examples/ServiceExamples/Scripts/ExampleAssistantV2.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
*
1616
*/
1717

18-
using System;
1918
using System.Collections;
2019
using System.Collections.Generic;
21-
using FullSerializer;
2220
using IBM.Watson.DeveloperCloud.Connection;
2321
using IBM.Watson.DeveloperCloud.Logging;
2422
using IBM.Watson.DeveloperCloud.Utilities;
@@ -58,8 +56,6 @@ public class ExampleAssistantV2 : MonoBehaviour
5856

5957
private Assistant _service;
6058

61-
private fsSerializer _serializer = new fsSerializer();
62-
6359
private bool _createSessionTested = false;
6460
private bool _messageTested = false;
6561
private bool _deleteSessionTested = false;

Examples/ServiceExamples/Scripts/ExampleVisualRecognition.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ void Start()
8888
private IEnumerator CreateService()
8989
{
9090
Credentials credentials = null;
91-
if (!string.IsNullOrEmpty(_apikey))
92-
{
93-
// Authenticate using apikey
94-
credentials = new Credentials(_apikey, _serviceUrl);
95-
}
96-
else if (!string.IsNullOrEmpty(_iamApikey))
91+
if (!string.IsNullOrEmpty(_iamApikey))
9792
{
9893
// Authenticate using iamApikey
9994
TokenOptions tokenOptions = new TokenOptions()
@@ -110,7 +105,7 @@ private IEnumerator CreateService()
110105
}
111106
else
112107
{
113-
throw new WatsonException("Please provide either CF apikey or IAM apikey to authenticate the service.");
108+
throw new WatsonException("Please provide IAM apikey to authenticate the service.");
114109
}
115110

116111
// Create credential and instantiate service

README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ The credentials for each service contain either a `username`, `password` and end
6767
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.
6868
* [Assistant V1](/Scripts/Services/Assistant/v1)
6969
* [Assistant V2](/Scripts/Services/Assistant/v2)
70-
* [Conversation](/Scripts/Services/Conversation/v1)
70+
* [Conversation](/Scripts/Services/Conversation/v1) (deprecated - Use Assistant V1 or Assistant V2)
7171
* [Discovery](/Scripts/Services/Discovery/v1)
72-
* [Language Translator V2](/Scripts/Services/LanguageTranslator/v2) (deprecated)
72+
* [Language Translator V2](/Scripts/Services/LanguageTranslator/v2) (deprecated - Use LanguageTranslator V3)
7373
* [Language Translator V3](/Scripts/Services/LanguageTranslator/v3)
7474
* [Natural Language Classifier](/Scripts/Services/NaturalLanguageClassifier/v2)
7575
* [Natural Language Understanding](/Scripts/Services/NaturalLanguageUnderstanding/v1)
@@ -84,7 +84,6 @@ Watson services are migrating to token-based Identity and Access Management (IAM
8484

8585
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
8686
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
87-
- Visual Recognition uses a form of [API key](#api-key) only with instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
8887

8988
### Getting credentials
9089
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:
@@ -179,20 +178,6 @@ void Start()
179178
}
180179
```
181180

182-
### API key
183-
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
184-
```cs
185-
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
186-
using IBM.Watson.DeveloperCloud.Utilities;
187-
188-
void Start()
189-
{
190-
Credentials credentials = new Credentials(<apikey>, <url>);
191-
VisualRecognition _visualRecognition = new VisualRecognition(credentials);
192-
}
193-
```
194-
195-
196181
## Callbacks
197182
Success and failure callbacks are required. You can specify the return type in the callback.
198183
```cs

Scripts/Services/Conversation/v1/Conversation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public Credentials Credentials
9292
/// Conversation constructor
9393
/// </summary>
9494
/// <param name="credentials">The service credentials</param>
95+
[Obsolete("Conversation V1 is deprecated and will be removed in the next major release of the SDK. Use Assistant V1 or Assistant V2.")]
9596
public Conversation(Credentials credentials)
9697
{
9798
if (credentials.HasCredentials() || credentials.HasWatsonAuthenticationToken() || credentials.HasIamTokenData())

Scripts/Services/Conversation/v1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Conversation
22

3+
**Conversation V1 is deprecated and will be removed in the next major release of the SDK. Use Assistant V1 or Assistant V2.**
4+
35
With the IBM Watson™ [Conversation][conversation] service, you can create an application that understands natural-language input and uses machine learning to respond to customers in a way that simulates a conversation between humans.
46

57
## Usage

Scripts/Services/Discovery/v1/DataModels.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,20 @@ public class Environment
7171
/// </summary>
7272
public bool read_only { get; set; }
7373
/// <summary>
74-
/// Size of the environment. = ['XS', 'S', 'MS', 'M', 'ML', 'L', 'XL', 'XXL', 'XXXL'].
74+
/// Size of the environment. = ['LT', 'XS', 'S', 'MS', 'M', 'ML', 'L', 'XL', 'XXL', 'XXXL'].
7575
/// </summary>
7676
public SizeEnum? size { get; set; }
7777
/// <summary>
78+
/// The new size requested for this environment. Only returned when the environment *status* is `resizing`.
79+
///
80+
/// *Note:* Querying and indexing can still be performed during an environment upsize.
81+
/// </summary>
82+
public string requested_size { get; set; }
83+
/// <summary>
84+
/// Information about Continuous Relevancy Training for this environment.
85+
/// </summary>
86+
public SearchStatus search_status { get; set; }
87+
/// <summary>
7888
/// Disk and memory usage.
7989
/// </summary>
8090
public IndexCapacity index_capacity { get; set; }
@@ -112,6 +122,11 @@ public class CreateEnvironmentRequest
112122
/// </value>
113123
public enum SizeEnum
114124
{
125+
/// <summary>
126+
/// Enum LT for LT
127+
/// </summary>
128+
[EnumMember(Value = "LT")]
129+
LT,
115130

116131
/// <summary>
117132
/// Enum XS for XS

Scripts/Services/Discovery/v1/Discovery.cs

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,12 +2612,20 @@ private void OnUpdateDocumentResponse(RESTConnector.Request req, RESTConnector.R
26122612
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
26132613
/// json output from the REST call will be passed in this object as the value of the 'json'
26142614
/// key.</string></param>
2615-
public bool FederatedQuery(SuccessCallback<QueryResponse> successCallback, FailCallback failCallback, string environmentId, List<string> collectionIds, string filter = null, string query = null, string naturalLanguageQuery = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, bool? passages = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, Dictionary<string, object> customData = null)
2615+
public bool FederatedQuery(SuccessCallback<QueryResponse> successCallback, FailCallback failCallback, string environmentId, List<string> collectionIds, string filter = null, string query = null, string naturalLanguageQuery = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, bool? passages = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, string bias = null, string loggingOptOut = null, Dictionary<string, object> customData = null)
26162616
{
26172617
if (successCallback == null)
26182618
throw new ArgumentNullException("successCallback");
26192619
if (failCallback == null)
26202620
throw new ArgumentNullException("failCallback");
2621+
if (string.IsNullOrEmpty(environmentId))
2622+
{
2623+
throw new ArgumentNullException("environmentId");
2624+
}
2625+
if(collectionIds == null || collectionIds.Count < 1)
2626+
{
2627+
throw new ArgumentNullException("collectionId");
2628+
}
26212629

26222630
FederatedQueryRequestObj req = new FederatedQueryRequestObj();
26232631
req.SuccessCallback = successCallback;
@@ -2631,44 +2639,41 @@ public bool FederatedQuery(SuccessCallback<QueryResponse> successCallback, FailC
26312639
}
26322640
}
26332641
req.Parameters["version"] = VersionDate;
2634-
if (collectionIds != null)
2635-
req.Parameters["collection_ids"] = collectionIds != null && collectionIds.Count > 0 ? string.Join(",", collectionIds.ToArray()) : null;
2636-
if (!string.IsNullOrEmpty(filter))
2637-
req.Parameters["filter"] = filter;
2638-
if (!string.IsNullOrEmpty(query))
2639-
req.Parameters["query"] = query;
2640-
if (!string.IsNullOrEmpty(naturalLanguageQuery))
2641-
req.Parameters["natural_language_query"] = naturalLanguageQuery;
2642-
if (!string.IsNullOrEmpty(aggregation))
2643-
req.Parameters["aggregation"] = aggregation;
2644-
if (count != null)
2645-
req.Parameters["count"] = count;
2646-
if (returnFields != null)
2647-
req.Parameters["return"] = returnFields != null && returnFields.Count > 0 ? string.Join(",", returnFields.ToArray()) : null;
2648-
if (offset != null)
2649-
req.Parameters["offset"] = offset;
2650-
if (sort != null)
2651-
req.Parameters["sort"] = sort != null && sort.Count > 0 ? string.Join(",", sort.ToArray()) : null;
2652-
if (highlight != null)
2653-
req.Parameters["highlight"] = highlight;
2654-
if (deduplicate != null)
2655-
req.Parameters["deduplicate"] = deduplicate;
2656-
if (!string.IsNullOrEmpty(deduplicateField))
2657-
req.Parameters["deduplicate.field"] = deduplicateField;
2658-
if (similar != null)
2659-
req.Parameters["similar"] = similar;
2660-
if (similarDocumentIds != null)
2661-
req.Parameters["similar.document_ids"] = similarDocumentIds != null && similarDocumentIds.Count > 0 ? string.Join(",", similarDocumentIds.ToArray()) : null;
2662-
if (similarFields != null)
2663-
req.Parameters["similar.fields"] = similarFields != null && similarFields.Count > 0 ? string.Join(",", similarFields.ToArray()) : null;
2664-
if (passages != null)
2665-
req.Parameters["passages"] = passages;
2666-
if (passagesFields != null)
2667-
req.Parameters["passages.fields"] = passagesFields != null && passagesFields.Count > 0 ? string.Join(",", passagesFields.ToArray()) : null;
2668-
if (passagesCount != null)
2669-
req.Parameters["passages.count"] = passagesCount;
2670-
if (passagesCharacters != null)
2671-
req.Parameters["passages.characters"] = passagesCharacters;
2642+
if (loggingOptOut != null)
2643+
{
2644+
req.Headers.Add("X-Watson-Logging-Opt-Out", loggingOptOut.ToString());
2645+
}
2646+
req.Headers["Content-Type"] = "application/json";
2647+
2648+
QueryLarge queryLarge = new QueryLarge()
2649+
{
2650+
Filter = filter,
2651+
Query = query,
2652+
NaturalLanguageQuery = naturalLanguageQuery,
2653+
Passages = passages,
2654+
Aggregation = aggregation,
2655+
Count = count,
2656+
ReturnFields = (returnFields == null || returnFields.Count < 1) ? null : string.Join(", ", returnFields.ToArray()),
2657+
Offset = offset,
2658+
Sort = (sort == null || sort.Count < 1) ? null : string.Join(", ", sort.ToArray()),
2659+
Highlight = highlight,
2660+
PassagesFields = (passagesFields == null || passagesFields.Count < 1) ? null : string.Join(", ", passagesFields.ToArray()),
2661+
PassagesCount = passagesCount,
2662+
PassagesCharacters = passagesCharacters,
2663+
Deduplicate = deduplicate,
2664+
DeduplicateField = deduplicateField,
2665+
CollectionIds = (collectionIds == null || collectionIds.Count < 1) ? null : string.Join(", ", collectionIds.ToArray()),
2666+
Similar = similar,
2667+
SimilarDocumentIds = (similarDocumentIds == null || similarDocumentIds.Count < 1) ? null : string.Join(", ", similarDocumentIds.ToArray()),
2668+
SimilarFields = (similarFields == null || similarFields.Count < 1) ? null : string.Join(", ", similarFields.ToArray()),
2669+
Bias = bias
2670+
};
2671+
2672+
fsData data = null;
2673+
_serializer.TrySerialize(queryLarge, out data);
2674+
string json = data.ToString().Replace('\"', '"');
2675+
req.Send = Encoding.UTF8.GetBytes(json);
2676+
26722677
req.OnResponse = OnFederatedQueryResponse;
26732678

26742679
RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format("/v1/environments/{0}/query", environmentId));
@@ -2969,7 +2974,7 @@ private void OnFederatedQueryNoticesResponse(RESTConnector.Request req, RESTConn
29692974
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
29702975
/// json output from the REST call will be passed in this object as the value of the 'json'
29712976
/// key.</string></param>
2972-
public bool Query(SuccessCallback<QueryResponse> successCallback, FailCallback failCallback, string environmentId, string collectionId, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, bool? loggingOptOut = null, Dictionary<string, object> customData = null)
2977+
public bool Query(SuccessCallback<QueryResponse> successCallback, FailCallback failCallback, string environmentId, string collectionId, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, List<string> returnFields = null, long? offset = null, List<string> sort = null, bool? highlight = null, List<string> passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, List<string> similarDocumentIds = null, List<string> similarFields = null, string bias = null, bool? loggingOptOut = null, Dictionary<string, object> customData = null)
29732978
{
29742979
if (successCallback == null)
29752980
throw new ArgumentNullException("successCallback");
@@ -2989,43 +2994,39 @@ public bool Query(SuccessCallback<QueryResponse> successCallback, FailCallback f
29892994
}
29902995
req.Parameters["version"] = VersionDate;
29912996
if (loggingOptOut != null)
2992-
req.Headers["X-Watson-Logging-Opt-Out"] = loggingOptOut.ToString();
2993-
if (!string.IsNullOrEmpty(filter))
2994-
req.Parameters["filter"] = filter;
2995-
if (!string.IsNullOrEmpty(query))
2996-
req.Parameters["query"] = query;
2997-
if (!string.IsNullOrEmpty(naturalLanguageQuery))
2998-
req.Parameters["natural_language_query"] = naturalLanguageQuery;
2999-
if (passages != null)
3000-
req.Parameters["passages"] = passages;
3001-
if (!string.IsNullOrEmpty(aggregation))
3002-
req.Parameters["aggregation"] = aggregation;
3003-
if (count != null)
3004-
req.Parameters["count"] = count;
3005-
if (returnFields != null)
3006-
req.Parameters["return"] = returnFields != null && returnFields.Count > 0 ? string.Join(",", returnFields.ToArray()) : null;
3007-
if (offset != null)
3008-
req.Parameters["offset"] = offset;
3009-
if (sort != null)
3010-
req.Parameters["sort"] = sort != null && sort.Count > 0 ? string.Join(",", sort.ToArray()) : null;
3011-
if (highlight != null)
3012-
req.Parameters["highlight"] = highlight;
3013-
if (passagesFields != null)
3014-
req.Parameters["passages.fields"] = passagesFields != null && passagesFields.Count > 0 ? string.Join(",", passagesFields.ToArray()) : null;
3015-
if (passagesCount != null)
3016-
req.Parameters["passages.count"] = passagesCount;
3017-
if (passagesCharacters != null)
3018-
req.Parameters["passages.characters"] = passagesCharacters;
3019-
if (deduplicate != null)
3020-
req.Parameters["deduplicate"] = deduplicate;
3021-
if (!string.IsNullOrEmpty(deduplicateField))
3022-
req.Parameters["deduplicate.field"] = deduplicateField;
3023-
if (similar != null)
3024-
req.Parameters["similar"] = similar;
3025-
if(similarDocumentIds != null)
3026-
req.Parameters["similar.document_ids"] = similarDocumentIds != null && similarDocumentIds.Count > 0 ? string.Join(",", similarDocumentIds.ToArray()) : null;
3027-
if(similarFields != null)
3028-
req.Parameters["similar.fields"] = similarFields != null && similarFields.Count > 0 ? string.Join(",", similarFields.ToArray()) : null;
2997+
{
2998+
req.Headers.Add("X-Watson-Logging-Opt-Out", loggingOptOut.ToString());
2999+
}
3000+
req.Headers["Content-Type"] = "application/json";
3001+
3002+
QueryLarge queryLarge = new QueryLarge()
3003+
{
3004+
Filter = filter,
3005+
Query = query,
3006+
NaturalLanguageQuery = naturalLanguageQuery,
3007+
Passages = passages,
3008+
Aggregation = aggregation,
3009+
Count = count,
3010+
ReturnFields = (returnFields == null || returnFields.Count < 1) ? null : string.Join(", ", returnFields.ToArray()),
3011+
Offset = offset,
3012+
Sort = (sort == null || sort.Count < 1) ? null : string.Join(", ", sort.ToArray()),
3013+
Highlight = highlight,
3014+
PassagesFields = (passagesFields == null || passagesFields.Count < 1) ? null : string.Join(", ", passagesFields.ToArray()),
3015+
PassagesCount = passagesCount,
3016+
PassagesCharacters = passagesCharacters,
3017+
Deduplicate = deduplicate,
3018+
DeduplicateField = deduplicateField,
3019+
Similar = similar,
3020+
SimilarDocumentIds = (similarDocumentIds == null || similarDocumentIds.Count < 1) ? null : string.Join(", ", similarDocumentIds.ToArray()),
3021+
SimilarFields = (similarFields == null || similarFields.Count < 1) ? null : string.Join(", ", similarFields.ToArray()),
3022+
Bias = bias
3023+
};
3024+
3025+
fsData data = null;
3026+
_serializer.TrySerialize(queryLarge, out data);
3027+
string json = data.ToString().Replace('\"', '"');
3028+
req.Send = Encoding.UTF8.GetBytes(json);
3029+
30293030
req.OnResponse = OnQueryResponse;
30303031

30313032
RESTConnector connector = RESTConnector.GetConnector(Credentials, string.Format("/v1/environments/{0}/collections/{1}/query", environmentId, collectionId));

0 commit comments

Comments
 (0)