Is attaching a file to a prompt possible through API as it is in the UI?

If I want to add a file (e.g. PDF) along with my prompt as a message (NOT upload it for an assistant or fine-tuning), is there a way to do that through the API?
From what I’m seeing so far, one way to do it is send it all as text in the prompt, but the length limitations are far lower than those in the UI. A file that the UI handles without a problem, runs into token length issues through the API, even with the model with highest token count limit in the context window.

Hi!

What do you want the models to do with that file? :thinking:

If it can’t read all that text, and isn’t supposed to index it, do you want the the model to work the code interpreter to interact with that file? :thinking:

I would want it to read the file (let’s say that contains pages of fiction text) and analyze or answer a question about it, just within that current interaction.
I don’t want it to be stored for knowledge retrieval, as my next interaction would include a new file with new content for answering a set of questions just about the new document.

Hi and welcome to the Developer Forum!

At a fundamental level, the language model simply takes a series of input tokens and processes them into a number of output tokens. The only thing the model understands is those tokens, you must pass the model the text/tokens you wish to be processed.

Text goes in, text comes out. Anything else is a layer of abstraction, there are no files to be handled, you have to open the file read the text and insert that text into the prompt the model will receive, what ChatGPT does is hide all of that away behind the scenes in the form of you uploading a file, with the API you have to handle that yourself.

The Assistants API does do some of this for you if you wish to take a look into that here : https://platform.openai.com/docs/assistants/overview

Got it, I figured as much, as far as handling the file on my side and just passing it as a string within the content, along with the prompt. Where I hit the roadblock was with the token limit. I can run that same file in the UI without a problem. Through the API, I hit the token limit. It seems like that is, at this point, by design?

My alternative does seem to be going the assistants route so that I can actually upload a larger file. This is my understanding:

  1. Upload the file with purpose “assistants”
  2. Create the assistant. Do NOT include the file in the assistant object (As we don’t want the file for retrieval. The file will be different for each thread)
  3. Create a thread, with a message. Include the file id in the message object.
  4. Run the thread with the assistant.

Since the file is not part of the assistant, it will only be relevant for this thread, and not for retrieval. Am I correct in this assumption?

Thank you!