mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-12 12:47:53 +02:00
[Docs] Add ruff linting to .ipynb files (#645)
This commit is contained in:
+22
-22
@@ -9,7 +9,7 @@
|
||||
"\n",
|
||||
"When running LangGraph agents, you can easily save good threads and use them in the future.\n",
|
||||
"\n",
|
||||
"**Note:** this requires passing in a checkpointer."
|
||||
"**Note:** this requires passing in a checkpointer.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -19,7 +19,7 @@
|
||||
"source": [
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"First we need to install the packages required"
|
||||
"First we need to install the packages required\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -47,7 +47,7 @@
|
||||
"id": "0abe11f4-62ed-4dc4-8875-3db21e260d1d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Next, we need to set API keys for OpenAI (the LLM we will use) and Tavily (the search tool we will use)"
|
||||
"Next, we need to set API keys for OpenAI (the LLM we will use) and Tavily (the search tool we will use)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -66,8 +66,8 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")\n",
|
||||
"os.environ[\"TAVILY_API_KEY\"] = getpass.getpass(\"Tavily API Key:\")"
|
||||
@@ -78,7 +78,7 @@
|
||||
"id": "f0ed46a8-effe-4596-b0e1-a6a29ee16f5c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Optionally, we can set API key for [LangSmith tracing](https://smith.langchain.com/), which will give us best-in-class observability."
|
||||
"Optionally, we can set API key for [LangSmith tracing](https://smith.langchain.com/), which will give us best-in-class observability.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -150,7 +150,7 @@
|
||||
"1. It should work with messages. We will represent all agent state in the form of messages, so it needs to be able to work well with them.\n",
|
||||
"2. It should work with OpenAI function calling. This means it should either be an OpenAI model or a model that exposes a similar interface.\n",
|
||||
"\n",
|
||||
"Note: these model requirements are not requirements for using LangGraph - they are just requirements for this one example."
|
||||
"Note: these model requirements are not requirements for using LangGraph - they are just requirements for this one example.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -170,7 +170,6 @@
|
||||
"id": "a77995c0-bae2-4cee-a036-8688a90f05b9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"After we've done this, we should make sure the model knows that it has these tools available to call.\n",
|
||||
"We can do this using the `.bind_tools()` method, common to many of LangChain's chat models.\n"
|
||||
]
|
||||
@@ -209,7 +208,7 @@
|
||||
" b. If the agent said that it was finished, then it should finish\n",
|
||||
"2. Normal Edge: after the tools are invoked, it should always go back to the agent to decide what to do next\n",
|
||||
"\n",
|
||||
"Let's define the nodes, as well as a function to decide how what conditional edge to take."
|
||||
"Let's define the nodes, as well as a function to decide how what conditional edge to take.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -237,7 +236,7 @@
|
||||
"source": [
|
||||
"## Define the graph\n",
|
||||
"\n",
|
||||
"We can now put it all together and define the graph!"
|
||||
"We can now put it all together and define the graph!\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -247,11 +246,19 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langgraph.graph import StateGraph, END\n",
|
||||
"from typing import Annotated, TypedDict\n",
|
||||
"\n",
|
||||
"from langchain_core.messages import (\n",
|
||||
" AIMessage,\n",
|
||||
" AnyMessage,\n",
|
||||
" HumanMessage,\n",
|
||||
" SystemMessage,\n",
|
||||
" ToolMessage,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"from langgraph.graph.message import add_messages\n",
|
||||
"from langgraph.managed.few_shot import FewShotExamples\n",
|
||||
"from typing import TypedDict, Annotated\n",
|
||||
"from langchain_core.messages import AnyMessage, HumanMessage, SystemMessage\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class BaseState(TypedDict):\n",
|
||||
@@ -259,9 +266,6 @@
|
||||
" examples: Annotated[list, FewShotExamples]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"from langchain_core.messages import AIMessage, ToolMessage\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def _render_message(m):\n",
|
||||
" if isinstance(m, HumanMessage):\n",
|
||||
" return \"Human: \" + m.content\n",
|
||||
@@ -299,9 +303,7 @@
|
||||
"\n",
|
||||
"{examples}\n",
|
||||
"\n",
|
||||
"Assist the user as they require!\"\"\".format(\n",
|
||||
" examples=_examples\n",
|
||||
" )\n",
|
||||
"Assist the user as they require!\"\"\".format(examples=_examples)\n",
|
||||
"\n",
|
||||
" else:\n",
|
||||
" system_message = \"\"\"You are a helpful assistant\"\"\"\n",
|
||||
@@ -350,7 +352,7 @@
|
||||
"source": [
|
||||
"**Persistence**\n",
|
||||
"\n",
|
||||
"To add in persistence, we pass in a checkpoint when compiling the graph"
|
||||
"To add in persistence, we pass in a checkpoint when compiling the graph\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -383,7 +385,7 @@
|
||||
"id": "e8aff75b-563e-42b1-969b-742201514fc3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Preview the graph"
|
||||
"## Preview the graph\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -435,8 +437,6 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.messages import HumanMessage\n",
|
||||
"\n",
|
||||
"thread = {\"configurable\": {\"thread_id\": \"1\"}}\n",
|
||||
"for event in app.stream(\n",
|
||||
" {\"messages\": [HumanMessage(content=\"whats the weather in sf?\")]}, thread\n",
|
||||
|
||||
Reference in New Issue
Block a user