import os
import time
from openai import OpenAI
from dotenv import load_dotenv
# Load environment variables from the .env file
load_dotenv("/web/.env")
# Get the API key from the environment
api_key = os.getenv("OPENAI_API_KEY")
# Initialize the OpenAI client
client = OpenAI(api_key=api_key)
# Hardcoded vector store ID
vector_store_id = "vs_d98tbtzphU5dMBNOyZM5oa4b"
# Hardcoded file IDs
file_ids = [
"file-YqpOz86ZkcqgjFAbrH5lySwe",
"file-Wm3LgThQcXNtu7PQpkZXqKoU",
"file-UDhhcmBEJUJWL8qWW7NE6mip",
"file-DEx8NY07xCzir3GcC1f3Ouyt",
"file-RMdwBG7Qt1kCoUfG6H10sQxU",
"file-WI8fuDF1h3yGecMjWapzeJcV"
]
# Attach the file IDs to the vector store
batch_add = client.beta.vector_stores.file_batches.create(
vector_store_id=vector_store_id,
file_ids=file_ids
)
# Polling for completion
status = batch_add.status
while status not in ["completed", "failed"]:
time.sleep(5) # Wait for 5 seconds before polling again
batch_add = client.beta.vector_stores.file_batches.retrieve(
vector_store_id=vector_store_id, # Provide vector_store_id as a keyword argument
batch_id=batch_add.id
)
status = batch_add.status
print(f"Current status: {status}")
# Final status
print(f"Batch operation completed with status: {status}")
When I poll it continues to say in progress but the platform UI says its failed.
Is there any way to improve this or fix? Each file is approx 130MB. Thank you.
Update
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: in_progress
Current status: failed
Batch operation completed with status: failed