1
Create and configure a Box application
The first step for any Box Platform integration is to create and configure a Box
application.
- Go to Box Developer Console.
- For this quick start, create an App with the
Client Credentials Grantapplication type. - Once the app is created, enable the following scopes:
Read all files and folders stored in BoxManage AI
2
Upload a test file
To use Box AI to get insights from documents, you need a file in Box. For this quick start, use this document containing
federal code.
- Download the test document, and then drag and drop it into your Box account.
- Get the file ID by opening the file in Box and inspecting the URL.
The last part of the path is your file ID. For example, the URL might look like this:
https://app.box.com/file/2064123286902
2064123286902.3
Configure the environment
Now set up your development environment to run this quickstart. This tutorial uses Python and the
latest Box Python SDK to run the code. Make sure you have Python 3.11 or higher installed on your machine.
- Create a new directory for your project and navigate into it.
- Create a virtual environment:
- Install the Box Python SDK:
- Install the
python-dotenvpackage to load environment variables from the.envfile: - Create an
.envfile in the root of your project directory and add the following environment variables, replacing the placeholder values with your actual Box app credentials and the IDs from the previous steps:
- Click Generate Developer Token to create a new token.
4
Create the summarize.py file
Your development environment is now ready to create the Python script to summarize the document using Box AI.
-
Create a new file named
summarize.pyin the root of your project directory and add the following code:
.env file, initializes the Box SDK client,
and prints the current user’s ID to validate that the client is working correctly.-
Run the script using the following command in your terminal:
If the Box SDK client is set up correctly, the console displays your user ID. For example:
5
Summarize the file
With a working Box SDK client, you can add the code to summarize the document using Box AI.
-
Between the
get_box_clientfunction and themainfunction, add the following function:This function uses the Box AIcreate_ai_askmethod to interrogate the specified file. Your BoxClient and file ID created earlier are sent to the function, which returns the summary of the file as a string. -
Add the function call to summarize the file in the
mainfunction. Ensure that the newmainfunction contains the following logic:The SDK handles the API call to Box AI and returns the summary as anAiResponseFullobject. In this quick start, the code converts this object to a dictionary and returns theanswerfield that contains the summary. -
Print out the summary to the console to verify that the operation was successful by running the following command in your terminal:
If the summarization was successful, the console displays your user ID followed by the summary from the test document.
