5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

検証!! AI BuilderでDataverse以外の表データをデータソースとして扱えるか!?

Last updated at Posted at 2024-12-18

この記事は2024.12.18時点の情報です。
数日後には不要になる可能性があります。

はじめに

Power AutomatePower Appsで非常に気軽にAIの機能が使える、それがAI Builder
このAI Builderでは強力な生成 AI 機能Azure OpenAI ServiceGPT 4o MiniまたはGPT 4oモデルを使用することができます。

やはり生成AIというと、このGPTのモデルが気軽に使えるということは非常にうれしいことです。

MicrosoftはAIのガイドも豊富に提供しており、プロンプトのイロハから生成AIの活用シーンまでくまなくMicrosoft learnで紹介しています。

事前構築されたプロンプトにより、下記はサクッと用意することができます。

  1. テキストの要約
  2. テキストから情報の抽出
  3. テキストの分類
  4. テキストの感情分析
  5. 苦情への応答
  6. テキストの匿名化と編集
  7. 言語の検出
  8. 単語の頻度分析
  9. テキストの種類の特定
  10. 2つのテキストから類似性や相違性の測定

一方で実際に **これがやりたい!**となるのは、あるデータソースからデータを照合し、回答するような機能ではないでしょうか。
いわゆるRAG(検索拡張生成)というやつです。

独自のデータを試用した生成シナリオ

2024.12.18では、データ オプションを利用して、Dataverseテーブルをナレッジソースとした回答が生成できます。
Dataverseテーブルを用いて、値を抽出し回答に使えます。

こちらの機能はPower AutomatePower AppsCopilot Studioで利用することができます。

公式の学習コンテンツから利用方法を学べます。

前置きが長くなりましたが、ここからが本題です。
SharePoint ListsExcelからやってみたいんだけどな・・・
と思ったそこのあなた!そうですよね!まずはそこからですよね!!

ということで挑戦的な手法を用いて、実現する方法を考えてみました!

プロンプトに表データを書き込む

がつくレベルの無理やりな手法ですが、プロンプトの中にテキスト形式で表を入れてみました。
構造化されたテキスト形式の表データというと真っ先に思い浮かぶのはCSV 次点でMarkdownが挙げられます。

消費するトークンが気になりますが、いったんプロンプトに全部含めて機能するか検証してみました。

カスタム プロンプト

簡単に下記のように設定してみます。

image.png

カスタムプロンプト
以下にテキスト形式でCSV形式で表データが記載されています。出力はHTML文字列で返してください。
{Question}

# CSVデータ
{Table}

image.png

引数とするのはQuestion - 質問Table - CSVテーブルです。

結果をプレビューするのは、やはりPower Apps!!
Power Apps Loverとしてそこはゆずれません!

HTML文字列で出力することを定義づけるため、JSON 出力を設定します。

image.png

カスタム形式
{
  "response": "HTML文字列"
}

GPTで作成したProductというCSVデータで試してみましょう。

Power Appsから呼び出す

今回の目的はインポートされたExcelExcel OnlineSharePoint Listsを想定した読み取りです。
Power AppsでCSV形式の文字列にかえます。

インポートされたExcel

テーブル形式にしてPower Appsにインポートします。

image.png

テキストへの変換は、Concat 関数で無理くり実施します。

CSV変換を表すテキスト
$"ProductID,ProductName,Category,Price,StockQuantity,Rating,Features
{
    Concat(
        Product,
        $"{Char(34)}{ProductID}{Char(34)},{Char(34)}{ProductName}{Char(34)},{Char(34)}{Category}{Char(34)},{Char(34)}{Price}{Char(34)},{Char(34)}{StockQuantity}{Char(34)},{Char(34)}{Rating}{Char(34)},{Char(34)}{Features}{Char(34)}{Char(10)}"
    )
}"

列がハードコーディングになっていてイケてないですね。

このうち Char 関数は下記を意味しています。

  • Char(34): ダブルクォーテーション "
  • Char(10): 改行

ダブルクォーテーションは引用符としての利用です。
果たして機能するのでしょうか。

検証!

実験1
製品名を一覧化してください。

image.png

結果1
{
  "response": "<ul><li>Mouse</li><li>Printer</li><li>Monitor</li><li>Router</li><li>Tablet</li><li>Keyboard</li><li>Laptop</li><li>Smartphone</li><li>Smartwatch</li><li>Earbuds</li></ul>"
}

い、意外とそれらしい!!それらしいぞぉ!

実験2
最も高価な製品とその価格を教えてください。

image.png

結果2
{
  "response": "最も高価な製品は「Monitor」で、価格は1165です。"
}

プレーンテキストで返ってきました。

実験3
軽さがポイントの製品を教えてください。

image.png

Lightweightという特長を抽出できています。

結果3
{
"response": "<table>
  <tr>
    <th>ProductID</th>
    <th>ProductName</th>
    <th>Category</th>
    <th>Price</th>
    <th>StockQuantity</th>
    <th>Rating</th>
    <th>Features</th>
  </tr>
  <tr>
    <td>101</td>
    <td>Mouse</td>
    <td>Wearables</td>
    <td>737</td>
    <td>384</td>
    <td>4.3</td>
    <td>Lightweight and portable<br>High-resolution display<br>Long battery life</td>
  </tr>
  <tr>
    <td>104</td>
    <td>Router</td>
    <td>Gaming</td>
    <td>659</td>
    <td>14</td>
    <td>4.4</td>
    <td>Lightweight and portable<br>High-resolution display<br>Long battery life</td>
  </tr>
  <tr>
    <td>113</td>
    <td>Laptop</td>
    <td>Wearables</td>
    <td>896</td>
    <td>94</td>
    <td>5</td>
    <td>Lightweight and portable<br>High-resolution display<br>Long battery life</td>
  </tr>
  <tr>
    <td>122</td>
    <td>Laptop</td>
    <td>Home Appliances</td>
    <td>1206</td>
    <td>263</td>
    <td>3.2</td>
    <td>Lightweight and portable<br>High-resolution display<br>Long battery life</td>
  </tr>
  <tr>
    <td>148</td>
    <td>Router</td>
    <td>Electronics</td>
    <td>1290</td>
    <td>422</td>
    <td>4.4</td>
    <td>Lightweight and portable<br>High-resolution display<br>Long battery life</td>
  </tr>
</table>"
}

Power Appsで文字列変換をかましているのでExcel OnlineでもSharePointでも同様の結果が得られます。

SharePoint Listsの場合は

image.png

質問
評価が高い製品をリストアップして教えてください。

ソースが長いのでキャプチャだけ出します。

image.png

おわりに

Concat 関数で変換をかましているので、そりゃあそうだと思われる方もいると思います。
しかしFAQから回答を生成したりするのに、意外と役に立ちそうです。

Power Automateではデータ操作アクションでCSV テーブルの作成が存在するため、より簡単に使えます。

image.png

結果をTeamsに投稿してみました。

AI活用 はじめの一歩に採用できればいいなーくらいです。
回りくどい方法ではあるので、活用される場合はよく吟味して採用してください。

5
1
0

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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?