Skip to content

Commit

Permalink
docs[patch]: Update tutorials (langchain-ai#5473)
Browse files Browse the repository at this point in the history
* Update tutorials

* Fix LangSmith section:
  • Loading branch information
jacoblee93 authored May 20, 2024
1 parent 59181ab commit 14e697f
Show file tree
Hide file tree
Showing 9 changed files with 951 additions and 155 deletions.
2 changes: 2 additions & 0 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ docs/tutorials/extraction.md
docs/tutorials/extraction.mdx
docs/tutorials/classification.md
docs/tutorials/classification.mdx
docs/tutorials/chatbot.md
docs/tutorials/chatbot.mdx
docs/how_to/tools_prompting.md
docs/how_to/tools_prompting.mdx
docs/how_to/tools_builtin.md
Expand Down
78 changes: 57 additions & 21 deletions docs/core_docs/docs/how_to/structured_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,70 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "070bf702",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" setup: \u001b[32m\"Why was the cat sitting on the computer?\"\u001b[39m,\n",
" punchline: \u001b[32m\"Because it wanted to keep an eye on the mouse!\"\u001b[39m,\n",
" rating: \u001b[33m8\u001b[39m\n",
" setup: \u001b[32m\"Why don't cats play poker in the wild?\"\u001b[39m,\n",
" punchline: \u001b[32m\"Too many cheetahs.\"\u001b[39m,\n",
" rating: \u001b[33m7\u001b[39m\n",
"}"
]
},
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import { z } from \"zod\";\n",
"\n",
"const Joke = z.object({\n",
"const joke = z.object({\n",
" setup: z.string().describe(\"The setup of the joke\"),\n",
" punchline: z.string().describe(\"The punchline to the joke\"),\n",
" rating: z.number().optional().describe(\"How funny the joke is, from 1 to 10\"),\n",
"});\n",
"\n",
"const structuredLlm = model.withStructuredOutput(Joke);\n",
"const structuredLlm = model.withStructuredOutput(joke);\n",
"\n",
"await structuredLlm.invoke(\"Tell me a joke about cats\")"
]
},
{
"cell_type": "markdown",
"id": "fe6efeab",
"metadata": {},
"source": [
"One key point is that though we set our Zod schema as a variable named `joke`, Zod is not able to access that variable name, and therefore cannot pass it to the model. Though it is not required, we can pass a name for our schema in order to give the model additional context as to what our schema represents, improving performance:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f3d01a1d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" setup: \u001b[32m\"Why don't cats play poker in the wild?\"\u001b[39m,\n",
" punchline: \u001b[32m\"Too many cheetahs!\"\u001b[39m,\n",
" rating: \u001b[33m7\u001b[39m\n",
"}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const structuredLlm = model.withStructuredOutput(joke, { name: \"joke\" });\n",
"\n",
"await structuredLlm.invoke(\"Tell me a joke about cats\")"
]
Expand Down Expand Up @@ -155,27 +190,28 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "df0370e3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" setup: \u001b[32m\"Why was the cat sitting on the computer?\"\u001b[39m,\n",
" punchline: \u001b[32m\"To keep an eye on the mouse!\"\u001b[39m\n",
" setup: \u001b[32m\"Why don't cats play poker in the jungle?\"\u001b[39m,\n",
" punchline: \u001b[32m\"Too many cheetahs!\"\u001b[39m\n",
"}"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const structuredLlm = model.withStructuredOutput(Joke, {\n",
" method: \"json_schema\"\n",
"const structuredLlm = model.withStructuredOutput(joke, {\n",
" method: \"json_mode\",\n",
" name: \"joke\",\n",
"})\n",
"\n",
"await structuredLlm.invoke(\n",
Expand Down Expand Up @@ -203,7 +239,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "6e514455",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -256,7 +292,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "3d73d33d",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -290,7 +326,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "8d6b3d17",
"metadata": {},
"outputs": [
Expand All @@ -300,7 +336,7 @@
"{ people: [ { name: \u001b[32m\"Anna\"\u001b[39m, height_in_meters: \u001b[33m1.83\u001b[39m } ] }"
]
},
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -325,7 +361,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 10,
"id": "525721b3",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -399,7 +435,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 11,
"id": "c8a30d0e",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -432,7 +468,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 12,
"id": "e1e7baf6",
"metadata": {},
"outputs": [
Expand All @@ -444,7 +480,7 @@
"]"
]
},
"execution_count": 17,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
---
sidebar_class_name: hidden
---

# 🦜🛠️ LangSmith

[LangSmith](https://smith.langchain.com) helps you trace and evaluate your language model applications and intelligent agents to help you
move from prototype to production.

Check out the [interactive walkthrough](/docs/langsmith/walkthrough) to get started.

For more information, please refer to the [LangSmith documentation](https://docs.smith.langchain.com/).
To get started, please refer to the [LangSmith documentation](https://docs.smith.langchain.com/).

For tutorials and other end-to-end examples demonstrating ways to integrate LangSmith in your workflow,
check out the [LangSmith Cookbook](https://github.com/langchain-ai/langsmith-cookbook). Some of the guides therein include:
Expand Down
Empty file.
Loading

0 comments on commit 14e697f

Please sign in to comment.