Share via

Updating code_interpreter file_ids using Python at Azure OpenAi Assistant

Mohamed Hussein 715 Reputation points
2024-11-13T18:09:21.6566667+00:00

Hi,

I was trying to update code_interpreter file_ids using Python at Azure OpenAi Assistant,

but got the following error, any work arounds?

To best of my knowledge only 20 file_ids supported

An error occurred: Error code: 400 - {'error': {'message': "Invalid 'tool_resources.azure_ai_search.indexes': empty array. Expected an array with minimum length 1, but got an empty array instead.", 'type': 'invalid_request_error', 'param': 'tool_resources.azure_ai_search.indexes', 'code': 'empty_array'}}
Updating code_interpreter file_ids using Python at Azure OpenAi Assistant
     if len(my_thread.tool_resources.code_interpreter.file_ids) > 19:
      my_thread.tool_resources.code_interpreter.file_ids.pop()

     my_thread.tool_resources.code_interpreter.file_ids.append(message_file.id) 
     my_thread = client.beta.threads.update(
         my_thread.id,
         tool_resources = my_thread.tool_resources
         )
Updating code_interpreter file_ids using Python at Azure OpenAi Assistant
Azure OpenAI in Foundry Models

Answer accepted by question author

YutongTie-9091 54,021 Reputation points Moderator
2024-11-13T21:28:32.9166667+00:00

Hello Mohamed,

Thanks for reaching out to us and share the insight here. Are you mentioning you want to just remove the oldest file from your file list and add a new one?

This scenario seems not covered in the official document.

I know there is a 20 files limit for code interpreter from OpenAI document but it seems the Azure official document not mentions it.

This issue seems related to the structure more, I would suggest you try to enable the azure_ai_search.indexes is populated as below. Or another way, you may just update your file list and update your assistant directly.

Please have a try and let us know how it works, if it is not working, I would recommend you raising a support ticket for this case, I am happy to enable you a free ticket since this scenario is not covered and the feature is still on preview stage.

# Ensure azure_ai_search.indexes is populated, even if it's a placeholder
if not my_thread.tool_resources.azure_ai_search.indexes:
    my_thread.tool_resources.azure_ai_search.indexes = ["your_index_name"]  # Replace with your actual index name if using Search 

# Maintain the file_ids limit of 20 by removing the oldest file_id if needed
if len(my_thread.tool_resources.code_interpreter.file_ids) >= 20:
    my_thread.tool_resources.code_interpreter.file_ids.pop(0)

# Append the new file_id
my_thread.tool_resources.code_interpreter.file_ids.append(message_file.id)

# Update the thread with the fully populated tool_resources
my_thread = client.beta.threads.update(
    my_thread.id,
    tool_resources=my_thread.tool_resources
)


I hope this helps.

Regards,

Yutong

-Please kindly accept the answer if you feel helpful to support the community, thanks a lot.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.