ChatGPT Powered Question Answering Over Documents

FREEMIUM
Health Check

N/A

Back to All Tutorials (1)

ChatGPT Powered Question Answering Over Documents

There are 2 ways to use this API as below

**NOTE: **You need to upload the text as a string - currently you can’t upload entire documents (like PDF or other formats). An option around this is to first extract the text using a library (e.g. PyMUPDF for PDF to text) and then use the URL as part of your pipeline:

  1. Insert text and query and obtain answer as below (in the example below, text is a string containing the entire BERT paper):

url = “https://chatgpt-powered-question-answering-over-documents.p.rapidapi.com/qa877

payload = {
“text”: text,
“query”: “Summarize in 3 sentences”
}
headers = {
“content-type”: “application/json”,
“X-RapidAPI-Key”: “BLAH”,
“X-RapidAPI-Host”: “chatgpt-powered-question-answering-over-documents.p.rapidapi.com
}

response = requests.request(“POST”, url, json=payload, headers=headers)

print(response.text)

{
“answer”: “BERT is a deep bidirectional transformer pre-trained for language understanding. It is trained on a 3.3 billion word corpus with a batch size of 256 sequences for 1,000,000 steps. The pre-training tasks include Masked LM and Next Sentence Prediction, which are illustrated with examples.”,
“id”: “1875011f-1a4e-40af-9b5c-77e6ba1729fd”,
“message”: “Successful”,
“status”: true
}

  1. Once you have an article uploaded, you can use the id to query on the same document (without needing to upload again!) as follows:

import requests

url = “https://chatgpt-powered-question-answering-over-documents.p.rapidapi.com/qa877

payload = {
“id”: “1875011f-1a4e-40af-9b5c-77e6ba1729fd”,
“query”: “What is BERT trained on?”
}
headers = {
“content-type”: “application/json”,
“X-RapidAPI-Key”: “BLAH”,
“X-RapidAPI-Host”: “chatgpt-powered-question-answering-over-documents.p.rapidapi.com
}

response = requests.request(“POST”, url, json=payload, headers=headers)

print(response.text)

{
“answer”: “BERT is trained on unlabeled data over different pre-training tasks.”,
“id”: “1875011f-1a4e-40af-9b5c-77e6ba1729fd”,
“message”: “Successful”,
“status”: true
}

And that’s it! Feel free to let me know if you have any questions.