【问题标题】:For every new message(old user) a new session id is created although i am not deleting previous session id. Watson Assisstant V2 API尽管我没有删除以前的会话 ID,但对于每条新消息(旧用户)都会创建一个新的会话 ID。 Watson 助手 V2 API
【发布时间】: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


    【解决方案1】:

    我不得不在函数之外编写代码..

      # 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
    

    【讨论】:

      猜你喜欢
      • 2015-10-04
      • 2019-06-02
      • 2014-04-25
      • 2011-01-19
      • 2013-07-26
      • 2021-04-21
      • 2013-11-13
      • 2016-02-03
      • 1970-01-01
      相关资源
      最近更新 更多