Skip to content

Commit 52f0cf9

Browse files
committed
feat(AssistantV2): Add support for BulkClassify and refactor context skill system
BREAKING CHANGE: MessageContextSkill
1 parent 20e42e3 commit 52f0cf9

35 files changed

+887
-59
lines changed

Scripts/Services/Assistant/V1/AssistantService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/DialogNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/DialogNodeOutput.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/DialogNodeOutputGeneric.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/DialogSuggestion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/Pagination.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/RuntimeResponseGeneric.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V1/Model/Workspace.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

Scripts/Services/Assistant/V2/AssistantService.cs

+82-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2018, 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -601,5 +601,86 @@ private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.R
601601
if (((RequestObject<object>)req).Callback != null)
602602
((RequestObject<object>)req).Callback(response, resp.Error);
603603
}
604+
/// <summary>
605+
/// Identify intents and entities in multiple user utterances.
606+
///
607+
/// Send multiple user inputs to a dialog skill in a single request and receive information about the intents
608+
/// and entities recognized in each input. This method is useful for testing and comparing the performance of
609+
/// different skills or skill versions.
610+
///
611+
/// This method is available only with Premium plans.
612+
/// </summary>
613+
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
614+
/// <param name="skillId">Unique identifier of the skill. To find the skill ID in the Watson Assistant user
615+
/// interface, open the skill settings and click **API Details**.</param>
616+
/// <param name="input">An array of input utterances to classify. (optional)</param>
617+
/// <returns><see cref="BulkClassifyResponse" />BulkClassifyResponse</returns>
618+
public bool BulkClassify(Callback<BulkClassifyResponse> callback, string skillId, List<BulkClassifyUtterance> input = null)
619+
{
620+
if (callback == null)
621+
throw new ArgumentNullException("`callback` is required for `BulkClassify`");
622+
if (string.IsNullOrEmpty(skillId))
623+
throw new ArgumentNullException("`skillId` is required for `BulkClassify`");
624+
625+
RequestObject<BulkClassifyResponse> req = new RequestObject<BulkClassifyResponse>
626+
{
627+
Callback = callback,
628+
HttpMethod = UnityWebRequest.kHttpVerbPOST,
629+
DisableSslVerification = DisableSslVerification
630+
};
631+
632+
foreach (KeyValuePair<string, string> kvp in customRequestHeaders)
633+
{
634+
req.Headers.Add(kvp.Key, kvp.Value);
635+
}
636+
637+
ClearCustomRequestHeaders();
638+
639+
foreach (KeyValuePair<string, string> kvp in Common.GetSdkHeaders("conversation", "V2", "BulkClassify"))
640+
{
641+
req.Headers.Add(kvp.Key, kvp.Value);
642+
}
643+
644+
req.Parameters["version"] = VersionDate;
645+
req.Headers["Content-Type"] = "application/json";
646+
req.Headers["Accept"] = "application/json";
647+
648+
JObject bodyObject = new JObject();
649+
if (input != null && input.Count > 0)
650+
bodyObject["input"] = JToken.FromObject(input);
651+
req.Send = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(bodyObject));
652+
653+
req.OnResponse = OnBulkClassifyResponse;
654+
655+
Connector.URL = GetServiceUrl() + string.Format("/v2/skills/{0}/workspace/bulk_classify", skillId);
656+
Authenticator.Authenticate(Connector);
657+
658+
return Connector.Send(req);
659+
}
660+
661+
private void OnBulkClassifyResponse(RESTConnector.Request req, RESTConnector.Response resp)
662+
{
663+
DetailedResponse<BulkClassifyResponse> response = new DetailedResponse<BulkClassifyResponse>();
664+
foreach (KeyValuePair<string, string> kvp in resp.Headers)
665+
{
666+
response.Headers.Add(kvp.Key, kvp.Value);
667+
}
668+
response.StatusCode = resp.HttpResponseCode;
669+
670+
try
671+
{
672+
string json = Encoding.UTF8.GetString(resp.Data);
673+
response.Result = JsonConvert.DeserializeObject<BulkClassifyResponse>(json);
674+
response.Response = json;
675+
}
676+
catch (Exception e)
677+
{
678+
Log.Error("AssistantService.OnBulkClassifyResponse()", "Exception: {0}", e.ToString());
679+
resp.Success = false;
680+
}
681+
682+
if (((RequestObject<BulkClassifyResponse>)req).Callback != null)
683+
((RequestObject<BulkClassifyResponse>)req).Callback(response, resp.Error);
684+
}
604685
}
605686
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
20+
21+
namespace IBM.Watson.Assistant.V2.Model
22+
{
23+
/// <summary>
24+
/// BulkClassifyOutput.
25+
/// </summary>
26+
public class BulkClassifyOutput
27+
{
28+
/// <summary>
29+
/// The user input utterance to classify.
30+
/// </summary>
31+
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
32+
public BulkClassifyUtterance Input { get; set; }
33+
/// <summary>
34+
/// An array of entities identified in the utterance.
35+
/// </summary>
36+
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
37+
public List<RuntimeEntity> Entities { get; set; }
38+
/// <summary>
39+
/// An array of intents recognized in the utterance.
40+
/// </summary>
41+
[JsonProperty("intents", NullValueHandling = NullValueHandling.Ignore)]
42+
public List<RuntimeIntent> Intents { get; set; }
43+
}
44+
}

Scripts/Services/Assistant/V2/Model/BulkClassifyOutput.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
20+
21+
namespace IBM.Watson.Assistant.V2.Model
22+
{
23+
/// <summary>
24+
/// BulkClassifyResponse.
25+
/// </summary>
26+
public class BulkClassifyResponse
27+
{
28+
/// <summary>
29+
/// An array of objects that contain classification information for the submitted input utterances.
30+
/// </summary>
31+
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
32+
public List<BulkClassifyOutput> Output { get; set; }
33+
}
34+
}

Scripts/Services/Assistant/V2/Model/BulkClassifyResponse.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using Newtonsoft.Json;
19+
20+
namespace IBM.Watson.Assistant.V2.Model
21+
{
22+
/// <summary>
23+
/// The user input utterance to classify.
24+
/// </summary>
25+
public class BulkClassifyUtterance
26+
{
27+
/// <summary>
28+
/// The text of the input utterance.
29+
/// </summary>
30+
[JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
31+
public string Text { get; set; }
32+
}
33+
}

Scripts/Services/Assistant/V2/Model/BulkClassifyUtterance.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
20+
21+
namespace IBM.Watson.Assistant.V2.Model
22+
{
23+
/// <summary>
24+
/// Routing or other contextual information to be used by target service desk systems.
25+
/// </summary>
26+
public class DialogNodeOutputConnectToAgentTransferInfo
27+
{
28+
/// <summary>
29+
/// Gets or Sets Target
30+
/// </summary>
31+
[JsonProperty("target", NullValueHandling = NullValueHandling.Ignore)]
32+
public Dictionary<string, Dictionary<string, object>> Target { get; set; }
33+
}
34+
}

Scripts/Services/Assistant/V2/Model/DialogNodeOutputConnectToAgentTransferInfo.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scripts/Services/Assistant/V2/Model/MessageContextSkill.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2018, 2020.
2+
* (C) Copyright IBM Corp. 2019, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,6 @@ public class MessageContextSkill
3535
/// System context data used by the skill.
3636
/// </summary>
3737
[JsonProperty("system", NullValueHandling = NullValueHandling.Ignore)]
38-
public Dictionary<string, object> System { get; set; }
38+
public MessageContextSkillSystem System { get; set; }
3939
}
4040
}

Scripts/Services/Assistant/V2/Model/MessageContextSkillSystem.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2018, 2020.
2+
* (C) Copyright IBM Corp. 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,10 +26,10 @@ namespace IBM.Watson.Assistant.V2.Model
2626
public class MessageContextSkillSystem: DynamicModel<object>
2727
{
2828
/// <summary>
29-
/// An encoded string representing the current conversation state. By saving this value and then sending it in
30-
/// the context of a subsequent message request, you can restore the conversation to the same state. This can be
31-
/// useful if you need to return to an earlier point in the conversation. If you are using stateful sessions,
32-
/// you can also use a stored state value to restore a paused conversation whose session has expired.
29+
/// An encoded string that represents the current conversation state. By saving this value and then sending it
30+
/// in the context of a subsequent message request, you can return to an earlier point in the conversation. If
31+
/// you are using stateful sessions, you can also use a stored state value to restore a paused conversation
32+
/// whose session is expired.
3333
/// </summary>
3434
[JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)]
3535
public string State { get; set; }

Scripts/Services/Assistant/V2/Model/MessageRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2018, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)