- 02 May 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Get the list of uploaded files
- Updated on 02 May 2024
- 1 Minute to read
- Print
- DarkLight
- PDF
Retrieving List of Uploaded Documents in Paradigm
Overview
This guide explains how to retrieve the list of uploaded documents in Paradigm using the OpenAI python client. Ensure you have the OpenAI Python client set up as per the initial setup guide.
Step-by-Step Instructions
Step 1: Install Required Library
Ensure you have the OpenAI library installed. If not, install it using pip:
pip install --upgrade openai
Step 2: Set Up the OpenAI client
Configure your OpenAI client with the API key and set the base URL to the Paradigm API:
from openai import OpenAI as OpenAICompatibleClient
import os
# Get API key from environment
api_key = os.getenv("PARADIGM_API_KEY")
# Our API base url
base_url = "https://paradigm.lighton.ai/api/v2"
# Configure the OpenAI client
client = OpenAICompatibleClient(api_key=api_key, base_url=base_url)
Step 3: Fetch Paginated List of Documents
To retrieve the documents, use the files.list()
method of the OpenAi python object.
response = client.files.list()
Step 4: Handle the Response
The method will return a SyncPage
object containing the paginated list of documents and additional information, as described below:
data
: List ofFileObject
itemsobject
: constant value set tolist
next
: url to call to get the next page content if it existsprevious
: url to call to get the previous page content if it existscount
: total number of files available through all the pages
Handle this response as needed in your application.
# Example code to print all the documents information
for document in response.data:
print(document)
Handle pagination
The number of documents per page is currently set to 20 and cannot be modified by the end user.
To get the documents of a specific page, you can add the information through the extra_query
parameter of the files.list()
method, as shown below:
# Example snippet requesting the content of the second page
response = client.files.list(extra_query={"page": 2})
Conclusion
You have successfully retrieved a paginated list of uploaded documents from Paradigm using the specified method. Adjust the page
value in the extra_query
parameter to navigate through the pages.