Skip to content

Commit

Permalink
Clean up deprecated agents and update __init__ in experimental (#12231)
Browse files Browse the repository at this point in the history
Update init paths in experimental
  • Loading branch information
hwchase17 authored Oct 27, 2023
1 parent 05bbf94 commit 0ca539e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 48 deletions.
6 changes: 3 additions & 3 deletions docs/docs/expression_language/cookbook/code_writing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"id": "bd7c259a",
"metadata": {},
"outputs": [],
"source": [
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate\n",
"from langchain.schema.output_parser import StrOutputParser\n",
"from langchain.utilities import PythonREPL"
"from langchain_experimental.utilities import PythonREPL"
]
},
{
Expand Down Expand Up @@ -111,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
41 changes: 17 additions & 24 deletions docs/docs/integrations/memory/aws_dynamodb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
"execution_count": 14,
"id": "088c037c",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
Expand Down Expand Up @@ -237,8 +236,8 @@
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f92d9499",
"execution_count": 1,
"id": "0264134f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -247,9 +246,17 @@
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.agents import initialize_agent\n",
"from langchain.agents import AgentType\n",
"from langchain.utilities import PythonREPL\n",
"from getpass import getpass\n",
"\n",
"from langchain_experimental.utilities import PythonREPL\n",
"from getpass import getpass"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f92d9499",
"metadata": {},
"outputs": [],
"source": [
"message_history = DynamoDBChatMessageHistory(table_name=\"SessionTable\", session_id=\"1\")\n",
"memory = ConversationBufferMemory(\n",
" memory_key=\"chat_history\", chat_memory=message_history, return_messages=True\n",
Expand Down Expand Up @@ -277,24 +284,10 @@
},
{
"cell_type": "code",
"execution_count": 17,
"id": "fce085c5",
"execution_count": null,
"id": "06c6e5ba",
"metadata": {},
"outputs": [
{
"ename": "ValidationError",
"evalue": "1 validation error for ChatOpenAI\n__root__\n Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[17], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m llm \u001b[38;5;241m=\u001b[39m \u001b[43mChatOpenAI\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtemperature\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m agent_chain \u001b[38;5;241m=\u001b[39m initialize_agent(\n\u001b[1;32m 3\u001b[0m tools,\n\u001b[1;32m 4\u001b[0m llm,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 7\u001b[0m memory\u001b[38;5;241m=\u001b[39mmemory,\n\u001b[1;32m 8\u001b[0m )\n",
"File \u001b[0;32m~/Documents/projects/langchain/libs/langchain/langchain/load/serializable.py:74\u001b[0m, in \u001b[0;36mSerializable.__init__\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m---> 74\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 75\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lc_kwargs \u001b[38;5;241m=\u001b[39m kwargs\n",
"File \u001b[0;32m~/Documents/projects/langchain/.venv/lib/python3.9/site-packages/pydantic/main.py:341\u001b[0m, in \u001b[0;36mpydantic.main.BaseModel.__init__\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mValidationError\u001b[0m: 1 validation error for ChatOpenAI\n__root__\n Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)"
]
}
],
"outputs": [],
"source": [
"llm = ChatOpenAI(temperature=0)\n",
"agent_chain = initialize_agent(\n",
Expand Down Expand Up @@ -363,7 +356,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/integrations/toolkits/csv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "caae0bec",
"metadata": {},
"outputs": [],
Expand All @@ -24,7 +24,7 @@
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.agents.agent_types import AgentType\n",
"\n",
"from langchain.agents import create_csv_agent"
"from langchain_experimental.agents.agent_toolkits import create_csv_agent"
]
},
{
Expand Down Expand Up @@ -295,7 +295,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/toolkits/pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.agents import create_pandas_dataframe_agent\n",
"from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.agents.agent_types import AgentType"
]
Expand Down Expand Up @@ -292,7 +292,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/integrations/toolkits/python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"outputs": [],
"source": [
"from langchain.agents.agent_toolkits import create_python_agent\n",
"from langchain.tools.python.tool import PythonREPLTool\n",
"from langchain.python import PythonREPL\n",
"from langchain_experimental.agents.agent_toolkits import create_python_agent\n",
"from langchain_experimental.tools import PythonREPLTool\n",
"from langchain_experimental.utilities import PythonREPL\n",
"from langchain.llms.openai import OpenAI\n",
"from langchain.agents.agent_types import AgentType\n",
"from langchain.chat_models import ChatOpenAI"
Expand Down Expand Up @@ -269,7 +269,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/toolkits/spark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"source": [
"from langchain.llms import OpenAI\n",
"from pyspark.sql import SparkSession\n",
"from langchain.agents import create_spark_dataframe_agent\n",
"from langchain_experimental.agents.agent_toolkits import create_spark_dataframe_agent\n",
"\n",
"spark = SparkSession.builder.getOrCreate()\n",
"csv_file_path = \"titanic.csv\"\n",
Expand Down Expand Up @@ -410,7 +410,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/integrations/toolkits/spark_sql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
Expand Down Expand Up @@ -345,7 +344,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
24 changes: 18 additions & 6 deletions docs/docs/integrations/toolkits/xorbits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
"## Pandas examples"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-13T08:06:33.955439Z",
"start_time": "2023-07-13T08:06:33.767539500Z"
}
},
"outputs": [],
"source": [
"import xorbits.pandas as pd\n",
"\n",
"from langchain_experimental.agents.agent_toolkits import create_xorbits_agent\n",
"from langchain.llms import OpenAI"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand All @@ -49,11 +66,6 @@
}
],
"source": [
"import xorbits.pandas as pd\n",
"\n",
"from langchain.agents import create_xorbits_agent\n",
"from langchain.llms import OpenAI\n",
"\n",
"data = pd.read_csv(\"titanic.csv\")\n",
"agent = create_xorbits_agent(OpenAI(temperature=0), data, verbose=True)"
]
Expand Down Expand Up @@ -734,7 +746,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/tools/python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputs": [],
"source": [
"from langchain.agents import Tool\n",
"from langchain.utilities import PythonREPL"
"from langchain_experimental.utilities import PythonREPL"
]
},
{
Expand Down Expand Up @@ -95,7 +95,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langchain_experimental.agents.agent_toolkits.pandas.base import (
create_pandas_dataframe_agent,
)
from langchain_experimental.agents.agent_toolkits.python.base import create_python_agent
from langchain_experimental.agents.agent_toolkits.spark.base import (
create_spark_dataframe_agent,
)
from langchain_experimental.agents.agent_toolkits.xorbits.base import (
create_xorbits_agent,
)

__all__ = [
"create_xorbits_agent",
"create_pandas_dataframe_agent",
"create_spark_dataframe_agent",
"create_python_agent",
"create_csv_agent",
]
3 changes: 3 additions & 0 deletions libs/experimental/langchain_experimental/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_experimental.tools.python.tool import PythonAstREPLTool, PythonREPLTool

__all__ = ["PythonREPLTool", "PythonAstREPLTool"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from langchain_experimental.utilities.python import PythonREPL

__all__ = ["PythonREPL"]

0 comments on commit 0ca539e

Please sign in to comment.