ELIZA 的 Python 实现. ELIZA 是基于规则的聊天机器人, 用于扮演一个心理医生.
规则文件在 doctor.txt
. 如何写规则文件见 rule.md
从文件运行:
$ python eliza.py
How do you do. Please tell me your problem.
> I would like to have a chat bot.
You say you would like to have a chat bot ?
> bye
Goodbye. Thank you for talking to me.
作为包使用:
import eliza
eliza = eliza.Eliza()
eliza.load('doctor.txt')
print(eliza.initial())
while True:
said = input('> ')
response = eliza.respond(said)
if response is None:
break
print(response)
print(eliza.final())
源代码参考github:wadetb/eliza