建立conda環境
> conda create --name chatterbot python=3.6
啟動環境
> conda activate chatterbot
安裝chatterbot及語料庫
> pip install chatterbot
> pip install chatterbot_corpus
安裝spacy
* 沒有安裝的話,執行範例的時候會出現錯誤
> pip install spacy==2.1.8
> python -m spacy download en
範例
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')
trainer = ListTrainer(chatbot)
trainer.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')
print(response)
參考網站:https://chatterbot.readthedocs.io/en/stable/examples.html
沒有留言:
張貼留言