File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
examples/conversation_tone_analyzer_integration Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1- import json
2-
31"""
42 * Copyright 2015 IBM Corp. All Rights Reserved.
53 *
2220 * https://www.ibm.com/watson/developercloud/doc/tone-analyzer/understanding-tone.shtml
2321 * These thresholds can be adjusted to client/domain requirements.
2422"""
23+
24+ import json
25+ import asyncio
26+
2527PRIMARY_EMOTION_SCORE_THRESHOLD = 0.5
2628WRITING_HIGH_SCORE_THRESHOLD = 0.75
2729WRITING_NO_SCORE_THRESHOLD = 0.0
@@ -98,6 +100,20 @@ def initUser():
98100 }
99101 }
100102
103+
104+
105+
106+ '''
107+ invokeToneAsync is an asynchronous function that calls the Tone Analyzer service
108+ @param conversationPayload json object returned by the Watson Conversation Service
109+ @param tone_analyzer an instance of the Watson Tone Analyzer service
110+ @returns the result of calling the tone_analyzer with the conversationPayload
111+ (which contains the user's input text)
112+ '''
113+ async def invokeToneAsync (conversationPayload , tone_analyzer ):
114+ return tone_analyzer .tone (text = conversationPayload ['input' ]['text' ])
115+
116+
101117'''
102118 updateEmotionTone updates the user emotion tone with the primary emotion - the emotion tone that has
103119 a score greater than or equal to the EMOTION_SCORE_THRESHOLD; otherwise primary emotion will be 'neutral'
You can’t perform that action at this time.
0 commit comments