docs: update imports of `memory` to use `langchain_community` (#18689)

Refactored imports from `langchain` to `langchain_community` whenever it
is applicable
pull/17836/head
Leonid Ganeline 4 months ago committed by GitHub
parent e00c1ff2b0
commit 48eed86931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -88,7 +88,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import AstraDBChatMessageHistory\n", "from langchain_community.chat_message_histories import AstraDBChatMessageHistory\n",
"\n", "\n",
"message_history = AstraDBChatMessageHistory(\n", "message_history = AstraDBChatMessageHistory(\n",
" session_id=\"test-session\",\n", " session_id=\"test-session\",\n",

@ -45,6 +45,18 @@
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()" "# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "0c68f434-0ccf-49a4-8313-e9f6064086a8",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.chat_message_histories import (\n",
" DynamoDBChatMessageHistory,\n",
")"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "030d784f", "id": "030d784f",
@ -105,8 +117,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import DynamoDBChatMessageHistory\n",
"\n",
"history = DynamoDBChatMessageHistory(table_name=\"SessionTable\", session_id=\"0\")\n", "history = DynamoDBChatMessageHistory(table_name=\"SessionTable\", session_id=\"0\")\n",
"\n", "\n",
"history.add_user_message(\"hi!\")\n", "history.add_user_message(\"hi!\")\n",
@ -152,8 +162,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import DynamoDBChatMessageHistory\n",
"\n",
"history = DynamoDBChatMessageHistory(\n", "history = DynamoDBChatMessageHistory(\n",
" table_name=\"SessionTable\",\n", " table_name=\"SessionTable\",\n",
" session_id=\"0\",\n", " session_id=\"0\",\n",
@ -184,6 +192,7 @@
"execution_count": 14, "execution_count": 14,
"id": "088c037c", "id": "088c037c",
"metadata": { "metadata": {
"collapsed": false,
"jupyter": { "jupyter": {
"outputs_hidden": false "outputs_hidden": false
} }
@ -198,8 +207,6 @@
} }
], ],
"source": [ "source": [
"from langchain_community.chat_message_histories import DynamoDBChatMessageHistory\n",
"\n",
"composite_table = dynamodb.create_table(\n", "composite_table = dynamodb.create_table(\n",
" TableName=\"CompositeTable\",\n", " TableName=\"CompositeTable\",\n",
" KeySchema=[\n", " KeySchema=[\n",
@ -384,7 +391,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.1" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -123,7 +123,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import CassandraChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" CassandraChatMessageHistory,\n",
")\n",
"\n", "\n",
"message_history = CassandraChatMessageHistory(\n", "message_history = CassandraChatMessageHistory(\n",
" session_id=\"test-session\",\n", " session_id=\"test-session\",\n",
@ -181,7 +183,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.17" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -116,7 +116,9 @@
"source": [ "source": [
"import os\n", "import os\n",
"\n", "\n",
"from langchain.memory import ElasticsearchChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" ElasticsearchChatMessageHistory,\n",
")\n",
"\n", "\n",
"es_url = os.environ.get(\"ES_URL\", \"http://localhost:9200\")\n", "es_url = os.environ.get(\"ES_URL\", \"http://localhost:9200\")\n",
"\n", "\n",

@ -374,7 +374,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.5" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -27,7 +27,7 @@
"source": [ "source": [
"from datetime import timedelta\n", "from datetime import timedelta\n",
"\n", "\n",
"from langchain.memory import MomentoChatMessageHistory\n", "from langchain_community.chat_message_histories import MomentoChatMessageHistory\n",
"\n", "\n",
"session_id = \"foo\"\n", "session_id = \"foo\"\n",
"cache_name = \"langchain\"\n", "cache_name = \"langchain\"\n",

@ -202,9 +202,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 4
} }

@ -19,7 +19,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import Neo4jChatMessageHistory\n", "from langchain_community.chat_message_histories import Neo4jChatMessageHistory\n",
"\n", "\n",
"history = Neo4jChatMessageHistory(\n", "history = Neo4jChatMessageHistory(\n",
" url=\"bolt://localhost:7687\",\n", " url=\"bolt://localhost:7687\",\n",
@ -68,7 +68,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.8" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -19,7 +19,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import PostgresChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" PostgresChatMessageHistory,\n",
")\n",
"\n", "\n",
"history = PostgresChatMessageHistory(\n", "history = PostgresChatMessageHistory(\n",
" connection_string=\"postgresql://postgres:mypassword@localhost/chat_history\",\n", " connection_string=\"postgresql://postgres:mypassword@localhost/chat_history\",\n",

@ -31,6 +31,16 @@
"pip install -U langchain-community redis" "pip install -U langchain-community redis"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "b11090e7-284b-4ed2-9790-ce0d35638717",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.chat_message_histories import RedisChatMessageHistory"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "20b99474-75ea-422e-9809-fbdb9d103afc", "id": "20b99474-75ea-422e-9809-fbdb9d103afc",
@ -46,8 +56,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import RedisChatMessageHistory\n",
"\n",
"history = RedisChatMessageHistory(\"foo\", url=\"redis://localhost:6379\")\n", "history = RedisChatMessageHistory(\"foo\", url=\"redis://localhost:6379\")\n",
"\n", "\n",
"history.add_user_message(\"hi!\")\n", "history.add_user_message(\"hi!\")\n",
@ -103,7 +111,6 @@
"source": [ "source": [
"from typing import Optional\n", "from typing import Optional\n",
"\n", "\n",
"from langchain_community.chat_message_histories import RedisChatMessageHistory\n",
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
"from langchain_core.runnables.history import RunnableWithMessageHistory\n", "from langchain_core.runnables.history import RunnableWithMessageHistory\n",
"from langchain_openai import ChatOpenAI" "from langchain_openai import ChatOpenAI"
@ -178,7 +185,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.18" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -52,7 +52,9 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import RocksetChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" RocksetChatMessageHistory,\n",
")\n",
"from rockset import Regions, RocksetClient\n", "from rockset import Regions, RocksetClient\n",
"\n", "\n",
"history = RocksetChatMessageHistory(\n", "history = RocksetChatMessageHistory(\n",

@ -18,7 +18,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import SingleStoreDBChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" SingleStoreDBChatMessageHistory,\n",
")\n",
"\n", "\n",
"history = SingleStoreDBChatMessageHistory(\n", "history = SingleStoreDBChatMessageHistory(\n",
" session_id=\"foo\", host=\"root:pass@localhost:3306/db\"\n", " session_id=\"foo\", host=\"root:pass@localhost:3306/db\"\n",
@ -56,9 +58,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.2" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 5 "nbformat_minor": 5
} }

@ -71,7 +71,10 @@
"end_time": "2023-08-28T10:04:38.077748Z", "end_time": "2023-08-28T10:04:38.077748Z",
"start_time": "2023-08-28T10:04:36.105894Z" "start_time": "2023-08-28T10:04:36.105894Z"
}, },
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -94,7 +97,10 @@
"end_time": "2023-08-28T10:04:38.929396Z", "end_time": "2023-08-28T10:04:38.929396Z",
"start_time": "2023-08-28T10:04:38.915727Z" "start_time": "2023-08-28T10:04:38.915727Z"
}, },
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"outputs": [ "outputs": [
{ {
@ -241,7 +247,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.1" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -36,7 +36,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import StreamlitChatMessageHistory\n", "from langchain_community.chat_message_histories import (\n",
" StreamlitChatMessageHistory,\n",
")\n",
"\n", "\n",
"history = StreamlitChatMessageHistory(key=\"chat_messages\")\n", "history = StreamlitChatMessageHistory(key=\"chat_messages\")\n",
"\n", "\n",
@ -71,8 +73,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories import StreamlitChatMessageHistory\n",
"\n",
"# Optionally, specify your own session_state key for storing messages\n", "# Optionally, specify your own session_state key for storing messages\n",
"msgs = StreamlitChatMessageHistory(key=\"special_app_key\")\n", "msgs = StreamlitChatMessageHistory(key=\"special_app_key\")\n",
"\n", "\n",

@ -244,7 +244,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "langchain", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -258,9 +258,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.13" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 4
} }

@ -17,7 +17,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.chat_message_histories.upstash_redis import (\n", "from langchain_community.chat_message_histories import (\n",
" UpstashRedisChatMessageHistory,\n", " UpstashRedisChatMessageHistory,\n",
")\n", ")\n",
"\n", "\n",

@ -75,7 +75,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.memory import XataChatMessageHistory\n", "from langchain_community.chat_message_histories import XataChatMessageHistory\n",
"\n", "\n",
"history = XataChatMessageHistory(\n", "history = XataChatMessageHistory(\n",
" session_id=\"session-1\", api_key=api_key, db_url=db_url, table_name=\"memory\"\n", " session_id=\"session-1\", api_key=api_key, db_url=db_url, table_name=\"memory\"\n",
@ -154,7 +154,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_community.vectorstores.xata import XataVectorStore\n", "from langchain_community.vectorstores import XataVectorStore\n",
"from langchain_openai import OpenAIEmbeddings\n", "from langchain_openai import OpenAIEmbeddings\n",
"\n", "\n",
"embeddings = OpenAIEmbeddings()\n", "embeddings = OpenAIEmbeddings()\n",

@ -419,7 +419,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.6" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

Loading…
Cancel
Save