How can I upload pdf files in chatgpt and ask for a summary of it?

Hi, I need to send files and interact with them, but I only find separated paths:

from openai import OpenAI
client = OpenAI()

client.files.create(
  file=open("mydata.jsonl", "rb"),
  purpose="fine-tune"
)
from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

Is there a way that I can send files in the same request to tell ChatGPT what do I need? or is there a way that I can back and tell it watch the past files?

Which is the best way to upload data files?

Thanks.

Sometime back I wrote a simple code base to read and ask questions from PDF file using Open AI and Langchain and that may help you.
Have a look it at here.

from langchain.document_loaders import PyPDFLoader
from langchain.llms import OpenAI
from langchain.chains.question_answering import load_qa_chain

#Locate your PDF here.
pdf="<YOUR_PDF_GOES_HERE>"
#Load the PDF
loader = PyPDFLoader(pdf)
documents = loader.load()

api_key = "sk-?????"
llm = OpenAI(openai_api_key=api_key)
chain = load_qa_chain(llm,verbose=True)
question = input("Enter your question here : ")
response = chain.run(input_documents=documents, question=question)
print(response) 

Happy coding!

5 Likes

Thank you.

I only need to know something, if I have more files and I want to get a summary about all of them, what is the best way to upload them?, or what can I do to if I need that my chatbot remember the information in the future?. :slightly_smiling_face:

Your best bet would be to look into using the Assistants API, you can create the assistant and add as many files as you need. Then enable the retrieval tool and you should be able to then chat with the assistant about any info in any of those documents.

3 Likes

@BrokenSoul

As this topic has a selected solution, closing topic.

A post was split to a new topic: ‘Max Tokens’ Query: A Beginner’s Doubt