Hi there, we think it’d be extremely useful for iterating on user feedback of our implementation of the Assistants API to be able to retrieve the content of the file being used. Currently this is not supported and the following error is returned from the API. Just wondering why is this the case and could it potentially be changed in future? Right now we are having to store a copy of the file in AWS S3 every time we upload the file to OpenAI.
Request:
curl --location 'https://api.openai.com/v1/files/<FILE_ID>/content' \
--header 'Authorization: Bearer <OPENAI_API_KEY>' \
Response:
{
"error": {
"message": "Not allowed to download files of purpose: assistants",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Currently you can only download files created by Code interpreter, so… presumably you could ask the assistant to make use of code interpreter to create a file of the contents you need.
What about just asking the assistant to print out the file? Would that serve your purpose?
how do you get around this problem?
openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “‘code_interpreter’ is not one of [‘fine-tune’, ‘assistants’, ‘batch’, ‘user_data’, ‘responses’, ‘vision’] - ‘purpose’”, ‘type’: ‘invalid_request_error’, ‘param’: ‘purpose’, ‘code’: None}}
Here's the whole script for creating the assistant. (It's run by a separate script which uses config.txt.)
#!/home/tom/miniconda3/bin/python3.9
from tuts import brr, brc
from openai import OpenAI
import os
import sys
openai_api_key = os.getenv('OPENAI_API_KEY')
client = OpenAI(
api_key=openai_api_key
)
file_name = sys.argv[1]
file = client.files.create(
file=open(file_name, "rb"),
purpose='assistants'
)
file_id = file.id
assistant = client.beta.assistants.create(
model="gpt-4o-mini",
tools=[{"type": "code_interpreter"}],
tool_resources={
"code_interpreter": {
"file_ids": [file_id]
}
}
)
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": "You are a helpful assistant whose answers are always short.\
You always ask for clarification if my request has more than one meaning. \
The following is an inventory file for a coffee house. You help me manage it and observe the following very important rules. \
1. Whenever the quantity of an item is _below_ the Reorder Point, you put 'YES' in the Reorder? field for the item. \
2. When you change a record you do this:\
2.a Show all of the record in this format: before: <record before change>\
2.b Change the record.\
2.c Show all of the new record in this format: after: <record after change>\
3. NEVER show before/after lines unless a record has been changed.",
"attachments": [
{
"file_id": file_id,
"tools": [{"type": "code_interpreter"}]
}
]
}
]
)
with open('config.txt', 'w') as file:
file.write(assistant.id)
file.write("\n")
file.write(thread.id)
file.write("\n")
file.write(file_id)
file.write("\n")