Assistants API support CSV files?

Hi all! Anyone know how I can use csv files if I pass it via the API? I am calling the OpenAI Assistants API via Google Sheet’s Google Apps Script. I want to be able to upload csv data files using GDrive file paths.

Seems like per the API, I need to store it in vector store then call it with file search but csv is not a file search supported file. Saw some posts mentioning that if code interpreter is enabled, then it can take csv. I do have code interpreter and file search enabled but same issue.

If I use it in the playground on the UI, I’m able to use the code interpreter section to add but not in the file search section. But via API, I have to give it the file to save down first and need it to be retrieved by file search before I can run code interpreter on it.

Is there a workaround I’m missing or what would be the best workaround? Any insight would be appreciated!

Have you tried something like:

file = client.files.create(
  file=open("mystuff.csv", "rb"),
  purpose='assistants'
)

then use it as a tool resource for the code interpreter?
That method is from creating assistants example

Hey thanks for responding! I’ve tried this but having difficulty retrieving the file’s contents in subsequent messages

What error are you getting? Also, did you verify that the ‘file.id’ shows up in your dashboard? If it’s there, then most likely the assistant is missing a tool or tool resource to find the file during the thread run (that the subsequent messages are attached to)

What you need to do is to upload the file to OpenAI, create a message with the file in it, finish the stream. Here’s how I did it on my side

Step 1 upload the file to OpenAI:

            openAiFile = await openai.files.create({
               file,
              purpose: "assistants"
            });

Step 2 create a message with the file as an attachement and the tool list with code_execution:

    const createdMessage = await openai.beta.threads.messages.create(threadId!, {
        role: 'user' as 'user' | 'assistant',
        content: data.message.toString(),
        attachments: openAiFile ? [
            {
                file_id: openAiFile.id,
                tools: toolList
            }
        ] : []
    });

OpenAssistantGPT/app/api/chatbots/[chatbotId]/chat/route.ts at main · marcolivierbouch/OpenAssistantGPT · GitHub

Step 3 finish to run the stream:

             const runStream = openai.beta.threads.runs.stream(threadId!, {
                    assistant_id: chatbot.openaiId,
                    instructions: (data.clientSidePrompt || "").replace('+', '') || "",
                    tools: [
                        { type: "file_search" },
                        { type: "code_interpreter" },
                    ],
                    max_completion_tokens: chatbot.maxCompletionTokens,
                    max_prompt_tokens: chatbot.maxPromptTokens,
                });

You can check the full code in github :slight_smile: or you can always use my hosted solution. Don’t hesitate if you have more question!

Here you have Assistant + Instructions + 2 functions python and json versions (is not perfect, but enough for you to have an idea and to start to move faster using CSV files with Assistant).

In the video you can see the How Assistant Manipulate CSV files at min 14:19:


This kind of approach need a lot of work. And I think worth it because Assistants are capable to do multiple tasks and can speak with multiple persons in same time.


Here is another demonstration I made 1-2 months ago, but with assistants version 1, that slower version.
Check at min 03:05

And here is FlexiAI repository