public void Tone() { IamConfig config = new IamConfig( apikey: apikey ); ToneAnalyzerService service = new ToneAnalyzerService(versionDate, config); service.SetEndpoint(url); ToneInput toneInput = new ToneInput() { Text = "Hello! Welcome to IBM Watson! How can I help you?" }; var result = service.Tone( toneInput: toneInput, contentType: "text/html", sentences: true, contentLanguage: "en-US", acceptLanguage: "en-US" ); Console.WriteLine(result.Response); }
public void ToneChat() { IamConfig config = new IamConfig( apikey: apikey ); ToneAnalyzerService service = new ToneAnalyzerService(versionDate, config); service.SetEndpoint(url); var utterances = new List <Utterance>() { new Utterance() { Text = "Hello! Welcome to IBM Watson! How can I help you?", User = "******" } }; var result = service.ToneChat( utterances: utterances, contentLanguage: "en-US", acceptLanguage: "en-US" ); Console.WriteLine(result.Response); }
public static void Main(string[] args) { string credentials = string.Empty; #region Get Credentials string _endpoint = string.Empty; string _username = string.Empty; string _password = string.Empty; if (string.IsNullOrEmpty(credentials)) { var parentDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName; string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json"; if (File.Exists(credentialsFilepath)) { try { credentials = File.ReadAllText(credentialsFilepath); credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES"); } catch (Exception e) { throw new Exception(string.Format("Failed to load credentials: {0}", e.Message)); } VcapCredentials vcapCredentials = JsonConvert.DeserializeObject <VcapCredentials>(credentials); var vcapServices = JObject.Parse(credentials); Credential credential = vcapCredentials.GetCredentialByname("tone-analyzer-sdk")[0].Credentials; _endpoint = credential.Url; _username = credential.Username; _password = credential.Password; } else { Console.WriteLine("Credentials file does not exist. Please define credentials."); _username = ""; _password = ""; _endpoint = ""; } } #endregion var versionDate = "2016-05-19"; ToneAnalyzerService _toneAnalyzer = new ToneAnalyzerService(_username, _password, versionDate); _toneAnalyzer.SetEndpoint(_endpoint); // Test PostTone ToneInput toneInput = new ToneInput() { Text = "How are you doing? My name is Taj!" }; var postToneResult = _toneAnalyzer.Tone(toneInput, "application/json", null); Console.WriteLine(string.Format("post tone result: {0}", JsonConvert.SerializeObject(postToneResult, Formatting.Indented))); // Test ToneChat ToneChatInput toneChatInput = new ToneChatInput() { Utterances = new List <Utterance>() { new Utterance() { Text = "Hello how are you?" } } }; var toneChatResult = _toneAnalyzer.ToneChat(toneChatInput); Console.WriteLine(string.Format("tone chat result: {0}", JsonConvert.SerializeObject(toneChatResult, Formatting.Indented))); Console.ReadKey(); }