Prioritizing Privacy in AI: Secure File Handling with OpenAI
This guide delves into the privacy-centric approach to uploading documents for question-answering purposes, creating an AI assistant, and the secure deletion of files post-interaction, ensuring no data persistence on OpenAI servers.
Secure File Upload for Confidential QA
The process respects user privacy by securely uploading files to be used exclusively for generating answers. The following code snippet demonstrates how to upload a document with confidentiality as the core consideration:
import openai
# Securely set your OpenAI API key
openai.api_key = 'your_secure_openai_api_key'
# Function to create an assistant with a privacy-first approach
def create_assistant_with_file(file_path):
# Upload a file with a privacy-focused "assistants" purpose
with open(file_path, 'rb') as file:
file_response = openai.File.create(file=file, purpose='answers')
# Create an assistant with the file, ensuring no residual data retention
assistant_response = openai.Assistant.create(
model="gpt-4-1106-preview",
tools=[{"type": "retrieval"}],
file_ids=[file_response['id']]
)
return assistant_response['id'], file_response['id']
Privacy Aware Interactions
To inquire about the content of the uploaded document, the following function maintains the confidentiality of the interaction:
# Function to ask a question with privacy safeguards
def ask_question(assistant_id, file_id, question):
# Initiate a secure thread for the question, referencing the file
thread_response = openai.Thread.create(
assistant_id=assistant_id,
messages=[{
"role": "user",
"content": question,
"file_ids": [file_id]
}]
)
return thread_response
Ensuring Data Deletion
After utilizing the file for its intended purpose, the code below ensures complete removal of the file from OpenAI's systems, upholding the strictest data privacy standards:
# Function to delete the file, maintaining privacy integrity
def delete_file(file_id):
# Securely remove the file, ensuring complete data deletion
deletion_status = openai.File.delete(file_id=file_id)
return deletion_status