From 3493e66490dbf9f28c67705de4493f2e2a713b88 Mon Sep 17 00:00:00 2001 From: Deepankar Mahapatro Date: Wed, 22 May 2024 23:54:36 +0530 Subject: [PATCH] fix: getpass module call (#523) --- .../agent-simulation-evaluation.ipynb | 2 +- ...angsmith-agent-simulation-evaluation.ipynb | 2 +- examples/multi_agent/agent_supervisor.ipynb | 2 +- .../hierarchical_agent_teams.ipynb | 134 +++++++++--------- .../multi-agent-collaboration.ipynb | 2 +- 5 files changed, 71 insertions(+), 71 deletions(-) diff --git a/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb b/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb index e307105ef..cbb1d9433 100644 --- a/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb +++ b/examples/chatbot-simulation-evaluation/agent-simulation-evaluation.ipynb @@ -45,7 +45,7 @@ "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", - " os.environ[var] = getpass(f\"Please provide your {var}\")\n", + " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n", diff --git a/examples/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb b/examples/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb index 2ebe99e29..47b0e0a2d 100644 --- a/examples/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb +++ b/examples/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb @@ -36,7 +36,7 @@ "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", - " os.environ[var] = getpass(f\"Please provide your {var}\")\n", + " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n", diff --git a/examples/multi_agent/agent_supervisor.ipynb b/examples/multi_agent/agent_supervisor.ipynb index b25eb96fb..38746a70f 100644 --- a/examples/multi_agent/agent_supervisor.ipynb +++ b/examples/multi_agent/agent_supervisor.ipynb @@ -44,7 +44,7 @@ "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", - " os.environ[var] = getpass(f\"Please provide your {var}\")\n", + " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n", diff --git a/examples/multi_agent/hierarchical_agent_teams.ipynb b/examples/multi_agent/hierarchical_agent_teams.ipynb index e36c1120c..5dbd9b78d 100644 --- a/examples/multi_agent/hierarchical_agent_teams.ipynb +++ b/examples/multi_agent/hierarchical_agent_teams.ipynb @@ -31,6 +31,7 @@ }, { "cell_type": "code", + "execution_count": 1, "id": "0d30b6f7-3bec-4d9f-af50-43dfdc81ae6c", "metadata": { "ExecuteTime": { @@ -38,15 +39,15 @@ "start_time": "2024-05-15T08:19:42.359273Z" } }, + "outputs": [], "source": [ "# %%capture --no-stderr\n", "# %pip install -U langgraph langchain langchain_openai langchain_experimental" - ], - "outputs": [], - "execution_count": 1 + ] }, { "cell_type": "code", + "execution_count": 2, "id": "30c2f3de-c730-4aec-85a6-af2c2f058803", "metadata": { "ExecuteTime": { @@ -54,6 +55,7 @@ "start_time": "2024-05-15T08:19:42.365662Z" } }, + "outputs": [], "source": [ "import getpass\n", "import os\n", @@ -62,7 +64,7 @@ "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", - " os.environ[var] = getpass(f\"Please provide your {var}\")\n", + " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n", @@ -73,9 +75,7 @@ "# This will help you visualize and debug the control flow\n", "os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", "os.environ[\"LANGCHAIN_PROJECT\"] = \"Multi-agent Collaboration\"" - ], - "outputs": [], - "execution_count": 2 + ] }, { "cell_type": "markdown", @@ -95,6 +95,7 @@ }, { "cell_type": "code", + "execution_count": 3, "id": "4024eb89-843d-4cc3-ab3f-e1eb4d031179", "metadata": { "ExecuteTime": { @@ -102,6 +103,7 @@ "start_time": "2024-05-15T08:19:42.397083Z" } }, + "outputs": [], "source": [ "from typing import Annotated, List, Tuple, Union\n", "\n", @@ -125,9 +127,7 @@ " for doc in docs\n", " ]\n", " )" - ], - "outputs": [], - "execution_count": 3 + ] }, { "cell_type": "markdown", @@ -144,6 +144,7 @@ }, { "cell_type": "code", + "execution_count": 4, "id": "f20a18ca-2709-4c12-84f3-88678591a9fa", "metadata": { "ExecuteTime": { @@ -151,6 +152,7 @@ "start_time": "2024-05-15T08:19:44.479132Z" } }, + "outputs": [], "source": [ "from pathlib import Path\n", "from tempfile import TemporaryDirectory\n", @@ -243,9 +245,7 @@ " except BaseException as e:\n", " return f\"Failed to execute. Error: {repr(e)}\"\n", " return f\"Successfully executed:\\n```python\\n{code}\\n```\\nStdout: {result}\"" - ], - "outputs": [], - "execution_count": 4 + ] }, { "cell_type": "markdown", @@ -264,6 +264,7 @@ }, { "cell_type": "code", + "execution_count": 5, "id": "e09fb60f-1aac-455b-b67d-8d2e4ccfd747", "metadata": { "ExecuteTime": { @@ -271,6 +272,7 @@ "start_time": "2024-05-15T08:19:44.541330Z" } }, + "outputs": [], "source": [ "from typing import Any, Callable, List, Optional, TypedDict, Union\n", "\n", @@ -350,9 +352,7 @@ " | llm.bind_functions(functions=[function_def], function_call=\"route\")\n", " | JsonOutputFunctionsParser()\n", " )" - ], - "outputs": [], - "execution_count": 5 + ] }, { "cell_type": "markdown", @@ -370,6 +370,7 @@ }, { "cell_type": "code", + "execution_count": 6, "id": "53db0c78-e357-48ba-ae5f-3fc04735a3b7", "metadata": { "ExecuteTime": { @@ -377,6 +378,7 @@ "start_time": "2024-05-15T08:19:46.561088Z" } }, + "outputs": [], "source": [ "import functools\n", "import operator\n", @@ -423,9 +425,7 @@ " \" respond with FINISH.\",\n", " [\"Search\", \"Web Scraper\"],\n", ")" - ], - "outputs": [], - "execution_count": 6 + ] }, { "cell_type": "markdown", @@ -437,6 +437,7 @@ }, { "cell_type": "code", + "execution_count": 7, "id": "1a7a1260-d9f6-4011-b2b1-13fab5126997", "metadata": { "ExecuteTime": { @@ -444,6 +445,7 @@ "start_time": "2024-05-15T08:19:48.811753Z" } }, + "outputs": [], "source": [ "research_graph = StateGraph(ResearchTeamState)\n", "research_graph.add_node(\"Search\", search_node)\n", @@ -475,24 +477,18 @@ "\n", "\n", "research_chain = enter_chain | chain" - ], - "outputs": [], - "execution_count": 7 + ] }, { + "cell_type": "code", + "execution_count": 8, + "id": "110f59bed6134685", "metadata": { "ExecuteTime": { "end_time": "2024-05-15T08:19:51.936523Z", "start_time": "2024-05-15T08:19:48.827798Z" } }, - "cell_type": "code", - "source": [ - "from IPython.display import Image, display\n", - "\n", - "display(Image(chain.get_graph(xray=True).draw_mermaid_png()))" - ], - "id": "110f59bed6134685", "outputs": [ { "data": { @@ -505,7 +501,11 @@ "output_type": "display_data" } ], - "execution_count": 8 + "source": [ + "from IPython.display import Image, display\n", + "\n", + "display(Image(chain.get_graph(xray=True).draw_mermaid_png()))" + ] }, { "cell_type": "markdown", @@ -517,6 +517,7 @@ }, { "cell_type": "code", + "execution_count": 9, "id": "912b0604-a178-4246-a36f-2dedae606680", "metadata": { "ExecuteTime": { @@ -524,6 +525,7 @@ "start_time": "2024-05-15T08:19:51.937879Z" } }, + "outputs": [], "source": [ "for s in research_chain.stream(\n", " \"when is Taylor Swift's next tour?\", {\"recursion_limit\": 100}\n", @@ -531,9 +533,7 @@ " if \"__end__\" not in s:\n", " print(s)\n", " print(\"---\")" - ], - "outputs": [], - "execution_count": 9 + ] }, { "cell_type": "markdown", @@ -549,6 +549,7 @@ }, { "cell_type": "code", + "execution_count": 10, "id": "1bcdbf44-9481-430c-8429-fa142ed8a626", "metadata": { "ExecuteTime": { @@ -556,6 +557,7 @@ "start_time": "2024-05-15T08:19:51.953933Z" } }, + "outputs": [], "source": [ "import operator\n", "from pathlib import Path\n", @@ -641,9 +643,7 @@ " \" respond with FINISH.\",\n", " [\"DocWriter\", \"NoteTaker\", \"ChartGenerator\"],\n", ")" - ], - "outputs": [], - "execution_count": 10 + ] }, { "cell_type": "markdown", @@ -655,6 +655,7 @@ }, { "cell_type": "code", + "execution_count": 11, "id": "9c5c644f-8966-4d2e-98d2-80d73520e9fe", "metadata": { "ExecuteTime": { @@ -662,6 +663,7 @@ "start_time": "2024-05-15T08:19:53.678906Z" } }, + "outputs": [], "source": [ "# Create the graph here:\n", "# Note that we have unrolled the loop for the sake of this doc\n", @@ -708,24 +710,18 @@ " functools.partial(enter_chain, members=authoring_graph.nodes)\n", " | authoring_graph.compile()\n", ")" - ], - "outputs": [], - "execution_count": 11 + ] }, { + "cell_type": "code", + "execution_count": 19, + "id": "58e7d1e48a9c39a5", "metadata": { "ExecuteTime": { "end_time": "2024-05-15T08:32:13.913188Z", "start_time": "2024-05-15T08:32:11.598993Z" } }, - "cell_type": "code", - "source": [ - "from IPython.display import Image, display\n", - "\n", - "display(Image(chain.get_graph().draw_mermaid_png()))" - ], - "id": "58e7d1e48a9c39a5", "outputs": [ { "data": { @@ -738,10 +734,15 @@ "output_type": "display_data" } ], - "execution_count": 19 + "source": [ + "from IPython.display import Image, display\n", + "\n", + "display(Image(chain.get_graph().draw_mermaid_png()))" + ] }, { "cell_type": "code", + "execution_count": 13, "id": "9860fd46-c24d-40a5-a6ba-e8fddcd43369", "metadata": { "ExecuteTime": { @@ -749,6 +750,7 @@ "start_time": "2024-05-15T08:19:53.709307Z" } }, + "outputs": [], "source": [ "for s in authoring_chain.stream(\n", " \"Write an outline for poem and then write the poem to disk.\",\n", @@ -757,9 +759,7 @@ " if \"__end__\" not in s:\n", " print(s)\n", " print(\"---\")" - ], - "outputs": [], - "execution_count": 13 + ] }, { "cell_type": "markdown", @@ -775,6 +775,7 @@ }, { "cell_type": "code", + "execution_count": 14, "id": "95ae7e52-92ed-41a3-88c4-21b6d7c8b041", "metadata": { "ExecuteTime": { @@ -782,6 +783,7 @@ "start_time": "2024-05-15T08:19:53.725466Z" } }, + "outputs": [], "source": [ "from langchain_core.messages import AIMessage, BaseMessage, HumanMessage\n", "from langchain_openai.chat_models import ChatOpenAI\n", @@ -798,12 +800,11 @@ " \" respond with FINISH.\",\n", " [\"Research team\", \"Paper writing team\"],\n", ")" - ], - "outputs": [], - "execution_count": 14 + ] }, { "cell_type": "code", + "execution_count": 15, "id": "4880e573-612f-4d24-97c1-2079382a4a2f", "metadata": { "ExecuteTime": { @@ -811,6 +812,7 @@ "start_time": "2024-05-15T08:19:55.455831Z" } }, + "outputs": [], "source": [ "# Top-level graph state\n", "class State(TypedDict):\n", @@ -850,24 +852,18 @@ ")\n", "super_graph.set_entry_point(\"supervisor\")\n", "super_graph = super_graph.compile()" - ], - "outputs": [], - "execution_count": 15 + ] }, { + "cell_type": "code", + "execution_count": 20, + "id": "270ff3ae26cd42ff", "metadata": { "ExecuteTime": { "end_time": "2024-05-15T08:32:33.694459Z", "start_time": "2024-05-15T08:32:31.524790Z" } }, - "cell_type": "code", - "source": [ - "from IPython.display import Image, display\n", - "\n", - "display(Image(super_graph.get_graph().draw_mermaid_png()))" - ], - "id": "270ff3ae26cd42ff", "outputs": [ { "data": { @@ -880,10 +876,15 @@ "output_type": "display_data" } ], - "execution_count": 20 + "source": [ + "from IPython.display import Image, display\n", + "\n", + "display(Image(super_graph.get_graph().draw_mermaid_png()))" + ] }, { "cell_type": "code", + "execution_count": null, "id": "6b8badbf-d728-44bd-a2a7-5b4e587c92fe", "metadata": { "ExecuteTime": { @@ -891,6 +892,7 @@ "start_time": "2024-05-15T08:19:55.796497Z" } }, + "outputs": [], "source": [ "for s in super_graph.stream(\n", " {\n", @@ -905,9 +907,7 @@ " if \"__end__\" not in s:\n", " print(s)\n", " print(\"---\")" - ], - "outputs": [], - "execution_count": null + ] } ], "metadata": { diff --git a/examples/multi_agent/multi-agent-collaboration.ipynb b/examples/multi_agent/multi-agent-collaboration.ipynb index e95e89284..1bef08bfd 100644 --- a/examples/multi_agent/multi-agent-collaboration.ipynb +++ b/examples/multi_agent/multi-agent-collaboration.ipynb @@ -44,7 +44,7 @@ "\n", "def _set_if_undefined(var: str):\n", " if not os.environ.get(var):\n", - " os.environ[var] = getpass(f\"Please provide your {var}\")\n", + " os.environ[var] = getpass.getpass(f\"Please provide your {var}\")\n", "\n", "\n", "_set_if_undefined(\"OPENAI_API_KEY\")\n",