Embeddable AI

 View Only

Extract Watson Assistant Chat Logs

By Tim Lai posted Fri September 25, 2020 04:56 PM

  
As you use Watson Assistant, your chat statistics and user chat logs can be viewed on the Analytics tab within your Skill.  These chat logs are kept for 30 days on the Watson Assistant Plus Plan and 90 days on the Premium Plan.  Often times, customers may want to extract the logs to a custom database or analytics tool for historical reporting or a custom dashboard.  The Watson Assistant Logs API is available for you to export these chat logs from a variety of client application and languages including (but not limited to) REST Clients, Python, Jupyter Notebooks, and Java:

REST API
The Watson Assistant REST API documentation can be found here: https://cloud.ibm.com/apidocs/assistant/assistant-v1?code=java#listlogs

There are some code snippet examples in Curl, Java, Node, Python, etc.

Python

If you’re using Python, IBM has some reference scripts you can start with from this github repo: https://github.com/cognitive-catalyst/WA-Testing-Tool/tree/master/log_analytics

Jupyter Notebook

There are also Jupyter Notebooks which utilize the Python scripts above such as this example which extracts chat logs into a CSV file or custom DB2 database, and uses Cognos Analytics for a custom dashboard.  https://github.com/preethm/watson-assistant-metrics-notebook

 
Java

If you are writing a Java client, you can obtain the Watson Java SDK here: https://github.com/watson-developer-cloud/java-sdk

Here is an example of issuing a query to extract all logs from a Skill after a specified date, and using Watson convenience classes to retrieve various response fields such as request time stamp, response time stamp, the user utterance text, the Watson Assistant response text, conversation id, turn counter, and user id. 

IamAuthenticator authenticator = new IamAuthenticator(API_KEY);

// Obtain the API Key from your Watson Assistant credentials tab

Assistant assistant = new Assistant(2020-04-01”, authenticator);

assistant.setServiceUrl(https://gateway.watsonplatform.net/assistant/api");

             

String filter = “language::en,response_timestamp>=2020-08-26”;

ListLogsOptions options = new ListLogsOptions.Builder(SKILL_ID).filter(filter).build();

// Obtain the Skill ID from your Watson Assistant Skill

             

LogCollection response = assistant.listLogs(options).execute().getResult();

List<Log> logs = response.getLogs();

Iterator iterator = logs.iterator();

while (iterator.hasNext()) {

       Log log = (Log) iterator.next();                    

       String requestTimeStamp = log.getRequestTimestamp();

       String responseTimeStamp = log.getResponseTimestamp();      

      

       MessageResponse mr = log.getResponse();

       String inputText = mr.getInput().getText();

 

       OutputData od = mr.getOutput(); 

       String outputText = od.getText().get(0);     

                    

       Context context = mr.getContext();

       String conversationID = context.getConversationId();

                          

       SystemResponse sr = context.getSystem();

       String turnCounter = sr.get("dialog_turn_counter").toString();                      

       MessageContextMetadata mcm = context.getMetadata();                     

       String userID = userID = mcm.userId();                                               

}

 

Optionally if you want to extract the chat logs for a specific Assistant, you can append the Assistant ID in the query string such as the following:

String filter = “language::en,response_timestamp>=2020-08-26assistant_id::"+ASSISTANT_ID;

 
A full description of all the available Watson Assistant filter criteria can be found here: https://cloud.ibm.com/docs/assistant?topic=assistant-filter-reference


Overall, you can see there are various methods to extract your Watson Assistant chat logs to an offline repository for reporting and analysis. 


The full Java sample class file for the example above can be downloaded here: https://github.com/public-data-and-ai-csm/Public-DataAI-Assets/tree/master/WatsonAssistant/WatsonAssistantExtractChatLogs

 


#BuildwithWatsonApps
#EmbeddableAI
0 comments
21 views

Permalink