def main_func(text): proto = Unmo('manachan') try: response = proto.dialogue(text, 1) except IndexError as error: return '{}: {}'.format(type(error).__name__, str(error)), '警告: 辞書が空です。(Responder: {})'.format(proto.responder_name) else: return '{response}'.format(response=response)
def message(line_event): proto = Unmo('proto') text = line_event.message.text input_text = text.rstrip() response = proto.dialogue(input_text) line_bot_api.reply_message(line_event.reply_token, TextSendMessage(text=response))
def handle_message(event): #if event.reply_token == "00000000000000000000000000000000": #return if __name__ == '__main__': Lala = Unmo('Lala') #while True: #text = TextMessage response = Lala.dialogue(text=event.message.text) line_bot_api.reply_message( event.reply_token, TextSendMessage(text=response)) #ここでオウム返しのメッセージを返します。 gc.collect() Lala.save()
def handle_message(message): print('received message: ' + message, file=sys.stderr) send(message, broadcast=True) proto = Unmo('proto') try: response = proto.dialogue(message) except IndexError as error: print('{}: {}'.format(type(error).__name__, str(error))) print('Error: Dictionary is empty. (Responder: {})'.format(proto.responder_name)) else: print('{prompt}{response}'.format(prompt=build_prompt(proto), response=response)) print('response message: ' + response, file=sys.stderr) prompt_response = '{prompt}{response}'.format(prompt=build_prompt(proto), response=response) send(prompt_response, broadcast=True) proto.save()
# -*- coding: utf-8 -*- from unmo import Unmo from IPython.display import display, clear_output from PIL import Image import os import random from datetime import datetime from time import sleep noby = Unmo('noby') img_dir = '../KOISURU_PROGRAM/sample/emotion/bmps/' text = '*******************************************************' log = [] def now(): return datetime.now().strftime("[%Y/%m/%d %H:%M:%S] ") def prompt(unmo): return f"{unmo.name}:{unmo.responder.name} > " def draw_image(file_name): clear_output(wait=True) image_file = img_dir + file_name display(Image.open(image_file)) sleep(0.1)
# Python初心者に送る「人工知能の作り方」 # http://sandmark.hateblo.jp/entry/2017/10/07/141339 # に掲載されたコードを写経して勉強する。 from unmo import Unmo def build_prompt(unmo): """ AIインスタンスを取り、AIとResponderの名前を整形して返す """ return '{name}:{responder}> '.format(name=unmo.name, responder=unmo.responder_name) if __name__=='__main__': print('Unmo System prototype : proto') proto= Unmo('proto') while True: text = input('> ') if not text: break response = proto.dialogue(text) print('{prompt}{response}'.format(prompt=build_prompt(proto), response=response))
from unmo import Unmo def build_prompt(unmo): """ AIインスタンスを取り、AIとResponderの名前を整形して返す """ return '{name}:{responder}> '.format(name=unmo.name, responder=unmo.responder_name) if __name__ == '__main__': print('Unmo System prototype : proto') proto = Unmo('proto') while True: text = input('> ') if not text: break try: response = proto.dialogue(text) except IndexError as error: print('{}: {}'.format(type(error).__name__, str(error))) print('警告: 辞書が空です。(Responder: {})'.format(proto.responder_name)) else: print('{prompt}{response}'.format(prompt=build_prompt(proto), response=response)) proto.save() # 追加
# -*- coding: utf-8 -*- import os, sys sys.path.append(os.path.dirname(os.path.abspath(__file__))) from unmo import Unmo def prompt(unmo): return f"{unmo.name}:{unmo.responder.name} > " print('Unmo System prototype : proto') proto = Unmo('proto') while True: print('> ', end='') input_text = input() input_text = input_text.rstrip() if input_text == '': break response = proto.dialogue(input_text) print(prompt(proto) + response) print('shutdown')
from unmo import Unmo def build_prompt(unmo): """AIインスタンスを取り、AIとResponderの名前を整形して返す""" return "{name}:{responder}> ".format(name=unmo.name, responder=unmo.responder_name) if __name__ == "__main__": print("Unmo System prototype : proto") proto = Unmo("proto") while True: text = input("> ") if not text: break response = proto.dialogue(text) print("{prompt}{response}".format(prompt=build_prompt(proto), response=response))
# coding:utf-8 from unmo import Unmo def build_prompt(unmo): """AIインスタンスを取り,AIとResponderの名前を整形して返す""" return '{name}:{responder}> '.format(name=unmo.name, responder=unmo.responder_name) if __name__ == '__main__': print('Unmo System prototype : girlfriend') proto = Unmo('girlfriend') while True: text = input('> ') if not text: break try: response = proto.dialogue(text) except IndexError as error: print('{}: {}'.format(type(error).__name__, str(error))) print('警告:辞書が空です.(Responder: {})'.format(proto.responder_name)) else: print('{prompt}{response}'.format(prompt=build_prompt(proto), response=response)) proto.save()
from unmo import Unmo def build_prompt(unmo): """AIインスタンスを取り、AIとResponderの名前を整形して返す""" return '{name}:{responder}> '.format(name=unmo.name, responder=unmo.responder_name) if __name__ == '__main__': print('Unmo System prototype : proto') proto = Unmo('proto') markov_training = 0 while True: if markov_training == 1: markov_tr_list = markov_tr_list[1:] if len(markov_tr_list) == 0: markov_training = 0 print('markov training is done!') else: text = markov_tr_list[0] print('traiing :', text) if markov_training != 1: text = input('> ') if text == 'train markov': print('ファイル名を教えて下さい') path = input('path = ')