ファイルからメタデータを抽出する (自由形式)
ファイルからメタデータを抽出する (自由形式)
Box AI APIを使用すると、ドキュメントまたは画像に対してクエリを実行し、指定したプロンプトに基づいてメタデータを抽出できます。自由形式とは、JSONやXMLなどの形式の文字列化バージョン、またはプレーンテキストをプロンプトに含めることができるという意味です。
開始する前に
Platformアプリを作成して認証するには、Box AIの使い方に記載されている手順に従っていることを確認してください。
リクエストの送信
リクエストを送信するには、POST /2.0/ai/extract
エンドポイントを使用します。
cURL
curl -i -L 'https://api.box.com/2.0/ai/extract' \
-H 'content-type: application/json' \
-H 'authorization: Bearer <ACCESS_TOKEN>' \
-d '{
"prompt": "Extract data related to contract conditions",
"items": [
{
"type": "file",
"id": "1497741268097"
}
],
"ai_agent": {
"type": "ai_agent_extract",
"long_text": {
"model": "azure__openai__gpt_4o_mini",
"prompt_template": "It is `{current_date}`, and I have $8000 and want to spend a week in the Azores. What should I see?",
},
"basic_text": {
"model": "azure__openai__gpt_4o_mini",
}
}
}'
TypeScript Gen
await client.ai.createAiExtract({
prompt: 'firstName, lastName, location, yearOfBirth, company',
items: [new AiItemBase({ id: file.id })],
aiAgent: agentIgnoringOverridingEmbeddingsModel,
} satisfies AiExtract);
Python Gen
client.ai.create_ai_extract(
"firstName, lastName, location, yearOfBirth, company",
[AiItemBase(id=file.id)],
ai_agent=agent_ignoring_overriding_embeddings_model,
)
.NET Gen
await client.Ai.CreateAiExtractAsync(requestBody: new AiExtract(prompt: "firstName, lastName, location, yearOfBirth, company", items: Array.AsReadOnly(new [] {new AiItemBase(id: file.Id)})));
Java
BoxAIResponse response = BoxAI.extractMetadataFreeform(
api,
"firstName, lastName, location, yearOfBirth, company",
Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE))
);