Skip to content

Commit 6797bc9

Browse files
committed
added an asynchronous call to conversation that includes tone
1 parent b38c4f3 commit 6797bc9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

examples/conversation_tone_analyzer_integration/tone_conversation_integration.v1.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import os
33
from dotenv import load_dotenv, find_dotenv
4+
import asyncio
5+
46
from watson_developer_cloud import ConversationV1
57
from watson_developer_cloud import ToneAnalyzerV3
68

@@ -54,4 +56,20 @@ def invokeToneConversation (payload, maintainToneHistoryInContext):
5456
response = conversation.message(workspace_id=workspace_id, message_input=conversation_payload['input'], context=conversation_payload['context'])
5557
print(json.dumps(response, indent=2))
5658

57-
invokeToneConversation(payload,maintainToneHistoryInContext);
59+
async def invokeToneConversationAsync (payload, maintainToneHistoryInContext):
60+
tone = await tone_detection.invokeToneAsync(payload,tone_analyzer)
61+
conversation_payload = tone_detection.updateUserTone(payload, tone, maintainToneHistoryInContext)
62+
response = conversation.message(workspace_id=workspace_id, message_input=conversation_payload['input'], context=conversation_payload['context'])
63+
print(json.dumps(response, indent=2))
64+
65+
66+
# how to invoke both versions of the tone aware calls to conversation
67+
68+
# synchronous call to conversation with tone included in the context
69+
invokeToneConversation(payload,maintainToneHistoryInContext)
70+
71+
# asynchronous call to conversation with tone included in the context
72+
loop = asyncio.get_event_loop()
73+
loop.run_until_complete(invokeToneConversationAsync(payload,maintainToneHistoryInContext))
74+
loop.close()
75+

0 commit comments

Comments
 (0)