【发布时间】:2021-04-29 20:27:55
【问题描述】:
当我在 python 终端中为每条消息运行 main.py 时,不会创建新的会话 ID(旧用户)。但是当我每次为新消息部署它的服务器时,即使为旧用户创建一个新的 session_id ......
@app.route('/send_message/<string:user_message>',methods=['GET'])
def send_mesage(user_message):
try:
# Invoke a method
# Create Assistant service object.
authenticator = IAMAuthenticator('IcBMhVvVCh94QWP0u2DAfrT17-rmI9zGE4XzEoFdPDKa') # replace with API key
assistant = AssistantV2(
version = '2020-09-24',
authenticator = authenticator
)
assistant.set_service_url('https://api.us-south.assistant.watson.cloud.ibm.com/instances/8244c6b7-6d94-422f-9292-b7408871d24b')
assistant_id = 'c9866a42-652d-4f3e-a75c-0d3e3281bc75' # replace with assistant ID
message_input = {
'message_type:': 'text',
'text': user_message
}
#Create Session For every new User.
session_id = assistant.create_session(assistant_id=assistant_id).get_result()
print(json.dumps(session_id, indent=2))
while message_input['text'] != 'quit':
response = assistant.message(
assistant_id=assistant_id,
session_id=session_id['session_id'],
input=message_input
).get_result()
-------------
【问题讨论】:
标签: python api ibm-watson watson-assistant