-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add notebooks for integrations #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,79 +1,184 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Google DATABASE\n", | ||
| "\n", | ||
| "[Google DATABASE](https://cloud.google.com/DATABASE).\n", | ||
| "\n", | ||
| "Save chat messages into `DATABASE`." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Pre-reqs" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "tags": [] | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "%pip install PACKAGE_NAME" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 3, | ||
| "metadata": { | ||
| "tags": [] | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from PACKAGE import LOADER" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Basic Usage" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "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.10.6" | ||
| } | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "6-0_o3DxsFGi" | ||
| }, | ||
| "source": [ | ||
| "Google Database\n", | ||
| "\n", | ||
| "Use [Google Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis/memorystore-for-redis-overview) to store chat message history for LangChain." | ||
| ] | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "dWakBoPnsFGj" | ||
| }, | ||
| "source": [ | ||
| "## Pre-reqs" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "EudfLv_UsFGk" | ||
| }, | ||
| "source": [ | ||
| "### Setting Up a Memorystore for Redis Instance\n", | ||
| "\n", | ||
| "Before proceeding, an active Memorystore for Redis instance is needed to store chat message history:\n", | ||
| "\n", | ||
| "* Create a Memorystore for Redis Instance (>= 5.0): If an instance doesn't exist, follow the instructions at https://cloud.google.com/memorystore/docs/redis/create-instance-console to create a new one. Ensure the version is greater than or equal to 5.0.\n", | ||
| "* Obtain Endpoint: Note the endpoint associated with the instance." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "J5nxjYxHsFGk" | ||
| }, | ||
| "source": [ | ||
| "### Installing the LangChain Memorystore for Redis Module\n", | ||
| "\n", | ||
| "Interaction with the Memorystore for Redis instance from LangChain requires installing the necessary module:" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "tags": [], | ||
| "id": "iLwVMVkYsFGk" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Install Memorystore for Redis for LangChain module\n", | ||
| "%pip install langchain_google_memorystore_redis" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "2L7kMu__sFGl" | ||
| }, | ||
| "source": [ | ||
| "## Basic Usage" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "A2fT1iEhsFGl" | ||
| }, | ||
| "source": [ | ||
| "### Initialize a MemorystoreChatMessageHistory\n", | ||
| "\n", | ||
| "Each chat message history object must have a unique session ID. If the session ID already has messages stored in Redis, they will can be retrieved." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "id": "YEDKWR6asFGl" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import redis\n", | ||
| "from langchain_google_memorystore_redis import MemorystoreChatMessageHistory\n", | ||
| "\n", | ||
| "# Connect to a Memorystore for Redis instance\n", | ||
| "redis_client = redis.from_url(\"redis://127.0.0.1:6379\")\n", | ||
| "\n", | ||
| "message_history = MemorystoreChatMessageHistory(redis_client, session_id='session1')" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "EmoJcTgosFGl" | ||
| }, | ||
| "source": [ | ||
| "### Add Messages" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "id": "gB1PGe6wsFGm" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "message_history.add_ai_message('Hey! I am AI!')\n", | ||
| "message_history.add_user_message('Hey! I am human!')" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "02xxvmzTsFGm" | ||
| }, | ||
| "source": [ | ||
| "### Retrieve All Messages Stored in the Session" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "id": "BvS3UFsysFGm" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "message_history.messages" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "id": "sFJdt3ubsFGo" | ||
| }, | ||
| "source": [ | ||
| "### Clear Messages" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "id": "H5I7K3MTsFGo" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "message_history.clear()" | ||
| ] | ||
| } | ||
| ], | ||
| "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.6" | ||
| }, | ||
| "colab": { | ||
| "provenance": [] | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 0 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.