1414
1515import com .ibm .cloud .sdk .core .http .Response ;
1616import com .ibm .cloud .sdk .core .http .ServiceCallback ;
17+ import com .ibm .cloud .sdk .core .security .Authenticator ;
18+ import com .ibm .cloud .sdk .core .security .IamAuthenticator ;
1719import com .ibm .watson .assistant .v1 .Assistant ;
1820import com .ibm .watson .assistant .v1 .model .Context ;
21+ import com .ibm .watson .assistant .v1 .model .MessageInput ;
1922import com .ibm .watson .assistant .v1 .model .MessageOptions ;
2023import com .ibm .watson .assistant .v1 .model .MessageResponse ;
2124import com .ibm .watson .tone_analyzer .v3 .ToneAnalyzer ;
@@ -29,28 +32,28 @@ public static void main(String[] args) throws Exception {
2932
3033 // instantiate the assistant service
3134 Authenticator assistantAuthenticator = new IamAuthenticator ("<iam_api_key>" );
32- Assistant assistantService = new Assistant ("2019-02-28" , assistantAuthenticator );
35+ final Assistant assistantService = new Assistant ("2019-02-28" , assistantAuthenticator );
3336
3437 // instantiate the tone analyzer service
3538 Authenticator toneAuthenticator = new IamAuthenticator ("<iam_api_key>" );
3639 ToneAnalyzer toneService = new ToneAnalyzer ("2017-09-21" , toneAuthenticator );
3740
3841 // workspace id
39- String workspaceId = "<workspace-id>" ;
42+ final String workspaceId = "<workspace-id>" ;
4043
4144 // maintain history in the context variable - will add a history variable to
4245 // each of the emotion, social
4346 // and language tones
44- boolean maintainHistory = false ;
47+ final boolean maintainHistory = false ;
4548
4649 /**
4750 * Input for the Assistant service: text (String): an input string (the user's conversation
4851 * turn) and context (Context): any context that needs to be maintained - either added by the
4952 * client app or passed in the response from the Assistant service on the previous conversation
5053 * turn.
5154 */
52- String text = "I am happy" ;
53- Context context = null ;
55+ final String text = "I am happy" ;
56+ final Context context = new Context () ;
5457
5558 // UPDATE CONTEXT HERE IF CONTINUING AN ONGOING CONVERSATION
5659 // set local context variable to the context from the last response from the
@@ -59,7 +62,7 @@ public static void main(String[] args) throws Exception {
5962 // com.ibm.watson.assistant.v1.model)
6063
6164 // async call to Tone Analyzer
62- ToneOptions toneOptions = new ToneOptions .Builder ().text (input ).build ();
65+ ToneOptions toneOptions = new ToneOptions .Builder ().text (text ).build ();
6366 toneService
6467 .tone (toneOptions )
6568 .enqueue (
@@ -68,9 +71,9 @@ public static void main(String[] args) throws Exception {
6871 public void onResponse (Response <ToneAnalysis > toneResponsePayload ) {
6972
7073 // update context with the tone data returned by the Tone Analyzer
71- context =
74+ context . setSystem (
7275 ToneDetection .updateUserTone (
73- context , toneResponsePayload .getResult (), maintainHistory );
76+ context , toneResponsePayload .getResult (), maintainHistory )) ;
7477
7578 // create input for message
7679 MessageInput input = new MessageInput ();
0 commit comments