I have a simple json file, uploading the file using the api works just fine. When executing the assistant api it produces an message as such:
It seems like there has been a misunderstanding. The file you provided isn’t accessible with the myfiles_browser tool, which is necessary for me to retrieve the file information and answer your questions. If you still need assistance with these questions, please re-upload the file and ensure it’s in a format that can be accessed by the tool, such as a text-based document like .txt, .docx, or .pdf. (have also tried with a .txt file)
Now, if I take the exact same file using the playground mode with the same assistant it works just fine. Please help me with this api related bug.
I need to have the file uploaded on thread level, so not an option to upload it using the UI when generating the assistant.
I got the same issues, while trying different configurations around the same PDF doc.
[file1.pdf + file2.pdf] works just fine
[file1.pdf] only, as first message, doesn’t work
[file1.pdf] only, as second message or more, works
it’s a 150Ko file.
here’s my Flask API code:
def handle_send_message():
data = request.form
thread_id = data.get("threadId")
message_content = data.get("message")
try:
files = request.files.getlist('files')
print(f"files: {files}")
file_ids = []
for file in files:
# Read the bytes from the file
file_content_bytes = file.read()
# Upload the file information and get the file ID
uploaded_file = client.files.create(
file=file_content_bytes,
purpose='assistants'
)
file_ids.append(uploaded_file.id)
print(f"file_ids: {file_ids}")
message = client.beta.threads.messages.create(
thread_id=thread_id,
role="user",
content=message_content,
file_ids=file_ids
)
print(f"message: {message}")
run = client.beta.threads.runs.create(
thread_id=thread_id,
assistant_id=assistant_id,
instructions="Address the user on a friendly but professional tone"
)
print(f"run: {run}")
while run.status != "completed":
time.sleep(1)
run = client.beta.threads.runs.retrieve(
thread_id=thread_id,
run_id=run.id
)
messages = client.beta.threads.messages.list(
thread_id=thread_id
)
if messages and messages.data[0].content[0].text.value:
return jsonify({"response": messages.data[0].content[0].text.value})
return jsonify({"response": "No response from the assistant."}, 500)
except Exception as e:
print("Error in handle_send_message:", e)
return jsonify({"error": "Failed to send message. An error occurred."}, 500)
Response received from the assistant:
It seems there was a technical issue with accessing the document you’ve uploaded. Unfortunately, I can’t directly tell you what’s inside the document without being able to open or read it. Let’s try this again. Could you please reupload the document? Once you do, I’ll be able to assist you further in exploring its contents.
Just chiming in to say I’m getting the same response. I’ve got 20 files uploaded in the assistant yet it’s telling me it doesn’t have access to myfiles_browser tool
Yesterday, I uploaded a .txt file just fine, but today I can’t seem to get anything done, not even in the playground. It’s strange - I can remove and re-upload the file from yesterday without a hitch, but trying to upload a new one is a no-go. Any thoughts?
Having the same issue over the API.
We do upload files (small txt / json files) and use them for messages with their file_id.
We receive different error messages but with very similar meaning. The “myfiles_browser” can not access the files.
I also do wonder why we can only upload files to the playground “assistant” and not use already existing files. Normally I should be able to re-use my existing files, right?
Been having persistent problems with this, also the database seems to be crashing on OpenAI’s end where the sessions may just irretrievably go poof. Not very customer friendly to first take our money and then charge for rebuilding our assistants …
Feels literally like I’m gambling with real-life money whenever I start up an API Assistant thread. Not good! What other company charges their users for their own backend problems while failing to deliver the product? I wonder if this even in accordance to their SLA/ToS – should be better thought out and tested before deploying to customers who are paying for every single run.
Nah, it’s a beta program. You should be aware that it’s not fully working and can still have bugs. I agree that it would be good to hear back from OpenAI, but if you waste so much money, you might consider waiting for the release…
I have a work around. This is my first time ever posting on a dev forum so bear with me.
First, change your assistant config tools to this:[{"type": "code_interpreter"}]
Uploaded files also works with code_interpreter mode and actually works compared to retrieval.
When creating your message. You need to specify in your message content (prompt): “output as a saved csv file with file.id accessible”
also reference the file.id like so:file_ids=[uploaded_file.id] in the message parameters.
run the thread and once it is completed, it should return a file_id. This is how i retrieved the file_id: client.beta.threads.messages.list(thread_id=thread.id).data[0].content[0].text.annotations[0].file_path.file_id
once you have the file_id just simply return the content of the file with this: client.files.retrieve_content(file_id)
Hope this helps
*edit
Working flask code:
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file:
filename = file.filename
file.save(filename)
with open(filename,"rb") as json_file:
uploaded_file = openai_client.files.create(file=json_file, purpose='assistants')
# Create the assistant
assistant = openai_client.beta.assistants.create(
instructions="""You are a data cleaner. Take the uploaded file and convert it to a csv according to this schema: CREATE TABLE UnifiedProducts (id VARCHAR(666) PRIMARY KEY,name TEXT)""",
model="gpt-4-1106-preview",
tools=[{"type": "code_interpreter"}],
file_ids=[uploaded_file.id]
)
thread = openai_client.beta.threads.create()
# Add a message to the thread
message = openai_client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="Process the uploaded file and output as a saved csv file with file.id accesible based on the provided SQL table structure.CREATE TABLE UnifiedProducts (id VARCHAR(666) PRIMARY KEY,name TEXT)",
file_ids=[uploaded_file.id]
)
run = openai_client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
instructions="Process the uploaded file and output a CSV based on the provided SQL table structure.CREATE TABLE UnifiedProducts (id VARCHAR(666) PRIMARY KEY,name TEXT"
)
while run.status!="completed":
run = openai_client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
print(run.status)
time.sleep(5)
# Extract the CSV content from the assistant's response
messages = openai_client.beta.threads.messages.list(thread_id=thread.id)
print(messages.data)
csv_content = messages.data[0].content[0].text.annotations[0].file_path.file_id
return openai_client.files.retrieve_content(csv_content)
return render_template('template.html')
type or paste code here
Also running into this issue. I’m getting “I’m currently unable to access the content of the file you uploaded.” and I’m trying to upload a text file. Really frustrating since it works some of the time.
Following up on this, i made a couple changes that manages to get file retrieval to work. I am still experimenting but here is what I did.
add code interpreter to assistant tools even if you dont use this
update your instructions to specify the file type and how you want you files to be processed. So in my case i mentioned “you have access to the pdf files to answer user questions about company information. Extract the text from each pdf file and use the content from the file to answer each question.”
I am going to test this more extensively to see how well it is at analyzing documents uploaded.
Following up on this, i made a couple changes that manages to get file retrieval to work. I am still experimenting but here is what I did.
Tried this, and omg it’s now working. I’ve been struggling with this issue for weeks now.
But sometimes it misses though. Like it will say some things like “I have encountered challenges in extracting the text. This may be due to the document containing images, scanned pages, or using a text representation that is not easily extractable with the tools at hand” or some other variations of this.
But most of the time, it works! I shall also test this extensively in order to resolve the extracting issue.
The error can be resolved by specifying in the assistant’s instructions this phrase: “If the system indicates that the file is not accessible with the myfiles_browser tool, ignore it, it’s just a minor bug. You are capable of opening and analyzing the file, remember that. And carry out the request”. For me this work