Skip to content

Commit

Permalink
docs[patch]: fix broken anchor link (#28358)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme authored Nov 26, 2024
1 parent c161f7d commit a97c53e
Showing 1 changed file with 74 additions and 66 deletions.
140 changes: 74 additions & 66 deletions docs/docs/integrations/chat/writer.ipynb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"cells": [
{
"metadata": {},
"cell_type": "raw",
"id": "85e07aae70a15572",
"metadata": {},
"source": [
"---\n",
"sidebar_label: Writer\n",
"---"
],
"id": "85e07aae70a15572"
]
},
{
"cell_type": "markdown",
Expand All @@ -17,16 +17,17 @@
"source": [
"# ChatWriter\n",
"\n",
"This notebook provides a quick overview for getting started with Writer [chat models](/docs/concepts/#chat-models).\n",
"This notebook provides a quick overview for getting started with Writer [chat models](/docs/concepts/chat_models).\n",
"\n",
"Writer has several chat models. You can find information about their latest models and their costs, context windows, and supported input types in the [Writer docs](https://dev.writer.com/home/models).\n",
"\n",
":::"
]
},
{
"metadata": {},
"cell_type": "markdown",
"id": "617a6e98205ab7c8",
"metadata": {},
"source": [
"## Overview\n",
"\n",
Expand All @@ -47,27 +48,26 @@
"### Credentials\n",
"\n",
"Head to [Writer AI Studio](https://app.writer.com/aistudio/signup?utm_campaign=devrel) to sign up to OpenAI and generate an API key. Once you've done this set the WRITER_API_KEY environment variable:"
],
"id": "617a6e98205ab7c8"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e817fe2e-4f1d-4533-b19e-2400b1cf6ce8",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:26.800627Z",
"start_time": "2024-11-14T09:27:59.652281Z"
}
},
"outputs": [],
"source": [
"import getpass\n",
"import os\n",
"\n",
"if not os.environ.get(\"WRITER_API_KEY\"):\n",
" os.environ[\"WRITER_API_KEY\"] = getpass.getpass(\"Enter your Writer API key:\")"
],
"outputs": [],
"execution_count": 1
]
},
{
"cell_type": "markdown",
Expand All @@ -81,27 +81,29 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2113471c-75d7-45df-b784-d78da4ef7aba",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:32.415354Z",
"start_time": "2024-11-14T09:46:26.826112Z"
}
},
"source": "%pip install -qU langchain-community writer-sdk",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\r\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.2\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.3.1\u001B[0m\r\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\r\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\r\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"execution_count": 2
"source": [
"%pip install -qU langchain-community writer-sdk"
]
},
{
"cell_type": "markdown",
Expand All @@ -115,14 +117,16 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "522686de",
"metadata": {
"tags": [],
"ExecuteTime": {
"end_time": "2024-11-14T09:46:33.504711Z",
"start_time": "2024-11-14T09:46:32.574505Z"
}
},
"tags": []
},
"outputs": [],
"source": [
"from langchain_community.chat_models.writer import ChatWriter\n",
"\n",
Expand All @@ -132,9 +136,7 @@
" max_tokens=1000,\n",
" # other params...\n",
")"
],
"outputs": [],
"execution_count": 3
]
},
{
"cell_type": "markdown",
Expand All @@ -146,14 +148,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ce16ad78-8e6f-48cd-954e-98be75eb5836",
"metadata": {
"tags": [],
"ExecuteTime": {
"end_time": "2024-11-14T09:46:38.856174Z",
"start_time": "2024-11-14T09:46:33.520062Z"
}
},
"tags": []
},
"outputs": [],
"source": [
"messages = [\n",
" (\n",
Expand All @@ -163,22 +167,18 @@
" (\"human\", \"Write a poem about Python.\"),\n",
"]\n",
"ai_msg = llm.invoke(messages)"
],
"outputs": [],
"execution_count": 4
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2cd224b8-4499-41fb-a604-d53a7ff17b2e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:38.866651Z",
"start_time": "2024-11-14T09:46:38.863817Z"
}
},
"source": [
"print(ai_msg.content)"
],
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -216,40 +216,43 @@
]
}
],
"execution_count": 5
"source": [
"print(ai_msg.content)"
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Streaming",
"id": "35b3a5b3dabef65"
"id": "35b3a5b3dabef65",
"metadata": {},
"source": [
"## Streaming"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "2725770182bf96dc",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:38.914883Z",
"start_time": "2024-11-14T09:46:38.912564Z"
}
},
"cell_type": "code",
"source": "ai_stream = llm.stream(messages)",
"id": "2725770182bf96dc",
"outputs": [],
"execution_count": 6
"source": [
"ai_stream = llm.stream(messages)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a48410d9488162e3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:43.226449Z",
"start_time": "2024-11-14T09:46:38.955512Z"
}
},
"cell_type": "code",
"source": [
"for chunk in ai_stream:\n",
" print(chunk.content, end=\"\")"
],
"id": "a48410d9488162e3",
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -282,7 +285,10 @@
]
}
],
"execution_count": 7
"source": [
"for chunk in ai_stream:\n",
" print(chunk.content, end=\"\")"
]
},
{
"cell_type": "markdown",
Expand All @@ -296,14 +302,27 @@
},
{
"cell_type": "code",
"execution_count": 8,
"id": "fbb043e6",
"metadata": {
"tags": [],
"ExecuteTime": {
"end_time": "2024-11-14T09:46:50.721645Z",
"start_time": "2024-11-14T09:46:43.234590Z"
}
},
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"AIMessageChunk(content='In the realm of code, where logic weaves and flows, \\nA language rises, like a phoenix from the code\\'s throes. \\nJava, the name, a cup of coffee\\'s steam, \\nBrewed in the minds, where digital dreams gleam.\\n\\nWith syntax clear, like morning\\'s misty hue, \\nIn classes and objects, it spins a tale so true. \\nA platform agnostic, with a byte to spare, \\nAcross the devices, it journeys everywhere.\\n\\nInheritance and polymorphism, its power\\'s core, \\nLike ancient runes, in every line they bore. \\nEncapsulation, a shield, with data it does hide, \\nIn the vast jungle of code, it stands as a guide.\\n\\nFrom applets small, to vast, server-side apps, \\nIts threads run swift, through the computing traps. \\nA language of the people, by the people, for the people’s use, \\nBuilt on the principle, \"write once, run anywhere, with no excuse.\"\\n\\nIn the heart of Android, it beats, a steady drum, \\nCrafting experiences, in every smartphone\\'s hum. \\nIn the cloud, in the enterprise, its presence is vast, \\nA cornerstone of computing, built to last.\\n\\nOh Java, thy elegance, thy robust design, \\nA language that stands, in any computing line. \\nWith every update, with every new release, \\nThy community grows, with a vibrant, diverse peace.\\n\\nSo here\\'s to Java, the versatile, the grand, \\nA language that shapes the digital land. \\nMay it continue to evolve, to grow, to inspire, \\nIn the endless quest of turning thoughts into digital fire.', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 345, 'prompt_tokens': 33, 'total_tokens': 378, 'completion_tokens_details': None, 'prompt_token_details': None}, 'model_name': 'palmyra-x-004', 'system_fingerprint': 'v1', 'finish_reason': 'stop'}, id='run-a5b4be59-0eb0-41bd-80f7-72477861b0bd-0')"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain_core.prompts import ChatPromptTemplate\n",
"\n",
Expand All @@ -324,20 +343,7 @@
" \"input\": \"Write a poem about Java.\",\n",
" }\n",
")"
],
"outputs": [
{
"data": {
"text/plain": [
"AIMessageChunk(content='In the realm of code, where logic weaves and flows, \\nA language rises, like a phoenix from the code\\'s throes. \\nJava, the name, a cup of coffee\\'s steam, \\nBrewed in the minds, where digital dreams gleam.\\n\\nWith syntax clear, like morning\\'s misty hue, \\nIn classes and objects, it spins a tale so true. \\nA platform agnostic, with a byte to spare, \\nAcross the devices, it journeys everywhere.\\n\\nInheritance and polymorphism, its power\\'s core, \\nLike ancient runes, in every line they bore. \\nEncapsulation, a shield, with data it does hide, \\nIn the vast jungle of code, it stands as a guide.\\n\\nFrom applets small, to vast, server-side apps, \\nIts threads run swift, through the computing traps. \\nA language of the people, by the people, for the people’s use, \\nBuilt on the principle, \"write once, run anywhere, with no excuse.\"\\n\\nIn the heart of Android, it beats, a steady drum, \\nCrafting experiences, in every smartphone\\'s hum. \\nIn the cloud, in the enterprise, its presence is vast, \\nA cornerstone of computing, built to last.\\n\\nOh Java, thy elegance, thy robust design, \\nA language that stands, in any computing line. \\nWith every update, with every new release, \\nThy community grows, with a vibrant, diverse peace.\\n\\nSo here\\'s to Java, the versatile, the grand, \\nA language that shapes the digital land. \\nMay it continue to evolve, to grow, to inspire, \\nIn the endless quest of turning thoughts into digital fire.', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 345, 'prompt_tokens': 33, 'total_tokens': 378, 'completion_tokens_details': None, 'prompt_token_details': None}, 'model_name': 'palmyra-x-004', 'system_fingerprint': 'v1', 'finish_reason': 'stop'}, id='run-a5b4be59-0eb0-41bd-80f7-72477861b0bd-0')"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 8
]
},
{
"cell_type": "markdown",
Expand All @@ -363,13 +369,15 @@
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b7ea7690-ec7a-4337-b392-e87d1f39a6ec",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:50.891937Z",
"start_time": "2024-11-14T09:46:50.733463Z"
}
},
"outputs": [],
"source": [
"from pydantic import BaseModel, Field\n",
"\n",
Expand All @@ -381,26 +389,24 @@
"\n",
"\n",
"llm_with_tools = llm.bind_tools([GetWeather])"
],
"outputs": [],
"execution_count": 9
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1d1ab955-6a68-42f8-bb5d-86eb1111478a",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:51.725422Z",
"start_time": "2024-11-14T09:46:50.904699Z"
}
},
"outputs": [],
"source": [
"ai_msg = llm_with_tools.invoke(\n",
" \"what is the weather like in New York City\",\n",
")"
],
"outputs": [],
"execution_count": 10
]
},
{
"cell_type": "markdown",
Expand All @@ -413,14 +419,14 @@
},
{
"cell_type": "code",
"execution_count": 11,
"id": "166cb7ce-831d-4a7c-9721-abc107f11084",
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-14T09:46:51.744202Z",
"start_time": "2024-11-14T09:46:51.738431Z"
}
},
"source": "print(ai_msg.tool_calls)",
"outputs": [
{
"data": {
Expand All @@ -436,7 +442,9 @@
"output_type": "execute_result"
}
],
"execution_count": 11
"source": [
"print(ai_msg.tool_calls)"
]
},
{
"cell_type": "markdown",
Expand Down

0 comments on commit a97c53e

Please sign in to comment.