|
56 | 56 | "// import \"dotenv/config\";\n"
|
57 | 57 | ]
|
58 | 58 | },
|
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "id": "b2fe13d8", |
| 62 | + "metadata": {}, |
| 63 | + "source": [ |
| 64 | + "### Install dependencies\n", |
| 65 | + "\n", |
| 66 | + "```bash\n", |
| 67 | + "npm install @langchain/community @langchain/core @langchain/langgraph @langchain/openai @langchain/tavily canvas cheerio d3 tslab zod\n", |
| 68 | + "```" |
| 69 | + ] |
| 70 | + }, |
59 | 71 | {
|
60 | 72 | "cell_type": "markdown",
|
61 | 73 | "id": "11f28f8d",
|
|
77 | 89 | },
|
78 | 90 | {
|
79 | 91 | "cell_type": "code",
|
80 |
| - "execution_count": 2, |
| 92 | + "execution_count": null, |
81 | 93 | "id": "193df01b",
|
82 | 94 | "metadata": {},
|
83 | 95 | "outputs": [],
|
84 | 96 | "source": [
|
85 |
| - "import { TavilySearchResults } from \"@langchain/community/tools/tavily_search\";\n", |
| 97 | + "import { TavilySearch } from \"@langchain/tavily\";\n", |
86 | 98 | "import { CheerioWebBaseLoader } from \"@langchain/community/document_loaders/web/cheerio\";\n",
|
87 | 99 | "import { tool } from \"@langchain/core/tools\";\n",
|
88 | 100 | "import { z } from \"zod\";\n",
|
89 | 101 | "\n",
|
90 |
| - "const tavilyTool = new TavilySearchResults();\n", |
| 102 | + "const tavilyTool = new TavilySearch();\n", |
91 | 103 | "\n",
|
92 | 104 | "const scrapeWebpage = tool(async (input) => {\n",
|
93 | 105 | " const loader = new CheerioWebBaseLoader(input.url);\n",
|
|
440 | 452 | " ChatPromptTemplate,\n",
|
441 | 453 | " MessagesPlaceholder,\n",
|
442 | 454 | "} from \"@langchain/core/prompts\";\n",
|
443 |
| - "import { JsonOutputToolsParser } from \"langchain/output_parsers\";\n", |
| 455 | + "import { JsonOutputToolsParser } from \"@langchain/core/output_parsers/openai_tools\"\n", |
444 | 456 | "import { ChatOpenAI } from \"@langchain/openai\";\n",
|
445 | 457 | "import { Runnable } from \"@langchain/core/runnables\";\n",
|
446 | 458 | "import { StructuredToolInterface } from \"@langchain/core/tools\";\n",
|
|
624 | 636 | },
|
625 | 637 | {
|
626 | 638 | "cell_type": "code",
|
627 |
| - "execution_count": 9, |
| 639 | + "execution_count": null, |
628 | 640 | "id": "dff6a285",
|
629 | 641 | "metadata": {},
|
630 | 642 | "outputs": [],
|
|
645 | 657 | " })\n",
|
646 | 658 | " .addEdge(START, \"supervisor\");\n",
|
647 | 659 | "\n",
|
648 |
| - "const researchChain = researchGraph.compile();" |
| 660 | + "const enterResearchChain = RunnableLambda.from(\n", |
| 661 | + " ({ messages }: { messages: BaseMessage[] }) => {\n", |
| 662 | + " return {\n", |
| 663 | + " messages: messages,\n", |
| 664 | + " team_members: [\"Search\", \"WebScraper\"],\n", |
| 665 | + " };\n", |
| 666 | + " },\n", |
| 667 | + ");\n", |
| 668 | + "\n", |
| 669 | + "const researchChain = enterResearchChain.pipe(() => researchGraph.compile());" |
649 | 670 | ]
|
650 | 671 | },
|
651 | 672 | {
|
|
953 | 974 | },
|
954 | 975 | {
|
955 | 976 | "cell_type": "code",
|
956 |
| - "execution_count": 14, |
| 977 | + "execution_count": null, |
957 | 978 | "id": "2ab60a98",
|
958 | 979 | "metadata": {},
|
959 | 980 | "outputs": [],
|
|
985 | 1006 | " };\n",
|
986 | 1007 | " },\n",
|
987 | 1008 | ");\n",
|
988 |
| - "const authoringChain = enterAuthoringChain.pipe(authoringGraph.compile());" |
| 1009 | + "const authoringChain = enterAuthoringChain.pipe(() => authoringGraph.compile());" |
989 | 1010 | ]
|
990 | 1011 | },
|
991 | 1012 | {
|
|
1243 | 1264 | },
|
1244 | 1265 | {
|
1245 | 1266 | "cell_type": "code",
|
1246 |
| - "execution_count": 66, |
| 1267 | + "execution_count": null, |
1247 | 1268 | "id": "0f40c195",
|
1248 | 1269 | "metadata": {},
|
1249 | 1270 | "outputs": [],
|
|
1257 | 1278 | " const joinGraphResult = await joinGraph.invoke({\n",
|
1258 | 1279 | " messages: researchChainResult.messages,\n",
|
1259 | 1280 | " });\n",
|
| 1281 | + " return joinGraphResult;\n", |
1260 | 1282 | " })\n",
|
1261 | 1283 | " .addNode(\"PaperWritingTeam\", getMessages.pipe(authoringChain).pipe(joinGraph))\n",
|
1262 | 1284 | " .addNode(\"supervisor\", supervisorNode)\n",
|
|
0 commit comments