have you tried it? did it work for you? I’ve uploaded file to a vector store and then indicated its file_id in attachments, but it didn’t work me, I got the same error
So then it sounds like a workaround right now is to
- Upload the file to OpenAI.
- Check if the thread has a vectore store via it’s tool_resources
- If there is one, manually upload the file id via vector store batch operation.
- If not, create a new vector store, add the file to it and attach that to the thread.
- Run your message like before.
This is quite the amount of work…OpenAI should let us know if we all need to make these changes. I’ll be adding this to our system and reporting back on the results.
Yup, worked for me. Notice that you also need to manually associate the vector store with the thread when creating it, otherwise, it will still fail.
Here’s an example:
curl --location 'https://api.openai.com/v1/threads' \
--header 'OpenAI-Beta: assistants=v2' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
"messages": [
{
"role": "user",
"content": "What is the associated document about?",
"attachments": [
{
"file_id": "yourfileid",
"tools": [{ "type": "file_search" }]
}
]
}
],
"tool_resources": {
"file_search": {
"vector_store_ids": ["vectorestoreid-you-created-by-hand-with-the-file-ids"]
},
"code_interpreter": {
"file_ids": []
}
}
}'
If you remove the
"tool_resources"
property, the exact same request fails with the message: “Failed to create file operation.”
It works.
Here’s my working implementation. Hope it helps someone else.
def set_thread_attachments_from_file_ids_v2(file_ids, openai_thread, openai_client: openai.OpenAI):
if not file_ids:
return None
print("Adding file ids to thread {}".format(openai_thread.id))
print("File ids", file_ids)
vector_store_id, vector_store = None, None
if openai_thread.tool_resources:
file_search = openai_thread.tool_resources.file_search
if file_search and file_search.vector_store_ids:
vector_store_id = file_search.vector_store_ids[0]
if not vector_store_id:
print("No vector store id found for thread {} -- creating one.".format(openai_thread.id))
vector_store = openai_client.beta.vector_stores.create(
name="vs_{}".format(openai_thread.id)
expires_after={
"anchor": "last_active_at",
"days": 7
}
)
vector_store_id = vector_store.id
openai_client.beta.threads.update(
thread_id=openai_thread.id,
tool_resources={
"file_search": {
"vector_store_ids": [vector_store_id]
}
}
)
files_to_attach = file_ids
print("Attaching files to thread {}".format(openai_thread.id))
print("Files to attach", files_to_attach)
openai_client.beta.vector_stores.file_batches.upload_and_poll(
vector_store_id=vector_store_id,
file_ids=files_to_attach,
files=[]
)
return files_to_attach
[EDIT: Added expiration to bring back to parity with old system]
Here’s how I call it.
attachments_file_ids = set_thread_attachments_from_file_ids_v2(file_ids, thread, client)
print("Looking at attechments", attachments_file_ids)
message = wrap_with_retry(lambda: client.beta.threads.messages.create(
thread_id=thread.id, role="user", content=message if message else "...",
# attachments=attachments
))
This is also appears to be affecting files uploaded for the code interpreter. Although they don’t use vector stores, all my threads that use files with the code interpreter seem to be similarly failing.
I changed when I attach a file_id and it is now working.
The old code that was failing did this:
thread = client.beta.threads.create()
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=prompt_text,
attachments=[
{
"file_id": openai_file_id,
"tools": [
{ "type": "file_search" },
{ "type": "code_interpreter" }
]
}
]
)
I changed it to this as per the new docs and it works:
thread = client.beta.threads.create(
messages=[
{
"role": "user",
"content": prompt_text,
"attachments": [
{
"file_id": openai_file_id,
"tools": [
{ "type": "file_search" },
{ "type": "code_interpreter" }
]
}
]
}
]
)
Several bugfixes have been deployed yesterday. AFAIK the problem did not affect all users and it will be helpful if you can confirm that the problem has been resolved or follow-up with any ongoing issues.
@oyukruk @CinematicDev @lada @yashcher @erikt @p5developer
In case I forget to ping anyone it’s because I am on mobile
Referencing @erikt 's and @CinematicDev 's insights yesterday we’ve started to create the vector store manually on the thread and it had resolved the issue on our side.
Can’t really check if the original issue persists since we’ve changed our codebase.
For me everything works again (without any changes in the codebase).
I ran the tests again, and everything seems okay.
I just checked and nothing appears to have changed on my end. We are still seeing the same type of errors, which I believe are manifesting a bit differently because we are using the openai-dotnet library instead of manually making calls directly via the API (that part is abstracted).
But the error occurs any time we attempt to create a thread that has messages with file attachments for file search or code interpreter. Threads with no file attachments seem to work fine. The error message I am getting is:
HTTP 500 (server_error: ) The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID req_a4eb1300d878b20c2eebb4f076fcec29 in your email.)
When connected via the remote debugger I can see that this error is thrown right when the dotnet library is hitting _openAIAssistantsClient.CreateThreadAndRunAsync() in our code.
If I look on /threads in the OpenAI platform gui, each attempt we make shows a thread with no messages and no other detail.
I’ve posted a bug over on the Github for the library in case anyone there can provide further insight, but haven’t heard anything yet. Getting HTTP 500 error on creating messages with attachments · Issue #336 · openai/openai-dotnet · GitHub
So, for me, this issue, or at least a highly-related one, still persists exactly as it did yesterday.
I get the same error. Can’t submit thread messages with attachment.
Issue seems to be resolved for us without any code change.
Edit: Nevermind, I just tested again and instead of getting an error 500 like until now, we get a 200 but in the last_error property we still get the same error. Interestingly yesterday night it did work successfully.
To follow up on this issue from my end, someone from OpenAI reached out to me and asked me to try updating the API key we are using to allow write access to /v1/assistants (as a workaround, sounds like).
I did that and things appear to have resumed proper functionality. I was able to submit a few thread runs with file uploads and everything is working as intended, as far as I can tell.
Ultimately we’d probably like to remove write access to /v1/assistants if this workaround is no longer needed if a deeper fix is planned later. But for now, this seems to have gotten us out of the immediate bind.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.