キャンバスアプリからChatGPT(OpenAIのAPI)を呼び出してみたので、その結果をメモ。
今回使用するAPI
今回使用するAPIは「Create chat completion」。
公式はこちら
![]()
Just a moment...
API Keyの取得
APIの実行にはAPIKeyが必要なので、OpenAIのサイトから取得する。
Power Automateの作成
今回はカスタムコネクタを使用せずに、Power Automate経由でChatGPTを呼んでみる。
Power AutomateのトリガーはV2を選んで、


APIのReference通り、こんな感じでHTTPリクエストを呼び出す


実際に呼び出してみると、


こんな感じで返答が返ってくるので、


JSONの解析に本文を、


スキーマにさっきの戻り値を入れてあげる。


解析したJSONの中身のGPTからのメッセージをApps側に返してあげる。
※function Callingを使用していないので、choicesの最初のレコードがそのまま返答になる。
※function Callingを使用していないので、choicesの最初のレコードがそのまま返答になる。
first(body('JSON_の解析')?['choices'])?['message']?['content']
これでPower Automateは作成完了!
Power Appsからの呼び出し
作成したフローをAppsから呼び出してみる。
フローを追加して、


フローからの戻り値を変数に入れて、


ラベルに表示する。


動かしてみるとこんな感じ!


今回はOpenAIを呼び出したけど、Azure OpenAIも同じように呼び出すことは可能。
次回は画像生成を呼び出してみる。
コメント