Skip to content

Commit

Permalink
updated stream tokens doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 19, 2024
1 parent fa54104 commit f1da02f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 100 deletions.
36 changes: 11 additions & 25 deletions examples/how-tos/respond-in-format.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,14 @@
},
"outputs": [],
"source": [
"import { Annotation, messagesStateReducer } from \"@langchain/langgraph\";\n",
"import { BaseMessage } from \"@langchain/core/messages\";\n",
"import { StateGraphArgs, messagesStateReducer } from \"@langchain/langgraph\";\n",
"\n",
"interface IState {\n",
" messages: BaseMessage[];\n",
"}\n",
"\n",
"const graphState: StateGraphArgs<IState>[\"channels\"] = {\n",
" messages: {\n",
"const GraphState = Annotation.Root({\n",
" messages: Annotation<BaseMessage[]>({\n",
" reducer: messagesStateReducer,\n",
" },\n",
"};"
" }),\n",
"});"
]
},
{
Expand All @@ -142,7 +138,7 @@
"import { tool } from \"@langchain/core/tools\";\n",
"import { z } from \"zod\";\n",
"\n",
"const searchTool = tool(async ({}: { query: string }) => {\n",
"const searchTool = tool((_) => {\n",
" // This is a placeholder, but don't tell the LLM that...\n",
" return \"67 degrees. Cloudy with a chance of rain.\";\n",
"}, {\n",
Expand Down Expand Up @@ -176,7 +172,7 @@
"source": [
"import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n",
"\n",
"const toolNode = new ToolNode<{ messages: BaseMessage[] }>(tools);"
"const toolNode = new ToolNode<typeof GraphState.State>(tools);"
]
},
{
Expand Down Expand Up @@ -270,7 +266,7 @@
"import { RunnableConfig } from \"@langchain/core/runnables\";\n",
"\n",
"// Define the function that determines whether to continue or not\n",
"const route = (state: IState) => {\n",
"const route = (state: typeof GraphState.State) => {\n",
" const { messages } = state;\n",
" const lastMessage = messages[messages.length - 1] as AIMessage;\n",
" // If there is no function call, then we finish\n",
Expand All @@ -287,7 +283,7 @@
"\n",
"// Define the function that calls the model\n",
"const callModel = async (\n",
" state: IState,\n",
" state: typeof GraphState.State,\n",
" config?: RunnableConfig,\n",
") => {\n",
" const { messages } = state;\n",
Expand Down Expand Up @@ -315,9 +311,7 @@
"import { StateGraph } from \"@langchain/langgraph\";\n",
"\n",
"// Define a new graph\n",
"const workflow = new StateGraph<IState>({\n",
" channels: graphState,\n",
"})\n",
"const workflow = new StateGraph(GraphState)\n",
" .addNode(\"agent\", callModel)\n",
" .addNode(\"tools\", toolNode)\n",
" .addEdge(\"__start__\", \"agent\")\n",
Expand Down Expand Up @@ -506,7 +500,7 @@
" {\n",
" name: 'Response',\n",
" args: { temperature: 67, other_notes: 'Cloudy with a chance of rain.' },\n",
" id: 'call_rW75pHMufPX9DOhOTNZYb9ag',\n",
" id: 'call_oOhNx2SdeelXn6tbenokDtkO',\n",
" type: 'tool_call'\n",
" }\n",
"]\n"
Expand Down Expand Up @@ -551,14 +545,6 @@
"// Final aggregated tool call\n",
"console.log(aggregatedChunk.tool_calls);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc0e8d87",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit f1da02f

Please sign in to comment.