Hey there!
I am trying to follow the instructions for passing files to the code interpreter here.
However, I am getting the error create() got an unexpected keyword argument 'file' when I try to follow that section of the documentation.
Here is my full file for context:
import openai
import sys
from pathlib import Path
client = openai.OpenAI()
# Check if a file path is provided
if len(sys.argv) < 2:
print("Usage: python test.py <file_path>")
sys.exit(1)
file_path = sys.argv[1]
# Upload the file
try:
file = client.files.create(file=open(file_path, "rb"), purpose="assistants")
file_id = file.id
instruction = """You are a helpful assistant. Please analyze the file and respond with a JSON object containing either the student's name or an error message. Use the format {"status": "success",
"data": {
"name": "Alice"
}
} or {
"status": "error",
"error": {
"message": "Student name not found in the file",
"code": "NameNotFound"
}
}"""
# Process the uploaded file and get a response in JSON format
response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_format={"type": "json_object"},
file=file_id,
messages=[
{
"role": "system",
"content": instruction,
},
{
"role": "user",
"content": "Here is the transcript for the student",
},
],
)
print(response.choices[0].message.content)
except FileNotFoundError:
print(f"Error: File not found at {file_path}")
except Exception as e:
print(f"An error occurred: {e}")
Do I have some syntax wrong? Or should I be sending the file in a message instead or something?
Thanks for your help!