Assistant API: Analyzing with code interpreter a dataframe result of a query created by the assistant

Hello everyone, I would like to analyze with code interpreter a dataframe returned from executing a SQL query created by the assistant.

I created the following code:

file = client.files.create(file=df.to_json(index=False).encode(),purpose="assistants")

message = client.beta.threads.messages.create(
                                        thread_id=thread.id,
                                        role="user",
                                        content="Here is the result of the query execution. Please analyze this data and return an appropriate data visualization",
                                        file_ids=[file.id]
                                    )

however I get the following error:

query failed with error: Error code: 400 - {'error': {'message': "Can't add messages to Thread_XXX while a run run_XXX is active.", 'type': 'invalid_request_error', 'param': None, 'code': None}}

My challenge is understanding where should I place the upload to the assistant in order to do it AFTER the dataframe is available?
Is there a part of logic I am missing?

Thank you in advance for your help!

check wait_on_run in Assistants API Overview (Python SDK) | OpenAI Cookbook

1 Like