Try Contextual Answers API here

The Contextual Answers API is a tool for providing accurate and reliable question answering based on specific document context. This API is designed to avoid any factual issues that may arise when using language models to provide answers. It receives document text and a question and returns an answer based solely on the provided context. This means that if the answer to a question is not in the document, the model will indicate this rather than providing a potentially inaccurate answer. As a task-specific API, it is optimized for efficiency and can be easily integrated into existing systems without requiring any prompt engineering. Overall, the Contextual Answers API provides a user-friendly and efficient solution for accurate and context-based question answering.

Request Parameters

The Contextual Answers API requires two parameters for a successful request:

  • context: A string containing the document context for which the question will be answered. Limit: 50,000 characters.
  • question: A string containing the question to be answered based on the provided context. Limit: 160 characters.

Response Parameters

The Contextual Answers API returns the following parameter in its response:

  • answer: A string containing the answer to the question based on the provided context. The answer will be null if the model cannot find an answer in the provided context.
  • id: A unique identifier assigned by the API to identify the specific request that generated the response. This parameter can be useful for tracking and logging purposes, particularly if multiple requests are being made to the API.

Example

payload = {
    "context": "In 2020 and 2021, enormous QE — approximately $4.4 trillion, or 18%, of 2021 gross domestic product (GDP) — and enormous fiscal stimulus (which has been and always will be inflationary) — approximately $5 trillion, or 21%, of 2021 GDP — stabilized markets and allowed companies to raise enormous amounts of capital. In addition, this infusion of capital saved many small businesses and put more than $2.5 trillion in the hands of consumers and almost $1 trillion into state and local coffers. These actions led to a rapid decline in unemployment, dropping from 15% to under 4% in 20 months — the magnitude and speed of which were both unprecedented. Additionally, the economy grew 7% in 2021 despite the arrival of the Delta and Omicron variants and the global supply chain shortages, which were largely fueled by the dramatic upswing in consumer spending and the shift in that spend from services to goods. Fortunately, during these two years, vaccines for COVID-19 were also rapidly developed and distributed.In today's economy, the consumer is in excellent financial shape (on average), with leverage among the lowest on record, excellent mortgage underwriting (even though we've had home price appreciation), plentiful jobs with wage increases and more than $2 trillion in excess savings, mostly due to government stimulus. Most consumers and companies (and states) are still flush with the money generated in 2020 and 2021, with consumer spending over the last several months 12% above pre-COVID-19 levels. (But we must recognize that the account balances in lower-income households, smaller to begin with, are going down faster and that income for those households is not keeping pace with rising inflation.) Today's economic landscape is completely different from the 2008 financial crisis when the consumer was extraordinarily overleveraged, as was the financial system as a whole — from banks and investment banks to shadow banks, hedge funds, private equity, Fannie Mae and many other entities. In addition, home price appreciation, fed by bad underwriting and leverage in the mortgage system, led to excessive speculation, which was missed by virtually everyone — eventually leading to nearly $1 trillion in actual losses.",
    "question": "Did the economy shrink after the Omicron variant arrived?"
}

The following is a possible response from the Contextual Answers API to the example request above:

{
  "id": "36d2ec63-ef15-2296-af51-ef34206fc655",
  "answer": "The Delta and Omicron variants and the global supply chain shortages did not slow down economic growth."
}