语境化问答 API
Contextual Answers API 是一种根据特定文档上下文提供准确可靠的问题解答的工具。API 有两种操作模式:
- 单文档语境化问答: 此功能接收文档文本和问题,并仅根据提供的上下文返回答案。此方法要求在向 API 发出的每个请求中将上下文与问题一起发送。
- 在此处尝试单文档语境化问答。
- 文档库语境化问答: 一项新功能,允许用户提前上传多个文档到“文档库”,然后根据这些存储的文档检索答案。此方法仅需要在 API 请求中发送问题,并返回在文档库中找到的答案,以及有关在哪个或哪些文档中找到答案的信息。
- 在此处尝试文档库语境化问答
用户还有一组 API 来管理他们的文档库。包括上传文档、获取文档列表、通过id获取文档、更新文档、删除文档等操作。
请求参数
Contextual Answers API 需要不同的参数,具体取决于所使用的方法:
对于单文档语境化问答:
context
:包含要回答问题的文档上下文的字符串。限制:50,000 个字符。question
:包含要根据提供的上下文回答的问题的字符串。限制:160 个字符。
对于文档库语境化问答:
question
:一个字符串,包含根据库中的文档要回答的问题。限制:150 个字符。path
:指定文档在库中的路径的字符串。选修的labels
:表示回答问题时要考虑的文档标签的字符串数组。选修的documentIds
:文档 ID 数组,用于指定回答问题时要考虑哪些文档。选修的
响应参数
对于单文档语境化问答:
Contextual Answers API 在其响应中返回以下参数:
answer
:包含基于所提供上下文的问题答案的字符串。如果模型无法在提供的上下文中找到答案,则会做出响应。`id
:API 分配的唯一标识符,用于标识生成响应的特定请求。此参数对于跟踪和记录目的非常有用,特别是在向 API 发出多个请求时。
对于文档库语境化问答:
Contextual Answers API 在其响应中返回以下参数:
answer
:包含基于文档库内容的问题答案的字符串。如果模型无法在库中的任何位置找到答案,则会做出响应。`id
:API 分配的唯一标识符,用于标识生成响应的特定请求。此参数对于跟踪和记录目的非常有用,特别是在向 API 发出多个请求时。answerInContext
:一个布尔值,指示是否在文档库中找到了答案。sources
:对象数组,其中每个对象代表一个在其中找到答案的源文档。每个源对象包含:
document_id
:源文档的唯一标识符。name
:源文档的名称。highlights
:包含源文档中与答案相关的部分的字符串数组。publicUrl
:指向源文档的 URL(如果可用)。
示例:单文档语境化问答
Python
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?"
}
以下是 Contextual Answers [Single Document] API 对上述示例请求的可能响应:
JSON
{
"id": "36d2ec63-ef15-2296-af51-ef34206fc655",
"answer": "The Delta and Omicron variants and the global supply chain shortages did not slow down economic growth."
}
示例:文档库语境化问答
Python
payload = {
"question": "During the past decade, what amount did the bank remunerate the Federal Deposit Insurance Corporation?",
"labels": ["financial_reports", "banking"]
}
以下是 Contextual Answers [文档库] API 对上述示例请求的可能响应:
JSON
{
"id":"28a6f1a8-31f3-cca4-d71a-6bca2e62d124",
"answerInContext":true,
"answer":"JPMorgan Chase paid the Federal Deposit Insurance Corporation $11 billion over the past decade.",
"sources":[
{
"document_id":"f8527829-c036-4d3a-9a6e-3169f4db1765",
"name":"examples/banking/jpmorgan-annual-report-2021.txt",
"highlights":[
"I do just want to note that in our case, the silent partner is not so silent.\n\nJPMorgan Chase is a healthy and thriving company, and we always want to give\r\nback and pay our fair share.\n\nWe do — and we want it to be spent well and have\r\nthe greatest impact.\n\nTo give you an idea of where our taxes and fees go: In the\r\nlast 10 years, we paid $42 billion in federal, state and local taxes in the United\r\nStates and $17 billion in taxes outside of the United States.\n\nWe also paid the\r\nFederal Deposit Insurance Corporation $11 billion so that it has the resources\r\nto cover the failure of any major American bank.",
"31 Traditional assets include Equity, Fixed Income, Multi-Asset and Liquidity assets under\r\n2 Federal Deposit Insurance Corporation (“FDIC”)\n\n2021 Summary of Deposits survey per S&P management; Brokerage, Administration and Custody assets under supervision.",
"In addition to banks’ shrinking global role, you\r\n U.S. debt and equity markets, down from 11% can see that the number of public companies,\r\n in 2010.\n\nwhich should have grown substantially over the\r\n• Conversely, U.S. banks’ liquid assets are up past decade, is remarkably reduced.\n\nInstead, U.S.\r\n more than 300% to $8.6 trillion, most of which public companies peaked in 1996 at 7,300 and\r\n is needed to meet liquidity requirements.\n\nnow total 4,800.\n\nConversely, the number of pri-\r\n vate U.S. companies backed by private equity\r\n• Banks’ share of mortgage originations has companies has grown from 1,600 to 10,100 — a\r\n gone from 91% to 32%.\n\nremarkable increase.",
"Before we give an update on the\r\n million customer accounts — refunding more\r\nstructural shifts taking place, it would be good to\r\n than $250 million for nearly 2 million consumer\r\naddress the question: How did banks perform\r\n deposit and lending accounts and offering\r\nduring the recent COVID-19 crisis?",
"Although I begin this annual letter to shareholders in a challenging landscape,\r\nI remain proud of what our company and our hundreds of thousands of employ-\r\nees around the world have achieved, collectively and individually.\n\nAs you know,\r\nwe have long championed the essential role of banking in a community — its\r\npotential for bringing people together, for enabling companies and individuals to\r\nreach for their dreams, and for being a source of strength in difficult times.\n\nThroughout these past two challenging years, we never stopped doing all the\r\nthings we should be doing to serve our clients and our communities.\n\nLooking back on the last year and the past two decades — starting from my time\r\nas CEO of Bank One in 2000 — it is clear that our financial discipline, constant\r\ninvestment in innovation and ongoing development of our people are what\r\nenabled us to persevere in our steadfast dedication to help clients, communities\r\nand countries throughout the world."
],
"publicUrl":"https://www.jpmorganchase.com/ir/annual-report"
}
]
}
最后修改时间: 1 年前