Skip to content

The agent engineering platform.

community: update perplexity documentation (#30450)

David Sánchez Sánchezd7b13e12ee82
diff --git a/docs/docs/integrations/chat/perplexity.ipynb b/docs/docs/integrations/chat/perplexity.ipynb
index b2545aad14..2a9c0efce0 100644
--- a/docs/docs/integrations/chat/perplexity.ipynb
+++ b/docs/docs/integrations/chat/perplexity.ipynb
@@ -173,6 +173,41 @@
"response.content"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "a7f8f61b",
+ "metadata": {},
+ "source": [
+ "## Using Perplexity-specific parameters through `ChatPerplexity`\n",
+ "\n",
+ "You can also use Perplexity-specific parameters through the ChatPerplexity class. For example, parameters like search_domain_filter, return_images, return_related_questions or search_recency_filter using the extra_body parameter as shown below:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "73960f51",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\"Sure, here's a cat joke for you:\\n\\nWhy are cats bad storytellers?\\n\\nBecause they only have one tale. (Pun alert!)\\n\\nSource: OneLineFun.com [4]\""
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "chat = ChatPerplexity(temperature=0.7, model=\"llama-3.1-sonar-small-128k-online\")\n",
+ "response = chat.invoke(\n",
+ " \"Tell me a joke about cats\", extra_body={\"search_recency_filter\": \"week\"}\n",
+ ")\n",
+ "response.content"
+ ]
+ },
{
"cell_type": "markdown",
"id": "13d93dc4",
@@ -216,13 +251,56 @@
],
"source": [
"chat = ChatPerplexity(temperature=0.7, model=\"llama-3.1-sonar-small-128k-online\")\n",
- "prompt = ChatPromptTemplate.from_messages(\n",
- " [(\"human\", \"Give me a list of famous tourist attractions in Pakistan\")]\n",
- ")\n",
- "chain = prompt | chat\n",
- "for chunk in chain.stream({}):\n",
+ "\n",
+ "for chunk in chat.stream(\"Give me a list of famous tourist attractions in Pakistan\"):\n",
" print(chunk.content, end=\"\", flush=True)"
]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "397c43de",
+ "metadata": {},
+ "source": [
+ "## `ChatPerplexity` Supports Structured Outputs for Tier 3+ Users"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "1bae9b80-394a-4340-9c30-612c136b742a",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "AnswerFormat(first_name='Michael', last_name='Jordan', year_of_birth=1963, num_seasons_in_nba=15)"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "from pydantic import BaseModel\n",
+ "\n",
+ "\n",
+ "class AnswerFormat(BaseModel):\n",
+ " first_name: str\n",
+ " last_name: str\n",
+ " year_of_birth: int\n",
+ " num_seasons_in_nba: int\n",
+ "\n",
+ "\n",
+ "chat = ChatPerplexity(temperature=0.7, model=\"sonar-pro\")\n",
+ "structured_chat = chat.with_structured_output(AnswerFormat)\n",
+ "response = structured_chat.invoke(\n",
+ " \"Tell me about Michael Jordan. Return your answer \"\n",
+ " \"as JSON with keys first_name (str), last_name (str), \"\n",
+ " \"year_of_birth (int), and num_seasons_in_nba (int).\"\n",
+ ")\n",
+ "response"
+ ]
}
],
"metadata": {
@@ -241,7 +319,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.12"
+ "version": "3.10.4"
}
},
"nbformat": 4,