use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class AssistantToneAnalyzerIntegrationExample method main.
public static void main(String[] args) throws Exception {
// instantiate the assistant service
Authenticator assistantAuthenticator = new IamAuthenticator("<iam_api_key>");
final Assistant assistantService = new Assistant("2019-02-28", assistantAuthenticator);
// instantiate the tone analyzer service
Authenticator toneAuthenticator = new IamAuthenticator("<iam_api_key>");
ToneAnalyzer toneService = new ToneAnalyzer("2017-09-21", toneAuthenticator);
// workspace id
final String workspaceId = "<workspace-id>";
// maintain history in the context variable - will add a history variable to
// each of the emotion, social
// and language tones
final boolean maintainHistory = false;
/**
* Input for the Assistant service: text (String): an input string (the user's conversation
* turn) and context (Context): any context that needs to be maintained - either added by the
* client app or passed in the response from the Assistant service on the previous conversation
* turn.
*/
final String text = "I am happy";
final Context context = new Context();
// UPDATE CONTEXT HERE IF CONTINUING AN ONGOING CONVERSATION
// set local context variable to the context from the last response from the
// Assistant Service
// (see the getContext() method of the MessageResponse class in
// com.ibm.watson.assistant.v1.model)
// async call to Tone Analyzer
ToneOptions toneOptions = new ToneOptions.Builder().text(text).build();
toneService.tone(toneOptions).enqueue(new ServiceCallback<ToneAnalysis>() {
@Override
public void onResponse(Response<ToneAnalysis> toneResponsePayload) {
// update context with the tone data returned by the Tone Analyzer
context.setSystem(ToneDetection.updateUserTone(context, toneResponsePayload.getResult(), maintainHistory));
// create input for message
MessageInput input = new MessageInput();
input.setText(text);
// call Assistant Service with the input and tone-aware context
MessageOptions messageOptions = new MessageOptions.Builder(workspaceId).input(input).context(context).build();
assistantService.message(messageOptions).enqueue(new ServiceCallback<MessageResponse>() {
@Override
public void onResponse(Response<MessageResponse> response) {
System.out.println(response.getResult());
}
@Override
public void onFailure(Exception e) {
}
});
}
@Override
public void onFailure(Exception e) {
}
});
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
NaturalLanguageClassifier service = new NaturalLanguageClassifier(authenticator);
ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId("<classifierId>").text("Is it sunny?").build();
Classification classification = service.classify(classifyOptions).execute().getResult();
System.out.println(classification);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class ToneAnalyzerExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
ToneAnalyzer service = new ToneAnalyzer("2017-09-21", authenticator);
String text = "I know the times are difficult! Our sales have been " + "disappointing for the past three quarters for our data analytics " + "product suite. We have a competitive data analytics product " + "suite in the industry. But we need to do our job selling it! " + "We need to acknowledge and fix our sales challenges. " + "We can’t blame the economy for our lack of execution! " + "We are missing critical sales opportunities. " + "Our product is in no way inferior to the competitor products. " + "Our clients are hungry for analytical tools to improve their " + "business outcomes. Economy has nothing to do with it.";
// Call the service and get the tone
ToneOptions toneOptions = new ToneOptions.Builder().text(text).build();
ToneAnalysis tone = service.tone(toneOptions).execute().getResult();
System.out.println(tone);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class CompareComplyTest method constructClientService.
public void constructClientService() throws Throwable {
final String serviceName = "testService";
// set mock values for global params
String version = "testString";
final Authenticator authenticator = new NoAuthAuthenticator();
compareComplyService = new CompareComply(version, serviceName, authenticator);
String url = server.url("/").toString();
compareComplyService.setServiceUrl(url);
}
use of com.ibm.cloud.sdk.core.security.Authenticator in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsIT method setUp.
/**
* Sets up the tests.
*
* @throws Exception the exception
*/
/*
* (non-Javadoc)
*
* @see com.ibm.watson.common.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("PERSONALITY_INSIGHTS_APIKEY");
Assert.assertNotNull("PERSONALITY_INSIGHTS_APIKEY is not defined", apiKey);
Authenticator authenticator = new IamAuthenticator(apiKey);
service = new PersonalityInsights(VERSION, authenticator);
service.setServiceUrl(System.getenv("PERSONALITY_INSIGHTS_URL"));
service.setDefaultHeaders(getDefaultHeaders());
}
Aggregations