今回は、enebular で作ったシンプルな HTTP リクエストのフローで、りんな API の、会話の文脈を踏まえて回答を提案する API 、Session Based Scoring API を体験してみます。
(本記事の内容は執筆時 [2022/10] の情報に基づいて作成しています)
rinna Developers で API を使うには
rinna Developers で API を使うには、2022/10 現在、こちらの記事を参考にアカウント登録して各 API サブスクリプション申請すれば使えるようになります。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_01.png)
rinna Developers ページ
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_02.png)
rinna Developersの API 一覧を見てみます。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_03.png)
2022/10 現在、いろいろ API ありますね。今回は Session Based Scoring API をやってみます。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_04.png)
Session Based Scoring API とは、会話の文脈を踏まえて回答を提案する API とのこと。
サブスクリプション登録
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_05.png)
2022/10 現在の手順ですが、API の使い方ページからサブスクリプション登録します。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_06.png)
サブスクリプション登録完了してプロフィール画面でサブスクリプションキー詳細が出てきました。
今回はプライマリキーを使ってみます。メモしておきましょう。
API 仕様ページ
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_07.png)
API 仕様ページを見て POST リクエストの仕様を把握します。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_08.png)
API をすぐ試せるサイト内蔵の Try it ツールで、より詳細に送るべきプライマリキーを入れるヘッダー情報 Ocp-Apim-Subscription-Key 値がわかりました。
今回の Discover Flow
今回のフローはこちらです。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_09.png)
こちらのフローを自分のプロジェクトにインポートします。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_10.png)
インポート出来たら編集ボタンをクリックします。
inject ノードから送るサンプル文言
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_11.png)
inject ノードから送るサンプル文言は、API ページにあるサンプルをそのまま利用しています。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_12.png)
以下、 JSON の詳細です。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_13.png)
dialogHistory という前の会話の履歴を元に、responses の中身から次の会話を判断してくれる感じですね。
りんな API 設定と書かれている change ノードの設定
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_14.png)
りんな API 設定と書かれている change ノードの設定です。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_15.png)
API 仕様で把握した POST リクエストの送り先と、ヘッダーの設定をしていて、API のプライマリキーを設定してます。次の http request ノードが、この内容を元に送受信してくれます。
2 段目の msg.headers.Ocp-Apim-Subscription-Key の項目の <Ocp-Apim-Subscription-Key>
をプライマリキーで置き換えます。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_16.png)
設定ができたら保存ボタンをクリックしてデプロイしましょう。
動かしてみる
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_17.png)
inject ノードの左にあるボタンをクリックしてデータを送ってみます。
![image](/wp-content/uploads/2022/11/enebular-rinna-api-collaboration-1st_18.png)
待っていると、デバッグタブに次の会話が「おはよう」が一番適切な会話とお知らせしてくれました。
ということで、enebular で作ったシンプルな HTTP リクエストのフローで、りんな API の会話の文脈を踏まえて回答を提案する API 、Session Based Scoring API を体験できました。
チャットボットでこのあたりの判断を自前でやるのは大変ですし、一番良い topCandidate まで返してくれるのでうれしいですね。いろいろな応答する仕組みに活用できそうです。
りんな API には、さまざまな API があるので、他にも API 試してみようと思います。