Box AIに質問する

ガイド Box AI Box AIに質問する

Box AIに質問する

Box AI APIはベータ機能のため、利用可能な機能は変更される可能性があります。Box AI APIは、Enterprise Plusをご利用のすべてのお客様が利用できます。

Box AI APIを使用すると、指定した1ファイルまたは一連のファイルについて質問し、そのコンテンツに基づいた応答を得ることができます。たとえば、Boxでドキュメントを表示している場合に、Box AIに対して、コンテンツの要約を求めることができます。

リクエストの送信

質問を含むリクエストを送信するには、POST /2.0/ai/askエンドポイントを使用し、必須のパラメータを指定します。

cURL
curl -i -X POST "https://api.box.com/2.0/ai/ask" \
     -H "content-type: application/json" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
         "mode": "single_item_qa",
         "prompt": "What is the value provided by public APIs based on this document?",
         "items": [
        {
            "type": "file",
            "id": "9842787262"
        }
       ],
     }'
Java
BoxAIResponse response = BoxAI.sendAIRequest(
    api,
    "What is the content of the file?",
    Collections.singletonList("123456", BoxAIItem.Type.FILE)),
    BoxAI.Mode.SINGLE_ITEM_QA
);
TypeScript Gen
await client.ai.createAiAsk({
  mode: 'multiple_item_qa' as AiAskModeField,
  prompt: 'Which direction sun rises?',
  items: [
    new AiAskItemsField({
      id: fileToAsk1.id,
      type: 'file' as AiAskItemsTypeField,
      content: 'Earth goes around the sun',
    }),
    new AiAskItemsField({
      id: fileToAsk2.id,
      type: 'file' as AiAskItemsTypeField,
      content: 'Sun rises in the East in the morning',
    }),
  ],
} satisfies AiAsk);
Python Gen
client.ai.create_ai_ask(
    CreateAiAskMode.MULTIPLE_ITEM_QA.value,
    "Which direction sun rises?",
    [
        CreateAiAskItems(
            id=file_to_ask_1.id,
            type=CreateAiAskItemsTypeField.FILE.value,
            content="Earth goes around the sun",
        ),
        CreateAiAskItems(
            id=file_to_ask_2.id,
            type=CreateAiAskItemsTypeField.FILE.value,
            content="Sun rises in the East in the morning",
        ),
    ],
)
.NET (Beta)
await client.Ai.CreateAiAskAsync(requestBody: new AiAsk(mode: AiAskModeField.MultipleItemQa, prompt: "Which direction sun rises?", items: Array.AsReadOnly(new [] {new AiAskItemsField(id: fileToAsk1.Id, type: AiAskItemsTypeField.File) { Content = "Earth goes around the sun" },new AiAskItemsField(id: fileToAsk2.Id, type: AiAskItemsTypeField.File) { Content = "Sun rises in the East in the morning" }})));

認証

アプリを承認するための開発者トークンを生成済みであることを確認します。詳細については、Box AI入門ガイドを参照してください。

パラメータ

コールを実行するには、以下のパラメータを渡す必要があります。必須のパラメータは太字で示されています。

パラメータ説明使用可能な値
modeリクエストのタイプ。1つのファイルと一連のファイルのどちらに関する質問かを指定できます。1ファイルの場合、Box AI APIは、最大1 MBのテキストレプリゼンテーションをサポートします。ファイルサイズが1 MBを超えた場合は、テキストレプリゼンテーションの最初の1 MBが処理されます。複数のファイルのリストを取得する場合、上限は25ファイルです。modesingle_item_qaに設定すると、items配列には要素を1つしか取得できません。single_item_qa, multiple_item_qasingle_item_qa
promptドキュメントまたはコンテンツに関する質問。プロンプトの長さは10000文字以内にする必要があります。「これは何に関するドキュメントですか?」
items.id入力データとして指定するBoxファイルID。112233445566
items.type指定した入力データのタイプ。現在は、1つのファイルまたは複数のファイルを指定できます。filefile
items.content項目のコンテンツ (多くの場合はテキストレプリゼンテーション)。「アプリケーションプログラミングインターフェース (API) とは、2つ以上のコンピュータプログラムやコンポーネントが互いに通信するための手段です。ソフトウェアインターフェースの一種で......」