I have a problem, that when I try to use multiple files for the Assistant API, the first attachment is duplicated.
1. One file:
filepath = “C:\tst.xlsx”
client.files.create(
file=open(filepath, “rb”),
purpose=“assistants”
)
thread_message = client.beta.threads.messages.create(
thread_id=empty_thread.id,
role=“user”,
content=“blablabla”,
)
This works fine. No problem.
2. Two files:
filepath = “C:\tst.xlsx”
filepatha = “C:\tsta.xlsx”
uploaded_file = client.files.create(
file=open(filepath, “rb”),
purpose=“assistants”
)
uploaded_file_id = uploaded_file.id
uploaded_filea = client.files.create(
file=open(filepatha, “rb”),
purpose=“assistants”
)
uploaded_file_ida = uploaded_filea.id
#ABC
thread_message = client.beta.threads.messages.create(
thread_id=empty_thread.id,
role=“user”,
content=“blablabla”,
file_ids=[uploaded_file_id,uploaded_file_ida],
)
The first file is used twice.
I believe that it’s beacause for the first time it’s loaded thru client.files.create and for the second time thru file_ids=
I can solved it by adding client.files.delete to the #ABC position. But it’s seems to me quite weird.
Is there a better way?