2
1

More than 1 year has passed since last update.

Pythonでつくる対話システム_備忘録_Part01

Last updated at Posted at 2022-07-10

はじめに

現在は対話ロボットの研究に取り組んでいるが,対話システムを1から自分で実装できるようにするための勉強を始めようと思い,『Pythonでつくる対話システム』に取り組む.

環境

macOS: Big Sur(バージョン 11.6.7)
言語: Python 3.9.6
メッセンジャーアプリ: Telegram

第一章 対話システムを作るにあたって

『Pythonでつくる対話システム』ソースコード&データ配布とサポートページから必要なコードをダウンロードして動かす.

  1. Telegramのインストール
  2. Telegram上でBotの作成
  3. アクセストークンを取得
  4. telegram_bot.pyに取得したアクセストークンを貼り付け
  5. echo_system.py(おうむ返しをするプログラム)を起動
  6. エラーの修正
    サンプルコードをダウンロードしたまま動かしたが,以下のエラーが発生.
​​No error handlers are registered, logging exception.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telegram/ext/dispatcher.py", line 557, in process_update
    handler.handle_update(update, self, check, context)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telegram/ext/handler.py", line 199, in handle_update
    return self.callback(update, context)
  File "/Users/dsbook/telegram_bot.py", line 20, in message
    input = {'utt': update.message.text, 'sessionId': str(update.message.from_user.id)}
AttributeError: 'CallbackContext' object has no attribute 'message'

telegram_bot.py中のコールバック関数において,引数の順番が間違っていたために発生している.
参考ページ:AttributeError: 'CallbackContext' object has no attribute 'message'

telegram_bot.py
def start(self, bot, update):
def message(self, bot, update):

正しくは以下のようにする.

telegram_bot.py
def start(self, update, bot):
def message(self, update, bot):

動作成功

Screenshot_20220710-170945.png

おわりに

今回はチュートリアルとして,おうむ返しを行うTelegramのチャットボットを実際に動かしてみた.次回は第二章の状態遷移に基づくタスク指向型対話システムに取り組む.

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1