mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 22:42:05 +00:00
feat(perplexity): expose search_results
in chat model (#31468)
Description The Perplexity chat model already returns a search_results field, but LangChain dropped it when mapping Perplexity responses to additional_kwargs. This patch adds "search_results" to the allowed attribute lists in both _stream and _generate, so downstream code can access it just like images, citations, or related_questions. Dependencies None. The change is purely internal; no new imports or optional dependencies required. https://community.perplexity.ai/t/new-feature-search-results-field-with-richer-metadata/398 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mason Daugherty <github@mdrxy.com>
This commit is contained in:
@@ -240,6 +240,65 @@
|
||||
"response.content"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "382335a6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Accessing the search results metadata\n",
|
||||
"\n",
|
||||
"Perplexity often provides a list of the web pages it consulted (“search_results”).\n",
|
||||
"You don't need to pass any special parameter — the list is placed in\n",
|
||||
"`response.additional_kwargs[\"search_results\"]`.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2b09214a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The tallest mountain in South America is Aconcagua. It has a summit elevation of approximately 6,961 meters (22,838 feet), making it not only the highest peak in South America but also the highest mountain in the Americas, the Western Hemisphere, and the Southern Hemisphere[1][2][4].\n",
|
||||
"\n",
|
||||
"Aconcagua is located in the Principal Cordillera of the Andes mountain range, in Mendoza Province, Argentina, near the border with Chile[1][2][4]. It is of volcanic origin but is not an active volcano[4]. The mountain is part of Aconcagua Provincial Park and features several glaciers, including the large Ventisquero Horcones Inferior glacier[1].\n",
|
||||
"\n",
|
||||
"In summary, Aconcagua stands as the tallest mountain in South America at about 6,961 meters (22,838 feet) in height.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{'title': 'Aconcagua - Wikipedia',\n",
|
||||
" 'url': 'https://en.wikipedia.org/wiki/Aconcagua',\n",
|
||||
" 'date': None},\n",
|
||||
" {'title': 'The 10 Highest Mountains in South America - Much Better Adventures',\n",
|
||||
" 'url': 'https://www.muchbetteradventures.com/magazine/highest-mountains-south-america/',\n",
|
||||
" 'date': '2023-07-05'}]"
|
||||
]
|
||||
},
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"chat = ChatPerplexity(temperature=0, model=\"sonar\")\n",
|
||||
"\n",
|
||||
"response = chat.invoke(\n",
|
||||
" \"What is the tallest mountain in South America?\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Main answer\n",
|
||||
"print(response.content)\n",
|
||||
"\n",
|
||||
"# First two supporting search results\n",
|
||||
"response.additional_kwargs[\"search_results\"][:2]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "13d93dc4",
|
||||
|
Reference in New Issue
Block a user