Created
December 22, 2021 06:37
-
-
Save VincentK16/bc1a22dd6d2329741d4674db4b9f24a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from ibm_watson import AssistantV2 | |
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator | |
authenticator = IAMAuthenticator( | |
'<replace with your own IBM Watson Assistant API Key>') | |
assistant = AssistantV2( | |
version='2020-09-24', | |
authenticator=authenticator | |
) | |
assistant.set_service_url( | |
'https://api.us-south.assistant.watson.cloud.ibm.com/') | |
create = assistant.create_session(assistant_id='<replace with assistant-id>').get_result() | |
#context = {} | |
print(create) | |
value = create["session_id"] | |
print(value) | |
while (True): | |
user_input = input("Type in your questions:") | |
response = assistant.message(assistant_id='<replace with assistant-id>', session_id=value, input={'message_type': 'text', 'text': user_input }).get_result() | |
print(response) | |
text = response["output"]["generic"][0]["text"] | |
print(text) | |
#if len (response["output"]["generic"]) > 1: | |
# text = response["output"]["generic"][0]["text"] + ' ' + response["output"]["generic"][1]["text"] | |
#else: | |
# text = response["output"]["generic"][0]["text"] | |
#print(text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment