Delete a document

The files API endpoint can be used to delete an uploaded document from Paradigm.

Prerequisites

In order to do so, here are the prerequisites:

  • Paradigm API key: if you do not have one, go to your Paradigm profile and generate a new API key.
  • The desired document ID to delete: You can use the listing method to get the list of uploaded documents and be able to know the ID of the document you want to delete.

Usage methods

There are several ways to call the endpoint:

  1. With the OpenAI python client (recommended)
  2. With the python requests package: to avoid having the OpenAI layer
  3. Through a curl request: good to do a quick check or a first test

OpenAI python client

Setup

Install the OpenAI python package with the following bash command:

pip install --upgrade openai
 

You can then setup the OpenAI python client in your script:

from openai import OpenAI as OpenAICompatibleClient
import os

# Get API key from environment
api_key = os.getenv("PARADIGM_API_KEY")
# Our base url
base_url = "https://paradigm.lighton.ai/api/v2"

# Configure the OpenAI client
client = OpenAICompatibleClient(api_key=api_key, base_url=base_url)
 

Here the Paradigm API key is set up in an environment variable, but you could perfectly forward it through argument parsing with argparse.

Usage

To convert an input string into an embedding vector, you can use the client.files.delete() method with an existing file ID in Paradigm.
An example is described below to delete the file with ID n°1:

delete_response = client.files.delete(
file_id=1
)
 

The given response would then follow the OpenAI format:

FileDeleted(
id=1,
deleted=True,
object=None
)
 

Python requests package

You can also avoid using the OpenAI python class and directly send request to the API endpoint through the requests package.

import requests
import os

# Get API key from environment
api_key = os.getenv("PARADIGM_API_KEY")
# File ID to delete
file_id = 1

response = requests.request(
method="DELETE",
url=f"https://paradigm.lighton.ai/api/v2/files/{file_id}",
headers={
'Authorization': f"Bearer {api_key}"
}
)

print(response.json())
 

You would then get a JSON answer as a dictionnary:

{
'id': 1,
'deleted': True
}
 

cURL request

If you would prefer sending a request to Paradigm with a simple cURL command, here is an example:

curl --request DELETE \
--url https://paradigm-preprod.lighton.ai/api/v2/files/1 \
--header 'Authorization: Bearer <YOUR_API_KEY>'