I am using Python API to request Open AI for the file modifications. Every time I make a request assistant replies with a link to download an attachment, however attachment list is always empty. It was working a couple of times, but not anymore.
Assistant creation:
new_assistant = ai_client.beta.assistants.create(
model=CARBON_MODEL,
instructions=CARBON_INSTRUCTIONS,
name=CARBON_PROJECT,
tools=[
{
"type": "code_interpreter",
}
]
)
Running thread:
def run_thread(thread_id):
assistant_id = get_assistant()
run = ai_client.beta.threads.runs.create_and_poll(
assistant_id=assistant_id,
thread_id=thread_id,
)
if run.status == "completed":
process_thread(thread_id, run.id)
Processing thread:
def process_thread(thread_id, run_id = None):
if run_id is None:
messages = ai_client.beta.threads.messages.list(
thread_id=thread_id
)
else:
messages = ai_client.beta.threads.messages.list(
thread_id=thread_id,
run_id=run_id
)
for message in messages:
if message.role == "assistant":
for block in message.content:
if block.type == "text":
parsed_json = extract_json_from_text(block.text.value)
#if "file_id" in parsed_json:
# save_file(parsed_json["file_id"])
for attachment in message.attachments:
save_file(attachment.file_id)
If I uncomment lines to get file_id from JSON output, I then get a following error:
Could not save file: Error code: 400 - {'error': {'message': 'Not allowed to download files of purpose: assistants', 'type': 'invalid_request_error', 'param': None, 'code': None}}