Comparing PDF Files to get Changes


I know that it is possible to upload files to GPT-4 paid version and tell it to compare them in a prompt, I was wondering if I can do the same through Python API, as far as I know files can be uploaded to assistants and can be set to knowledge retrieval but I just want to compare the two files even if they had images in them (given they are PDF files) and everything and for it to tell me the differences.

Is this available or doable in any way?
Thanks in advance!

Sure, if OpenAI can program it, you can program it, and you can do it a bit more efficiently and task-oriented.

For searchable PDFs that have text embedded, there’s a couple different python libraries that can extract text from PDFs.

For those PDFs that are primarily images, you’ll need to do some additional OCR on the pages, also possible to do with Python (a forum search for “python ocr” might be a good start).

Doing a per-page extraction, you can easily identify the magnitude of differences in code, even if just by length of text. You can then just send and inquire about those with differences (although insertions may change all following pages).

Then you just need to select the most performative and affordable model with the context length required to have the tokens of both texts loaded at the same time.

1 Like


Thanks for your reply!

What you mentioned is what I had in mind at first indeed, but I was wondering if there was any direct way to compare the 2 PDF files directly just like the paid version but through the API.

I take it that there is no direct way to do this through the Python API, right?

Thanks so much for your help!

The API is language-agnostic. Python is just one of many languages you can use to interact with the RESTful API for OpenAI models.

“Assistants” on the API has ‘code interpreter’, where you can upload files, and then have the AI use its own python writing skills to perform tasks. It may be able to perform some of the PDF parsing for you with its own python code and then get the returned descriptions to answer the same way.

If the AI can code it, the AI can also give a coding solution to you, and if the AI can barely code it, you can work on the project with the AI until it is immutable code that works 100% on your side.

“retrieval” and files upload will also allow PDFs and does some PDF to text. The resulting “files” then can be attached to messages. However, the operation of this is opaque and you would have to try it yourself to see how well the AI can answer.

1 Like