#I've created an assistant but I don't know how to pass files to it

1 messages · Page 1 of 1 (latest)

fiery cypress
#

This is my code so far:

from openai import OpenAI

client = OpenAI(api_key='sk-proj-****')

def upload_file(file_path):
    message_file = client.files.create( file=open(file_path, "rb"), purpose="assistants" )
    return message_file.id


file1_id = upload_file('ms.pdf')
file2_id = upload_file('qp.pdf')

thread = client.beta.threads.create()

thread_message = client.beta.threads.messages.create(
    thread.id,
    role="user",
    content=f"Please process the uploaded files: {file1_id}, {file2_id}",
    attachments=[
        {"file_id": file1_id, "tools": [{"type": "file_search"}] },
        {"file_id": file2_id, "tools": [{"type": "file_search"}] }
    ]
)

run = client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id='asst_BfH0UddVXys0nW8iYG5pNWf1'
)

print(thread_message)
if run.status == 'completed': 
    messages = client.beta.threads.messages.list( thread_id=thread.id )
    print(messages)
else:
    print(run.status)

Its going to be a simple program where I can upload an exam question paper and markscheme and it returns it in a specific format (on the assistants system prompt)