如何与聊天机器人进行持续对话?

2024-06-07 22:18:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经成功地在python上实现了我的聊天机器人美国石油学会对于一个HTTP响应,然后解析值基本上得到我想要的部分。 问题是我想要一个持续的对话,例如,假设我说hi,bot说hello,python代码是第一次运行,那么我必须再次运行它,问你怎么样。在

我真正想要的是与bot进行对话,不管我在一次运行python代码时可以发送和接收多少个请求。在


Tags: 代码httphellobot机器人hi对话学会
1条回答
网友
1楼 · 发布于 2024-06-07 22:18:25

这是一个可能的程序结构-

# Initialize your program, lots of code here, get token/id, setup other variables

def process_input(input_text):
    # clean input text
    # get response from web bot
    response = requests.get('url')
    # clean response and then print it/redirect it
    return response


if __name__=='__main__':
    while True:
        user_input = raw_input()
        print(process_input(user_input))
        # also add some terminal conditions like if user types 'bye', break while loop and exit

相关问题 更多 >

    热门问题