-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cdee7b
commit cc6d3b5
Showing
2 changed files
with
29 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,22 +68,12 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"execution_count": 1, | ||
"id": "bdf2fe0f", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"[WARN]: You have enabled LangSmith tracing without backgrounding callbacks.\n", | ||
"[WARN]: If you are not using a serverless environment where you must wait for tracing calls to finish,\n", | ||
"[WARN]: we suggest setting \"process.env.LANGCHAIN_CALLBACKS_BACKGROUND=true\" to avoid additional latency.\n" | ||
] | ||
} | ||
], | ||
"outputs": [], | ||
"source": [ | ||
"import { BaseMessage, HumanMessage } from \"@langchain/core/messages\";\n", | ||
"import { BaseMessage } from \"@langchain/core/messages\";\n", | ||
"import { ChatOpenAI } from \"@langchain/openai\";\n", | ||
"import { ChatAnthropic } from \"@langchain/anthropic\";\n", | ||
"import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", | ||
|
@@ -93,35 +83,28 @@ | |
" MemorySaver,\n", | ||
" START,\n", | ||
" StateGraph,\n", | ||
" StateGraphArgs,\n", | ||
" Annotation,\n", | ||
"} from \"@langchain/langgraph\";\n", | ||
"\n", | ||
"interface IState {\n", | ||
" messages: BaseMessage[];\n", | ||
" userInfo: string;\n", | ||
"}\n", | ||
"\n", | ||
"// This defines the agent state\n", | ||
"const graphState: StateGraphArgs<IState>[\"channels\"] = {\n", | ||
" messages: {\n", | ||
" value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n", | ||
" default: () => [],\n", | ||
" },\n", | ||
" userInfo: {\n", | ||
" value: (x?: string, y?: string) => {\n", | ||
"const AgentState = Annotation.Root({\n", | ||
" messages: Annotation<BaseMessage[]>({\n", | ||
" reducer: (x, y) => x.concat(y),\n", | ||
" }),\n", | ||
" userInfo: Annotation<string | undefined>({\n", | ||
" reducer: (x, y) => {\n", | ||
" return y ? y : x ? x : \"N/A\";\n", | ||
" },\n", | ||
" default: () => \"N/A\",\n", | ||
" },\n", | ||
"};\n", | ||
" })\n", | ||
"});\n", | ||
"\n", | ||
"const promptTemplate = ChatPromptTemplate.fromMessages([\n", | ||
" [\"system\", \"You are a helpful assistant.\\n\\n## User Info:\\n{userInfo}\"],\n", | ||
" [\"placeholder\", \"{messages}\"],\n", | ||
"]);\n", | ||
"\n", | ||
"const callModel = async (\n", | ||
" state: { messages: BaseMessage[]; userInfo: string },\n", | ||
" state: typeof AgentState.State,\n", | ||
" config?: RunnableConfig,\n", | ||
") => {\n", | ||
" const { messages, userInfo } = state;\n", | ||
|
@@ -141,7 +124,7 @@ | |
"};\n", | ||
"\n", | ||
"const fetchUserInformation = async (\n", | ||
" _: { messages: BaseMessage[] },\n", | ||
" _: typeof AgentState.State,\n", | ||
" config?: RunnableConfig,\n", | ||
") => {\n", | ||
" const userDB = {\n", | ||
|
@@ -169,9 +152,7 @@ | |
" return { userInfo: \"N/A\" };\n", | ||
"};\n", | ||
"\n", | ||
"const workflow = new StateGraph<IState>({\n", | ||
" channels: graphState,\n", | ||
"})\n", | ||
"const workflow = new StateGraph(AgentState)\n", | ||
" .addNode(\"fetchUserInfo\", fetchUserInformation)\n", | ||
" .addNode(\"agent\", callModel)\n", | ||
" .addEdge(START, \"fetchUserInfo\")\n", | ||
|
@@ -207,13 +188,15 @@ | |
"Could you remind me of my email??\n", | ||
"-----\n", | ||
"\n", | ||
"Of course, John. Your email is [email protected].\n", | ||
"Sure, John. Your email is [email protected].\n", | ||
"-----\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import { HumanMessage } from \"@langchain/core/messages\";\n", | ||
"\n", | ||
"const config = {\n", | ||
" configurable: {\n", | ||
" model: \"openai\",\n", | ||
|
@@ -266,14 +249,8 @@ | |
"\n", | ||
"Could you remind me of my email??\n", | ||
"-----\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Certainly, Jane. Your email is [email protected].\n", | ||
"\n", | ||
"Sure, Jane. Your email is [email protected].\n", | ||
"-----\n", | ||
"\n" | ||
] | ||
|
@@ -307,14 +284,6 @@ | |
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "88d8db9c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f000b97c", | ||
|