Uploading a documentation pdf

Is it possible to upload a .txt file to OpenAI?
I want the LLM to use the file as a reference/context to answer questions.
The Objective is to avoid having to send multiple messages just to tell the LLM the context.

Hi and welcome to the Developer Forum!

The model is “stateless” it has no memory of prior events, even if you were to upload a text file it would have to read it each time and you would have to allocate and pay for that number of tokens each time, there is currently no way to avoid this.

1 Like

Thanks for you explanation @Foxalabs .

I have a related question. Is it possible to send a PDF (or a TXT file version of the PDF) that only contains text (no images) via the API and ask the questions at time of upload e.g. please summarise the document, and identify keywords? I currently send the contents in chunks with overlaps and then consolidate the results but I imagine it’s much cleaner to give it the whole doc.?

Supplying the entire document will always be superior to any form of vector retrieval. So if your budget and context allows, then you should do so, but for a great many use cases that is simply not practical. RAG (retrieval augmented generation) can be VERY powerful when the chunking and the text being searched against are well constructed.

1 Like

Thanks for your quick reply!

In many cases the context will allow for it but not for all, so I’ll need to keep the fallback option in there!

To attach a file to the chat API, is there an example of how to do it? Do I need to upload the file first and get the ID, then use the ID in the next step with the prompt? If so, what should purpose be set up e.g. in fine tuning job, we upload the file to OpenAI first via:

file=open(“file path”, rb),

Thanks :slight_smile:

1 Like

Yes, you upload data to the assistants endpoint for later use. You can find the documentation here https://platform.openai.com/docs/assistants/tools/uploading-files-for-retrieval

1 Like

Amazing thank you :pray:. I hadn’t realized I should look at the Assistants code samples.

1 Like