#Can't associate files with assistant

1 messages · Page 1 of 1 (latest)

sly solstice
#

I'm using openai-python@v1.1.0 SDK to upload files and create a retrieval assistant like this:

client = OpenAI()
# file creation works
client.files.create(file=Path("schema.csv"), purpose="assistants")
# error is thrown when creating an assistant
assistant = client.beta.assistants.create(
        name="SQL Assistant",
        model="gpt-4-1106-preview",
        tools=[{"type": "retrieval"}],
        file_ids=[file.id],
        instructions="You're a general purpose SQL assistant.",
    )

I get this error when passing in a CSV file:

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Failed to index file: Unsupported file file-v4z09tCj72aswCfxmUJB9Ggq type: application/csv', 'type': 'invalid_request_error', 'param': None, 'code': None}}

...and this error when passing in a JSON file:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid file format. Supported formats: ['c', 'cpp', 'csv', 'docx', 'html', 'java', 'json', 'md', 'pdf', 'php', 'pptx', 'py', 'rb', 'tex', 'txt', 'css', 'jpeg', 'jpg', 'js', 'gif', 'png', 'tar', 'ts', 'xlsx', 'xml', 'zip']", 'type': 'invalid_request_error', 'param': None, 'code': None}}

... even though csv and json file types are listed as supported.

The files in question are well-formed, short, and simple (they describe a table schema with three columns).

I've followed instructions here closely: https://platform.openai.com/docs/assistants/how-it-works/agents

Am I doing something obviously wrong? Or is the assistant API broken?

sly solstice
#

Uploading and using a file in the playground works fine.

gilded walrus
#

Yeah I'm having this same problem too.

#

The weird thing is it works if you have a JSON with empty elements, like
[]
or [{}, {}]

#

But as soon as I put content inside, it just breaks for some reason?

#

@sly solstice Okay I'm not sure why this works,

#

but if I replace all the double quotes (") with single quotes (') in the JSON file, it works

sly solstice
#

eeenteresting! I might give that a go (though I Really want CSV to start working)

brave anvil
#

I haven't been able to get any file to be read for retrieval. always get a myfiles_browser error

#
import os
import argparse
from openai import OpenAI

parser = argparse.ArgumentParser('summarize a file')
parser.add_argument('--file',type=str,help="filename of text to summarize")
args = parser.parse_args()

client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
with open(args.file,'rb') as f:
    file_id = client.files.create(file=f,purpose="assistants").id
    print(f"created file {file_id}")

assistant = client.beta.assistants.create(
    name="summarize",
    description="summarize a file",
    model="gpt-4-1106-preview",
    tools=[{"type":"retrieval"}],
    file_ids=[file_id]
)

thread = client.beta.threads.create(
    messages = [
        {
            "role":"user",
            "content":"summmarize the file",
            "file_ids":[file_id]
        }
    ]
)
run = client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id=assistant.id
)
run_id = run.id
print(f"created run {run_id}")

while run.status != "completed" and run.status != "failed" and run.status != "expired" and run.status != "cancelled":
    run = client.beta.threads.runs.retrieve(thread_id=thread.id,run_id=run_id)

print(f"run status: {run.status} run: {run}")
messages = client.beta.threads.messages.list(thread_id=thread.id)
print(f"messages: {messages}")
for message in messages:
    text = message.content[0].text.value
    print(f"message: {text}")
#

It appears there has been a misunderstanding. The file you've uploaded is not accessible through the myfiles_browser tool, which I use for browsing and extracting information from documents.\n\nTo provide a summary, I would need access to the file's contents. Since I cannot read the file directly through the tool, could you please check the file's accessibility settings or upload the file again? Additionally, ensure that the file format is one that's supported for browsing, such as a text-based file (e.g., .txt, .pdf, .docx). If the file format is one that I can't process, like an image or proprietary format, I wouldn't be able to summarize it for you.

sly solstice
#

When trying the "single quote" json hack by @gilded walrus , even though the file creation and assistant creation succeeds, when I run a thread I get a message like:

It seems the file provided does not contain the schema information required to create the SQL query, and I am not able to directly access the file content using the browsing tool.

gilded walrus
# sly solstice When trying the "single quote" json hack by <@1117111525161840752> , even though...

Is the file that you're retrieving long? I know for the retrieval tool, if the file is relatively short it'll just pass the whole thing into the context, but if it's long, it'll use vector searches, so important info from the file might be missing from the context, hence it saying file provided does not contain the schema information required to create the SQL query. I'd recommend trying to enable the code interpreter tool as well and see if that helps. Worst case scenario, you might be able to just put the whole content of the file into the messages manually.