class ElizaConsole: def __init__(self, config_file): self.HISTORY_FILENAME = os.path.expanduser('~/.eliza_history') self.init_history(self.HISTORY_FILENAME) self.eliza = Eliza(config_file) def run(self): print(self.eliza.initial()) while True: try: sent = input('> ') except EOFError: break output = self.eliza.respond(sent) if output is None: break print(output) print(self.eliza.final()) def init_history(self, histfile): readline.parse_and_bind("tab: complete") if hasattr(readline, "read_history_file"): try: readline.read_history_file(histfile) except IOError: pass atexit.register(self.save_history, histfile) def save_history(self, histfile): readline.set_history_length(1000) readline.write_history_file(histfile)
#!/usr/bin/env python3 from eliza import Eliza eliza = Eliza() eliza.load('doctor-fr.txt') print(eliza.initial()) while True: said = input('> ') response = eliza.respond(said) if response is None: break print(response) print(eliza.final())