How can I upload two .md files and ask about their contents?

I’m new to OpenAI and want to try uploading two .md files. After that, I need to ask about their contents. The original .md file is very large, which is why I split it into two sections. I’ve read the documentation, but I’m still unsure about what (thread_id) is.

def uploading_file(path_1,path_2):
    
    file_1 = client.files.create(

        file = open(path_1, "rb"),
        purpose='assistants'
    )
    print(f"file {file_1.filename} uploaded!")  
    
    file_2 = client.files.create(

        file = open(path_2, "rb"),
        purpose='assistants'
    )
    print(f"file {file_2.filename} uploaded!")  

    '''
    assistant = client.beta.assistants.create(
            instructions= 'You will be provided with a long document. Your task is to answer the question ....etc',
            model='gpt-4-0125-preview',
            tools=[{'type':'retrieval'}])


    # my assistant id is => #############################

    '''

    answer = client.beta.threads.messages.create(
        thread_id="", #### ????
        role="user",
        content="I want to know about ...etc",
        
        )
    
    return answer

Any idea how to do this?

1 Like

Threads are the object which contain all the messages from a conversation. You need to create a thread and add the messages to it: https://platform.openai.com/docs/assistants/overview/step-2-create-a-thread

If you want to attach files, you have three options:

  • Add the file at the Assistant level
  • Add the file at the Thread level
  • Add the file at the Message level

All of which have different tradeoffs. If you are building something where many users will interact with the same Assistant and ask questions, it should be at the Assistant level. If the file is specific to one users or conversation, it should be at the thread or message level.

1 Like