docs: update typing -> typing_extensions for TypedDict (#1871)

This commit is contained in:
Vadym Barda
2024-09-26 18:06:45 -04:00
committed by GitHub
parent fe7e7b9121
commit 29a03309c9
30 changed files with 62 additions and 36 deletions
+2 -1
View File
@@ -58,7 +58,8 @@ To make the server aware of your graph, you need to specify a path to the variab
To make your graph rebuild on each new run with custom configuration, you need to rewrite `openai_agent.py` to instead provide a _function_ that takes a config and returns a graph (or compiled graph) instance. Let's say we want to return our existing graph for user ID '1', and a tool-calling agent for other users. We can modify `openai_agent.py` as follows:
```python
from typing import Annotated, TypedDict
from typing import Annotated
from typing_extensions import TypedDict
from langchain_openai import ChatOpenAI
from langgraph.graph import END, START, MessageGraph
from langgraph.graph.state import StateGraph
+2 -1
View File
@@ -101,7 +101,8 @@ Example `agent.py` file, which shows how to import from other modules you define
```python
# my_agent/agent.py
from typing import TypedDict, Literal
from typing import Literal
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, END, START
from my_agent.utils.nodes import call_model, should_continue, tool_node # import nodes
@@ -110,7 +110,8 @@ Example `agent.py` file, which shows how to import from other modules you define
```python
# my_agent/agent.py
from typing import TypedDict, Literal
from typing import Literal
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, END, START
from my_agent.utils.nodes import call_model, should_continue, tool_node # import nodes
+2 -1
View File
@@ -7,7 +7,8 @@ E.g., the state should look something like:
=== "Python"
```python
from typing import TypedDict, Annotated
from typing import Annotated
from typing_extensions import TypedDict
from langgraph.graph import add_messages
from langchain_core.messages import AnyMessage
+5 -3
View File
@@ -118,7 +118,7 @@ These two examples show how to use the default reducer:
**Example A:**
```python
from typing import TypedDict
from typing_extensions import TypedDict
class State(TypedDict):
foo: int
@@ -130,7 +130,8 @@ In this example, no reducer functions are specified for any key. Let's assume th
**Example B:**
```python
from typing import TypedDict, Annotated
from typing import Annotated
from typing_extensions import TypedDict
from operator import add
class State(TypedDict):
@@ -169,7 +170,8 @@ Since the state updates are always deserialized into LangChain `Messages` when u
```python
from langchain_core.messages import AnyMessage
from langgraph.graph.message import add_messages
from typing import Annotated, TypedDict
from typing import Annotated
from typing_extensions import TypedDict
class GraphState(TypedDict):
messages: Annotated[list[AnyMessage], add_messages]
+4 -2
View File
@@ -27,7 +27,8 @@ Let's see what checkpoints are saved when a simple graph is invoked as follows:
```python
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
from typing import TypedDict, Annotated
from typing import Annotated
from typing_extensions import TypedDict
from operator import add
class State(TypedDict):
@@ -180,7 +181,8 @@ These are the values that will be used to update the state. Note that this updat
Let's assume you have defined the state of your graph with the following schema (see full example above):
```python
from typing import TypedDict, Annotated
from typing import Annotated
from typing_extensions import TypedDict
from operator import add
class State(TypedDict):
+2 -1
View File
@@ -77,7 +77,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, Sequence, TypedDict\n",
"from typing import Annotated, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_anthropic import ChatAnthropic\n",
"from langchain_core.messages import BaseMessage, HumanMessage\n",
@@ -122,7 +122,7 @@
}
],
"source": [
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"from langgraph.graph import StateGraph, START, END\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"from IPython.display import Image, display\n",
@@ -74,7 +74,7 @@
}
],
"source": [
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"from IPython.display import Image, display\n",
"\n",
"from langgraph.graph import StateGraph, START, END\n",
@@ -124,7 +124,7 @@
}
],
"source": [
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"from langgraph.graph import StateGraph, START, END\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"from IPython.display import Image, display\n",
@@ -118,7 +118,7 @@
}
],
"source": [
"from typing import TypedDict, Literal\n",
"from typing_extensions import TypedDict, Literal\n",
"from langgraph.graph import StateGraph, START, END, MessagesState\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"from langchain_anthropic import ChatAnthropic\n",
@@ -118,7 +118,7 @@
}
],
"source": [
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"from langgraph.graph import StateGraph, START, END\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"from IPython.display import Image, display\n",
+1 -1
View File
@@ -69,7 +69,7 @@
],
"source": [
"from langgraph.graph import StateGraph, START, END\n",
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"class InputState(TypedDict):\n",
+2 -1
View File
@@ -105,7 +105,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, TypedDict\n",
"from typing import Annotated\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_anthropic import ChatAnthropic\n",
"\n",
+2 -1
View File
@@ -123,7 +123,8 @@
"source": [
"import operator\n",
"import sqlite3\n",
"from typing import Annotated, Sequence, TypedDict\n",
"from typing import Annotated, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_anthropic import ChatAnthropic\n",
"from langchain_core.messages import BaseMessage\n",
@@ -271,7 +271,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, Sequence, TypedDict\n",
"from typing import Annotated, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_core.messages import BaseMessage\n",
"\n",
+1 -1
View File
@@ -75,7 +75,7 @@
],
"source": [
"from langgraph.graph import StateGraph, START, END\n",
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"# The overall state of the graph\n",
@@ -267,7 +267,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, TypedDict, Literal\n",
"from typing import Annotated, Literal\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langgraph.graph import StateGraph, END, START\n",
"\n",
@@ -125,7 +125,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import TypedDict, Annotated\n",
"from typing import Annotated\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langgraph.graph import END, StateGraph, START\n",
"from langgraph.graph.message import MessagesState\n",
@@ -251,7 +251,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, TypedDict, Literal\n",
"from typing import Annotated, Literal\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langgraph.graph import StateGraph, END, START\n",
"\n",
@@ -64,7 +64,7 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import TypedDict\n",
"from typing_extensions import TypedDict\n",
"from langgraph.graph.state import StateGraph, START, END\n",
"\n",
"\n",
@@ -130,7 +130,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import TypedDict, Literal\n",
"from typing import Literal\n",
"from typing_extensions import TypedDict\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"\n",
"\n",
@@ -710,7 +711,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import TypedDict, Literal\n",
"from typing import Literal\n",
"from typing_extensions import TypedDict\n",
"from langgraph.checkpoint.memory import MemorySaver\n",
"\n",
"\n",
@@ -352,7 +352,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import List, TypedDict\n",
"from typing import List\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"class GraphState(TypedDict):\n",
@@ -208,7 +208,8 @@
"source": [
"import functools\n",
"import operator\n",
"from typing import Sequence, TypedDict\n",
"from typing import Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_core.messages import BaseMessage\n",
"\n",
@@ -198,7 +198,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, Sequence, TypedDict\n",
"from typing import Annotated, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_openai import ChatOpenAI\n",
"\n",
@@ -211,7 +211,8 @@
"outputs": [],
"source": [
"import operator\n",
"from typing import Annotated, List, Tuple, TypedDict\n",
"from typing import Annotated, List, Tuple\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"class PlanExecute(TypedDict):\n",
@@ -155,7 +155,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import Annotated, Sequence, TypedDict\n",
"from typing import Annotated, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_core.messages import BaseMessage\n",
"\n",
@@ -223,7 +224,8 @@
}
],
"source": [
"from typing import Annotated, Literal, Sequence, TypedDict\n",
"from typing import Annotated, Literal, Sequence\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain import hub\n",
"from langchain_core.messages import BaseMessage, HumanMessage\n",
+2 -1
View File
@@ -109,7 +109,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import List, TypedDict\n",
"from typing import List\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"class ReWOO(TypedDict):\n",
@@ -167,7 +167,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import Optional, TypedDict\n",
"from typing import Optional\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_core.output_parsers import StrOutputParser\n",
"from langchain_openai import ChatOpenAI\n",
@@ -318,7 +319,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.11.9"
}
},
"nbformat": 4,
@@ -307,7 +307,8 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import List, Optional, TypedDict\n",
"from typing import List, Optional\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langchain_core.messages import BaseMessage, SystemMessage\n",
"from playwright.async_api import Page\n",