1.安装python Python Release Python 3.8.8 | Python.orgThe official home of the Python Programming Languagehttps://www.python.org/downloads/release/python-388/2.命令行 查看python是否安装成功
3.创建一个python项目,并打开
4.先更新pip版本,防止版本低更新不了
pip install --upgrade pip
5.依次安装依赖
pip install chatterbot==1.0.4
pip install chatterbot-corpus #语料库
pip install spacy
6.创建test.py测试实例
from chatterbot import ChatBot
# naming the ChatBot calculator
# using mathematical evaluation logic
# the calculator AI will not learn with the user input
Bot = ChatBot(name = 'Calculator',
read_only = True,
logic_adapters = ["chatterbot.logic.MathematicalEvaluation"],
storage_adapter = "chatterbot.storage.SQLStorageAdapter")
# clear the screen and start the calculator
print('\033c')
print("Hello, I am a calculator. How may I help you?")
while (True):
# take the input from the user
user_input = input("me: ")
# check if the user has typed quit to exit the prgram
if user_input.lower() == 'quit':
print("Exiting")
break
# otherwise, evaluate the user input
# print invalid input if the AI is unable to comprehend the input
try:
response = Bot.get_response(user_input)
print("Calculator:", response)
except:
print("Calculator: Please enter valid input.")
6.运行代码,
6.1 可能会报缺少 pytz 依赖,输入pip install pytz 下载依赖
6.2 可能会报 语法错误,打开 compat.py 将 time.clock
为:time.perf_counter()
重新运行即可成功!