mirror of https://github.com/hwchase17/langchain
docs: Update Google El Carro for Oracle Workload Documentation. (#18394)
In this commit we update the documentation for Google El Carro for Oracle Workloads. We amend the documentation in the Google Providers page to use the correct name which is El Carro for Oracle Workloads. We also add changes to the document_loaders and memory pages to reflect changes we made in our repo.pull/18463/head
parent
e192f6b6eb
commit
dd6f85caf1
@ -1,368 +1,393 @@
|
|||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Google El Carro Oracle Operator\n",
|
"# Google El Carro Oracle Operator\n",
|
||||||
"\n",
|
"\n",
|
||||||
"> Google [El Carro Oracle Operator](https://github.com/GoogleCloudPlatform/elcarro-oracle-operator) offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring. Extend your database application to build AI-powered experiences leveraging Oracle Langchain integrations.\n",
|
"> Google [El Carro Oracle Operator](https://github.com/GoogleCloudPlatform/elcarro-oracle-operator) offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring. Extend your Oracle database's capabilities to build AI-powered experiences by leveraging the El Carro Langchain integration.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This guide goes over how to use the El Carro Langchain integration to store chat message history with the `ElCarroChatMessageHistory` class.\n",
|
"This guide goes over how to use the El Carro Langchain integration to store chat message history with the `ElCarroChatMessageHistory` class. This integration works for any Oracle database, regardless of where it is running.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-el-carro-python/blob/main/docs/chat_message_history.ipynb)"
|
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-el-carro-python/blob/main/docs/chat_message_history.ipynb)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Before You Begin\n",
|
"## Before You Begin\n",
|
||||||
"\n",
|
"\n",
|
||||||
"To run this notebook, you will need to do the following:\n",
|
"To run this notebook, you will need to do the following:\n",
|
||||||
" * Complete the [Getting Started](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/README.md#getting-started) section"
|
" * Complete the [Getting Started](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/README.md#getting-started) section if you would like to run your Oracle database with El Carro."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### 🦜🔗 Library Installation\n",
|
"### 🦜🔗 Library Installation\n",
|
||||||
"The integration lives in its own `langchain-google-el-carro` package, so we need to install it."
|
"The integration lives in its own `langchain-google-el-carro` package, so we need to install it."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%pip install --upgrade --quiet langchain-google-el-carro langchain-google-vertexai langchain"
|
"%pip install --upgrade --quiet langchain-google-el-carro langchain-google-vertexai langchain"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top."
|
"**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# # Automatically restart kernel after installs so that your environment can access the new packages\n",
|
"# # Automatically restart kernel after installs so that your environment can access the new packages\n",
|
||||||
"# import IPython\n",
|
"# import IPython\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# app = IPython.Application.instance()\n",
|
"# app = IPython.Application.instance()\n",
|
||||||
"# app.kernel.do_shutdown(True)"
|
"# app.kernel.do_shutdown(True)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### 🔐 Authentication\n",
|
"### 🔐 Authentication\n",
|
||||||
"Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n",
|
"Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* If you are using Colab to run this notebook, use the cell below and continue.\n",
|
"* If you are using Colab to run this notebook, use the cell below and continue.\n",
|
||||||
"* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)."
|
"* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from google.colab import auth\n",
|
"from google.colab import auth\n",
|
||||||
"\n",
|
"\n",
|
||||||
"auth.authenticate_user()"
|
"auth.authenticate_user()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### ☁ Set Your Google Cloud Project\n",
|
"### ☁ Set Your Google Cloud Project\n",
|
||||||
"Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n",
|
"Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"If you don't know your project ID, try the following:\n",
|
"If you don't know your project ID, try the following:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* Run `gcloud config list`.\n",
|
"* Run `gcloud config list`.\n",
|
||||||
"* Run `gcloud projects list`.\n",
|
"* Run `gcloud projects list`.\n",
|
||||||
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)."
|
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n",
|
"# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n",
|
"PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Set the project id\n",
|
"# Set the project id\n",
|
||||||
"!gcloud config set project {PROJECT_ID}"
|
"!gcloud config set project {PROJECT_ID}"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Basic Usage"
|
"## Basic Usage"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Set Up Oracle Database Connection\n",
|
"### Set Up Oracle Database Connection\n",
|
||||||
"You can find the hostname and port values in the status of the El Carro\n",
|
"Fill out the following variable with your Oracle database connections details."
|
||||||
"Kubernetes instance. Use the user password you created for your PDB."
|
]
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
"cell_type": "code",
|
||||||
"cell_type": "code",
|
"execution_count": null,
|
||||||
"execution_count": null,
|
"outputs": [],
|
||||||
"metadata": {},
|
"source": [
|
||||||
"outputs": [],
|
"# @title Set Your Values Here { display-mode: \"form\" }\n",
|
||||||
"source": [
|
"HOST = \"127.0.0.1\" # @param {type: \"string\"}\n",
|
||||||
"# @title Set Your Values Here { display-mode: \"form\" }\n",
|
"PORT = 3307 # @param {type: \"integer\"}\n",
|
||||||
"HOST = \"127.0.0.1\" # @param {type: \"string\"}\n",
|
"DATABASE = \"my-database\" # @param {type: \"string\"}\n",
|
||||||
"PORT = 3307 # @param {type: \"integer\"}\n",
|
"TABLE_NAME = \"message_store\" # @param {type: \"string\"}\n",
|
||||||
"DATABASE = \"my-database\" # @param {type: \"string\"}\n",
|
"USER = \"my-user\" # @param {type: \"string\"}\n",
|
||||||
"TABLE_NAME = \"message_store\" # @param {type: \"string\"}\n",
|
"PASSWORD = input(\"Please provide a password to be used for the database user: \")"
|
||||||
"USER = \"my-user\" # @param {type: \"string\"}\n",
|
],
|
||||||
"PASSWORD = input(\"Please provide a password to be used for the database user: \")"
|
"metadata": {
|
||||||
]
|
"collapsed": false
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"cell_type": "markdown",
|
{
|
||||||
"metadata": {},
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"### ElCarroEngine Connection Pool\n",
|
"\n",
|
||||||
"\n",
|
"If you are using `El Carro`, you can find the hostname and port values in the\n",
|
||||||
"`ElCarroEngine` configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices."
|
"status of the `El Carro` Kubernetes instance.\n",
|
||||||
]
|
"Use the user password you created for your PDB.\n",
|
||||||
},
|
"Example"
|
||||||
{
|
],
|
||||||
"cell_type": "code",
|
"metadata": {
|
||||||
"execution_count": null,
|
"collapsed": false
|
||||||
"metadata": {},
|
}
|
||||||
"outputs": [],
|
},
|
||||||
"source": [
|
{
|
||||||
"from langchain_google_el_carro import ElCarroEngine\n",
|
"cell_type": "markdown",
|
||||||
"\n",
|
"source": [
|
||||||
"elcarro_engine = ElCarroEngine.from_instance(\n",
|
"kubectl get -w instances.oracle.db.anthosapis.com -n db\n",
|
||||||
" db_host=HOST,\n",
|
"NAME DB ENGINE VERSION EDITION ENDPOINT URL DB NAMES BACKUP ID READYSTATUS READYREASON DBREADYSTATUS DBREADYREASON\n",
|
||||||
" db_port=PORT,\n",
|
"mydb Oracle 18c Express mydb-svc.db 34.71.69.25:6021 False CreateInProgress"
|
||||||
" db_name=DATABASE,\n",
|
],
|
||||||
" db_user=USER,\n",
|
"metadata": {
|
||||||
" db_password=PASSWORD,\n",
|
"collapsed": false
|
||||||
")"
|
}
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
"cell_type": "markdown",
|
||||||
"cell_type": "markdown",
|
"metadata": {},
|
||||||
"metadata": {},
|
"source": [
|
||||||
"source": [
|
"### ElCarroEngine Connection Pool\n",
|
||||||
"### Initialize a table\n",
|
"\n",
|
||||||
"The `ElCarroChatMessageHistory` class requires a database table with a specific\n",
|
"`ElCarroEngine` configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices."
|
||||||
"schema in order to store the chat message history.\n",
|
]
|
||||||
"\n",
|
},
|
||||||
"The `ElCarroEngine` class has a\n",
|
{
|
||||||
"method `init_chat_history_table()` that can be used to create a table with the\n",
|
"cell_type": "code",
|
||||||
"proper schema for you."
|
"execution_count": null,
|
||||||
]
|
"metadata": {},
|
||||||
},
|
"outputs": [],
|
||||||
{
|
"source": [
|
||||||
"cell_type": "code",
|
"from langchain_google_el_carro import ElCarroEngine\n",
|
||||||
"execution_count": null,
|
"\n",
|
||||||
"metadata": {},
|
"elcarro_engine = ElCarroEngine.from_instance(\n",
|
||||||
"outputs": [],
|
" db_host=HOST,\n",
|
||||||
"source": [
|
" db_port=PORT,\n",
|
||||||
"elcarro_engine.init_chat_history_table(table_name=TABLE_NAME)"
|
" db_name=DATABASE,\n",
|
||||||
]
|
" db_user=USER,\n",
|
||||||
},
|
" db_password=PASSWORD,\n",
|
||||||
{
|
")"
|
||||||
"cell_type": "markdown",
|
]
|
||||||
"metadata": {},
|
},
|
||||||
"source": [
|
{
|
||||||
"### ElCarroChatMessageHistory\n",
|
"cell_type": "markdown",
|
||||||
"\n",
|
"metadata": {},
|
||||||
"To initialize the `ElCarroChatMessageHistory` class you need to provide only 3\n",
|
"source": [
|
||||||
"things:\n",
|
"### Initialize a table\n",
|
||||||
"\n",
|
"The `ElCarroChatMessageHistory` class requires a database table with a specific\n",
|
||||||
"1. `elcarro_engine` - An instance of an `ElCarroEngine` engine.\n",
|
"schema in order to store the chat message history.\n",
|
||||||
"1. `session_id` - A unique identifier string that specifies an id for the\n",
|
"\n",
|
||||||
" session.\n",
|
"The `ElCarroEngine` class has a\n",
|
||||||
"1. `table_name` : The name of the table within the Oracle database to store the\n",
|
"method `init_chat_history_table()` that can be used to create a table with the\n",
|
||||||
" chat message history."
|
"proper schema for you."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain_google_el_carro import ElCarroChatMessageHistory\n",
|
"elcarro_engine.init_chat_history_table(table_name=TABLE_NAME)"
|
||||||
"\n",
|
]
|
||||||
"history = ElCarroChatMessageHistory(\n",
|
},
|
||||||
" elcarro_engine=elcarro_engine, session_id=\"test_session\", table_name=TABLE_NAME\n",
|
{
|
||||||
")\n",
|
"cell_type": "markdown",
|
||||||
"history.add_user_message(\"hi!\")\n",
|
"metadata": {},
|
||||||
"history.add_ai_message(\"whats up?\")"
|
"source": [
|
||||||
]
|
"### ElCarroChatMessageHistory\n",
|
||||||
},
|
"\n",
|
||||||
{
|
"To initialize the `ElCarroChatMessageHistory` class you need to provide only 3\n",
|
||||||
"cell_type": "code",
|
"things:\n",
|
||||||
"execution_count": null,
|
"\n",
|
||||||
"metadata": {},
|
"1. `elcarro_engine` - An instance of an `ElCarroEngine` engine.\n",
|
||||||
"outputs": [],
|
"1. `session_id` - A unique identifier string that specifies an id for the\n",
|
||||||
"source": [
|
" session.\n",
|
||||||
"history.messages"
|
"1. `table_name` : The name of the table within the Oracle database to store the\n",
|
||||||
]
|
" chat message history."
|
||||||
},
|
]
|
||||||
{
|
},
|
||||||
"cell_type": "markdown",
|
{
|
||||||
"metadata": {},
|
"cell_type": "code",
|
||||||
"source": [
|
"execution_count": null,
|
||||||
"#### Cleaning up\n",
|
"metadata": {},
|
||||||
"When the history of a specific session is obsolete and can be deleted, it can be done the following way.\n",
|
"outputs": [],
|
||||||
"\n",
|
"source": [
|
||||||
"**Note:** Once deleted, the data is no longer stored in AlloyDB and is gone forever."
|
"from langchain_google_el_carro import ElCarroChatMessageHistory\n",
|
||||||
]
|
"\n",
|
||||||
},
|
"history = ElCarroChatMessageHistory(\n",
|
||||||
{
|
" elcarro_engine=elcarro_engine, session_id=\"test_session\", table_name=TABLE_NAME\n",
|
||||||
"cell_type": "code",
|
")\n",
|
||||||
"execution_count": null,
|
"history.add_user_message(\"hi!\")\n",
|
||||||
"metadata": {},
|
"history.add_ai_message(\"whats up?\")"
|
||||||
"outputs": [],
|
]
|
||||||
"source": [
|
},
|
||||||
"history.clear()"
|
{
|
||||||
]
|
"cell_type": "code",
|
||||||
},
|
"execution_count": null,
|
||||||
{
|
"metadata": {},
|
||||||
"cell_type": "markdown",
|
"outputs": [],
|
||||||
"metadata": {},
|
"source": [
|
||||||
"source": [
|
"history.messages"
|
||||||
"## 🔗 Chaining\n",
|
]
|
||||||
"\n",
|
},
|
||||||
"We can easily combine this message history class with [LCEL Runnables](/docs/expression_language/how_to/message_history)\n",
|
{
|
||||||
"\n",
|
"cell_type": "markdown",
|
||||||
"To do this we will use one of [Google's Vertex AI chat models](https://python.langchain.com/docs/integrations/chat/google_vertex_ai_palm) which requires that you [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com) in your Google Cloud Project.\n"
|
"metadata": {},
|
||||||
]
|
"source": [
|
||||||
},
|
"#### Cleaning up\n",
|
||||||
{
|
"When the history of a specific session is obsolete and can be deleted, it can be done the following way.\n",
|
||||||
"cell_type": "code",
|
"\n",
|
||||||
"execution_count": null,
|
"**Note:** Once deleted, the data is no longer stored in your database and is gone forever."
|
||||||
"metadata": {},
|
]
|
||||||
"outputs": [],
|
},
|
||||||
"source": [
|
{
|
||||||
"# enable Vertex AI API\n",
|
"cell_type": "code",
|
||||||
"!gcloud services enable aiplatform.googleapis.com"
|
"execution_count": null,
|
||||||
]
|
"metadata": {},
|
||||||
},
|
"outputs": [],
|
||||||
{
|
"source": [
|
||||||
"cell_type": "code",
|
"history.clear()"
|
||||||
"execution_count": null,
|
]
|
||||||
"metadata": {},
|
},
|
||||||
"outputs": [],
|
{
|
||||||
"source": [
|
"cell_type": "markdown",
|
||||||
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
"metadata": {},
|
||||||
"from langchain_core.runnables.history import RunnableWithMessageHistory\n",
|
"source": [
|
||||||
"from langchain_google_vertexai import ChatVertexAI"
|
"## 🔗 Chaining\n",
|
||||||
]
|
"\n",
|
||||||
},
|
"We can easily combine this message history class with [LCEL Runnables](/docs/expression_language/how_to/message_history)\n",
|
||||||
{
|
"\n",
|
||||||
"cell_type": "code",
|
"To do this we will use one of [Google's Vertex AI chat models](https://python.langchain.com/docs/integrations/chat/google_vertex_ai_palm) which requires that you [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com) in your Google Cloud Project.\n"
|
||||||
"execution_count": null,
|
]
|
||||||
"metadata": {},
|
},
|
||||||
"outputs": [],
|
{
|
||||||
"source": [
|
"cell_type": "code",
|
||||||
"prompt = ChatPromptTemplate.from_messages(\n",
|
"execution_count": null,
|
||||||
" [\n",
|
"metadata": {},
|
||||||
" (\"system\", \"You are a helpful assistant.\"),\n",
|
"outputs": [],
|
||||||
" MessagesPlaceholder(variable_name=\"history\"),\n",
|
"source": [
|
||||||
" (\"human\", \"{question}\"),\n",
|
"# enable Vertex AI API\n",
|
||||||
" ]\n",
|
"!gcloud services enable aiplatform.googleapis.com"
|
||||||
")\n",
|
]
|
||||||
"\n",
|
},
|
||||||
"chain = prompt | ChatVertexAI(project=PROJECT_ID)"
|
{
|
||||||
]
|
"cell_type": "code",
|
||||||
},
|
"execution_count": null,
|
||||||
{
|
"metadata": {},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"execution_count": null,
|
"source": [
|
||||||
"metadata": {},
|
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
||||||
"outputs": [],
|
"from langchain_core.runnables.history import RunnableWithMessageHistory\n",
|
||||||
"source": [
|
"from langchain_google_vertexai import ChatVertexAI"
|
||||||
"chain_with_history = RunnableWithMessageHistory(\n",
|
]
|
||||||
" chain,\n",
|
},
|
||||||
" lambda session_id: ElCarroChatMessageHistory(\n",
|
{
|
||||||
" elcarro_engine,\n",
|
"cell_type": "code",
|
||||||
" session_id=session_id,\n",
|
"execution_count": null,
|
||||||
" table_name=TABLE_NAME,\n",
|
"metadata": {},
|
||||||
" ),\n",
|
"outputs": [],
|
||||||
" input_messages_key=\"question\",\n",
|
"source": [
|
||||||
" history_messages_key=\"history\",\n",
|
"prompt = ChatPromptTemplate.from_messages(\n",
|
||||||
")"
|
" [\n",
|
||||||
]
|
" (\"system\", \"You are a helpful assistant.\"),\n",
|
||||||
},
|
" MessagesPlaceholder(variable_name=\"history\"),\n",
|
||||||
{
|
" (\"human\", \"{question}\"),\n",
|
||||||
"cell_type": "code",
|
" ]\n",
|
||||||
"execution_count": null,
|
")\n",
|
||||||
"metadata": {},
|
"\n",
|
||||||
"outputs": [],
|
"chain = prompt | ChatVertexAI(project=PROJECT_ID)"
|
||||||
"source": [
|
]
|
||||||
"# This is where we configure the session id\n",
|
},
|
||||||
"config = {\"configurable\": {\"session_id\": \"test_session\"}}"
|
{
|
||||||
]
|
"cell_type": "code",
|
||||||
},
|
"execution_count": null,
|
||||||
{
|
"metadata": {},
|
||||||
"cell_type": "code",
|
"outputs": [],
|
||||||
"execution_count": null,
|
"source": [
|
||||||
"metadata": {},
|
"chain_with_history = RunnableWithMessageHistory(\n",
|
||||||
"outputs": [],
|
" chain,\n",
|
||||||
"source": [
|
" lambda session_id: ElCarroChatMessageHistory(\n",
|
||||||
"chain_with_history.invoke({\"question\": \"Hi! I'm bob\"}, config=config)"
|
" elcarro_engine,\n",
|
||||||
]
|
" session_id=session_id,\n",
|
||||||
},
|
" table_name=TABLE_NAME,\n",
|
||||||
{
|
" ),\n",
|
||||||
"cell_type": "code",
|
" input_messages_key=\"question\",\n",
|
||||||
"execution_count": null,
|
" history_messages_key=\"history\",\n",
|
||||||
"metadata": {},
|
")"
|
||||||
"outputs": [],
|
]
|
||||||
"source": [
|
},
|
||||||
"chain_with_history.invoke({\"question\": \"Whats my name\"}, config=config)"
|
{
|
||||||
]
|
"cell_type": "code",
|
||||||
}
|
"execution_count": null,
|
||||||
],
|
"metadata": {},
|
||||||
"metadata": {
|
"outputs": [],
|
||||||
"kernelspec": {
|
"source": [
|
||||||
"display_name": "Python 3 (ipykernel)",
|
"# This is where we configure the session id\n",
|
||||||
"language": "python",
|
"config = {\"configurable\": {\"session_id\": \"test_session\"}}"
|
||||||
"name": "python3"
|
]
|
||||||
},
|
},
|
||||||
"language_info": {
|
{
|
||||||
"codemirror_mode": {
|
"cell_type": "code",
|
||||||
"name": "ipython",
|
"execution_count": null,
|
||||||
"version": 3
|
"metadata": {},
|
||||||
},
|
"outputs": [],
|
||||||
"file_extension": ".py",
|
"source": [
|
||||||
"mimetype": "text/x-python",
|
"chain_with_history.invoke({\"question\": \"Hi! I'm bob\"}, config=config)"
|
||||||
"name": "python",
|
]
|
||||||
"nbconvert_exporter": "python",
|
},
|
||||||
"pygments_lexer": "ipython3",
|
{
|
||||||
"version": "3.11.5"
|
"cell_type": "code",
|
||||||
}
|
"execution_count": null,
|
||||||
},
|
"metadata": {},
|
||||||
"nbformat": 4,
|
"outputs": [],
|
||||||
"nbformat_minor": 4
|
"source": [
|
||||||
|
"chain_with_history.invoke({\"question\": \"Whats my name\"}, config=config)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.11.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue