1
1
/**
2
- * (C) Copyright IBM Corp. 2018 , 2020.
2
+ * (C) Copyright IBM Corp. 2019 , 2020.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -601,5 +601,86 @@ private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.R
601
601
if ( ( ( RequestObject < object > ) req ) . Callback != null )
602
602
( ( RequestObject < object > ) req ) . Callback ( response , resp . Error ) ;
603
603
}
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
+ }
604
685
}
605
686
}
0 commit comments