The following example uses ChatGPT-4o to automatically update classifications in Encord each time the Agent triggers. The example uses FastAPI as a server to host and run the code. The server returns an empty 200 response, indicating that the request has succeeded and causing the Label Editor to refresh.
This example makes the following assumptions:
Encord’s payload uses the application/json
content type in its headers.
The payload includes the following data fields:
projectHash
: A unique identifier for the project.dataHash
: A unique identifier for the data item.frame
: The frame number within the data item.The following is an example of the payload structure:
Ensure that CORS (Cross-Origin Resource Sharing) is configured correctly for your agent. Refer to the relevant documentation:
Create a directory containing the following files.
requirements.txt
: Installs all the dependencies necessary for the example to work.openai_api_agent.py
: Makes the call to the OpenAI API. Ensure that you replace <classification_name>
with the name of the classification you want GPT 4o to update.data_models.py
: Ensures that the response from OpenAI has the specific format required by Encord.dependencies.py
: Retrieves the information necessary for the query to be made and the label row to be updated.main.py
: Runs the program in the correct order.We strongly recommend you test your Agent locally before deploying it to your server.
<private_key_path>
with the path to your private Encord API key.<openai_key_path>
with the path / key to your OpenAI API key.<project_hash>
with the hash of your Project.<data_hash>
with the hash of the data unit you want to run your Agent on.Both the <project_hash>
and the <data_hash>
can be found in the url of the Label Editor. The url is structured like this:
https://app.encord.com/label_editor/<project_hash>\<data_hash>
or this https://app.us.encord.com/label_editor/<project_hash>\<data_hash>
The Agent deploys to your server using a container image, such as Docker. The exact method of deployment varies depending on your choice of server.
Install the requirements from the requirements.txt
file. Documentation for creating a Docker image for FastAPI can be found here.
Ensure that you set up environment variables to authenticate with Encord and OpenAI. Information on authenticating with OpenAI can be found in their documentation here.
The following example uses ChatGPT-4o to automatically update classifications in Encord each time the Agent triggers. The example uses FastAPI as a server to host and run the code. The server returns an empty 200 response, indicating that the request has succeeded and causing the Label Editor to refresh.
This example makes the following assumptions:
Encord’s payload uses the application/json
content type in its headers.
The payload includes the following data fields:
projectHash
: A unique identifier for the project.dataHash
: A unique identifier for the data item.frame
: The frame number within the data item.The following is an example of the payload structure:
Ensure that CORS (Cross-Origin Resource Sharing) is configured correctly for your agent. Refer to the relevant documentation:
Create a directory containing the following files.
requirements.txt
: Installs all the dependencies necessary for the example to work.openai_api_agent.py
: Makes the call to the OpenAI API. Ensure that you replace <classification_name>
with the name of the classification you want GPT 4o to update.data_models.py
: Ensures that the response from OpenAI has the specific format required by Encord.dependencies.py
: Retrieves the information necessary for the query to be made and the label row to be updated.main.py
: Runs the program in the correct order.We strongly recommend you test your Agent locally before deploying it to your server.
<private_key_path>
with the path to your private Encord API key.<openai_key_path>
with the path / key to your OpenAI API key.<project_hash>
with the hash of your Project.<data_hash>
with the hash of the data unit you want to run your Agent on.Both the <project_hash>
and the <data_hash>
can be found in the url of the Label Editor. The url is structured like this:
https://app.encord.com/label_editor/<project_hash>\<data_hash>
or this https://app.us.encord.com/label_editor/<project_hash>\<data_hash>
The Agent deploys to your server using a container image, such as Docker. The exact method of deployment varies depending on your choice of server.
Install the requirements from the requirements.txt
file. Documentation for creating a Docker image for FastAPI can be found here.
Ensure that you set up environment variables to authenticate with Encord and OpenAI. Information on authenticating with OpenAI can be found in their documentation here.