Box AIを使用してテキストを生成する

ガイド Box AI Box AIを使用してテキストを生成する

Box AIを使用してテキストを生成する

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

Box AIを使用すると、提供されたコンテンツに基づいてテキストを生成できます。たとえば、Box Notesで参照または作成したコンテンツに基づいてテンプレートを生成するようBox AIに求めることができます。その後、生成されたテキストを直接ドキュメントに埋め込むことができます。

リクエストの送信

リクエストを送信するには、POST /2.0/ai/text_genエンドポイントを使用します。

cURL
curl -i -X POST "https://api.box.com/2.0/ai/text_gen" \
     -H "content-type: application/json" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
         "prompt": "Write an email to a client about the importance of public APIs.",
         "items": [
        {
            "id": "12345678",
            "type": "file",
            "content": "More information about public APIs"
        },
    ],
    "dialogue_history": [
        {
            "prompt": "Make my email about public APIs sound more professional",
            "answer": "Here is the first draft of your professional email about public APIs",
            "created_at": "2013-12-12T10:53:43-08:00"
        },
        {
            "prompt": "Can you add some more information?",
            "answer": "Public API schemas provide necessary information to integrate with APIs...",
            "created_at": "2013-12-12T11:20:43-08:00"
        }
    ],
  }'
Java
List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>();
dialogueHistory.add(
        new BoxAIDialogueEntry(
            "Make my email about public APIs sound more professional",
            "Here is the first draft of your professional email about public APIs.",
            BoxDateFormat.parse("2013-05-16T15:26:57-07:00")
        )
    );
BoxAIResponse response = BoxAI.sendAITextGenRequest(
    api,
    "Write an email to a client about the importance of public APIs.",
    Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)),
    dialogueHistory
);
TypeScript Gen
await client.ai.createAiTextGen({
  prompt: 'Parapharse the document.s',
  items: [
    {
      id: fileToAsk.id,
      type: 'file' as AiTextGenItemsTypeField,
      content:
        'The Earth goes around the sun. Sun rises in the East in the morning.',
    } satisfies AiTextGenItemsField,
  ],
  dialogueHistory: [
    {
      prompt: 'What does the earth go around?',
      answer: 'The sun',
      createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
    } satisfies AiTextGenDialogueHistoryField,
    {
      prompt: 'On Earth, where does the sun rise?',
      answer: 'East',
      createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
    } satisfies AiTextGenDialogueHistoryField,
  ],
} satisfies AiTextGen);
Python Gen
client.ai.create_ai_text_gen(
    "Parapharse the document.s",
    [
        CreateAiTextGenItems(
            id=file_to_ask.id,
            type=CreateAiTextGenItemsTypeField.FILE.value,
            content="The Earth goes around the sun. Sun rises in the East in the morning.",
        )
    ],
    dialogue_history=[
        CreateAiTextGenDialogueHistory(
            prompt="What does the earth go around?",
            answer="The sun",
            created_at=date_time_from_string("2021-01-01T00:00:00Z"),
        ),
        CreateAiTextGenDialogueHistory(
            prompt="On Earth, where does the sun rise?",
            answer="East",
            created_at=date_time_from_string("2021-01-01T00:00:00Z"),
        ),
    ],
)
.NET (Beta)
await client.Ai.CreateAiTextGenAsync(requestBody: new AiTextGen(prompt: "Parapharse the document.s", items: Array.AsReadOnly(new [] {new AiTextGenItemsField() { Id = fileToAsk.Id, Type = AiTextGenItemsTypeField.File, Content = "The Earth goes around the sun. Sun rises in the East in the morning." }})) { DialogueHistory = Array.AsReadOnly(new [] {new AiTextGenDialogueHistoryField() { Prompt = "What does the earth go around?", Answer = "The sun", CreatedAt = Utils.DateTimeFromString(dateTime: "2021-01-01T00:00:00Z") },new AiTextGenDialogueHistoryField() { Prompt = "On Earth, where does the sun rise?", Answer = "East", CreatedAt = Utils.DateTimeFromString(dateTime: "2021-01-01T00:00:00Z") }}) });

アプリを承認するための開発者トークンを生成済みであることを確認します。詳細については、Box AIの前提条件を確認してください。

パラメータ

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

: items配列に含めることができる要素は1つだけです。

パラメータ説明
promptBox AIに対するテキストの生成またはリファインのリクエスト。プロンプトの長さは10000文字以内にする必要があります。週1回の営業会議の議題を作成してください。
items.idドキュメントのBoxファイルID。1233039227512
items.type指定した入力データのタイプ。file
items.content項目のコンテンツ (多くの場合はテキストレプリゼンテーション)。これはBox AIに関する記事です。
dialogue_history.prompt以前にクライアントによって提供され、大規模言語モデル (LLM) が回答したプロンプト。「パブリックAPIに関する私のメールをよりプロフェッショナルなものにしてください」
dialogue_history.answer以前にLLMから提供された回答。「パブリックAPIに関するプロフェッショナルなメールの下書きを以下に示します。」
dialogue_history.created_atプロンプトに対する前回の回答が作成された時点のISO日付形式のタイムスタンプ。2012-12-12T10:53:43-08:00