Skip to content

Commit b344535

Browse files
committed
added an asynchronous call to tone analyzer
1 parent 6797bc9 commit b344535

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

examples/conversation_tone_analyzer_integration/tone_detection.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
"""
42
* Copyright 2015 IBM Corp. All Rights Reserved.
53
*
@@ -22,6 +20,10 @@
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+
2527
PRIMARY_EMOTION_SCORE_THRESHOLD = 0.5
2628
WRITING_HIGH_SCORE_THRESHOLD = 0.75
2729
WRITING_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'

0 commit comments

Comments
 (0)