I can get around this bug by doing the following:
- Attach the files to the thread when you create the thread
- In the subsequent queries, add messages with the same Files and this time they are noted. Here is my code, which generally works:
# First question in this topic
def startthread(query):
global Thread
Thread = Client.beta.threads.create(messages=[
{
"role": "user",
"content": query,
"file_ids": threadfiles()
}
])
return
# Subsequent questions in the same topic
def qtothread(query):
global Thread
thread_message = Client.beta.threads.messages.create(
Thread.id,
role="user",
content=query,
file_ids=threadfiles()
)
You still get the random BadRequestError
. For example, in my last run, I had the following Q&A chain:
Q1. My first question.
A1. I don’t know
Q2:The answer is in the attached text files. Please read them and answer the question. Repeat first question.
A2: Correct answer.
Q3: Follow-up question (this time only the question, not the preamble on the attached text files)
A3: Correct answer.
Q4: Another follow-up question
It bombed out with the following error:
BadRequestError Traceback (most recent call last)
...
run = Client.beta.threads.runs.create(
20 thread_id=Thread.id,
21 assistant_id=AssistantID,
22 instructions=Assistant.instructions)
...
...
raise self._make_status_error_from_response(err.response) from None
886 except httpx.TimeoutException as err:
887 if retries > 0:
BadRequestError: Error code: 400 - {'error': {'message': 'Failed to index file', 'type': 'invalid_request_error', 'param': None, 'code': None}}
The API also is very slow in giving answers. It was not like this before.
In conclusion, the above method is useful when you have the same set files for every interaction in one thread. There is still the random BadRequestError
but I have a feeling that its cause is different.