diff --git a/.kokoro/publish-docs.sh b/.kokoro/publish-docs.sh index 2d1d22c3..e7480aa5 100755 --- a/.kokoro/publish-docs.sh +++ b/.kokoro/publish-docs.sh @@ -27,7 +27,8 @@ python3 -m nox --version # build docs nox -s docs -VERSION=$(python -c "import langchain_google_cloud_sql_pg;print(langchain_google_cloud_sql_pg.__version__)") +python3 -m pip install . +VERSION=$(python3 -c "import langchain_google_cloud_sql_pg;print(langchain_google_cloud_sql_pg.__version__)") # create metadata python3 -m docuploader create-metadata \ diff --git a/CHANGELOG.md b/CHANGELOG.md index 89a60e02..665ec098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [0.4.0](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/compare/v0.3.0...v0.4.0) (2024-04-03) + + +### Features + +* Support private ip ([#106](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/issues/106)) ([0b8df1e](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/commit/0b8df1ebd803d5d648396291788f6cede538a042)) + + +### Bug Fixes + +* API reference doc pipeline ([#108](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/issues/108)) ([6ab1a40](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/commit/6ab1a409193ba49a85879b02f0234990f22c249f)) + ## [0.3.0](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/compare/v0.2.0...v0.3.0) (2024-04-02) diff --git a/README.rst b/README.rst index 17d5efaa..592e259e 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,6 @@ Cloud SQL for PostgreSQL for LangChain |preview| |pypi| |versions| - `Client Library Documentation`_ -- `How-to Guides`_ - `Product Documentation`_ .. |preview| image:: https://img.shields.io/badge/support-preview-orange.svg @@ -14,7 +13,6 @@ Cloud SQL for PostgreSQL for LangChain .. |versions| image:: https://img.shields.io/pypi/pyversions/langchain-google-cloud-sql-pg.svg :target: https://pypi.org/project/langchain-google-cloud-sql-pg/ .. _Client Library Documentation: https://github.com/googleapis/langchain-google-cloud-sql-pg-python -.. _How-to Guides: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/samples .. _Product Documentation: https://cloud.google.com/sql/docs Quick Start @@ -87,70 +85,70 @@ Vector Store Usage Use a Vector Store to store embedded data and perform vector search. -.. code:: python +.. code-block:: python - from langchain_google_cloud_sql_pg import PostgresVectorstore, PostgresEngine - from langchain.embeddings import VertexAIEmbeddings + from langchain_google_cloud_sql_pg import PostgresVectorstore, PostgresEngine + from langchain.embeddings import VertexAIEmbeddings - engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") - engine.init_vectorstore_table( - table_name="my-table", - vector_size=768, # Vector size for `VertexAIEmbeddings()` - ) - embeddings_service = VertexAIEmbeddings() - vectorstore = PostgresVectorStore.create_sync( - engine, - table_name="my-table", - embeddings=embedding_service - ) + engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") + engine.init_vectorstore_table( + table_name="my-table", + vector_size=768, # Vector size for `VertexAIEmbeddings()` + ) + embeddings_service = VertexAIEmbeddings() + vectorstore = PostgresVectorStore.create_sync( + engine, + table_name="my-table", + embeddings=embedding_service + ) See the full `Vector Store`_ tutorial. -.. _`Vector Store`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/samples/vector_store.ipynb +.. _`Vector Store`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/docs/vector_store.ipynb Document Loader Usage ~~~~~~~~~~~~~~~~~~~~~ Use a document loader to load data as Documents. -.. code:: python +.. code-block:: python - from langchain_google_cloud_sql_pg import PostgresEngine, PostgresLoader + from langchain_google_cloud_sql_pg import PostgresEngine, PostgresLoader - engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") - loader = PostgresSQLLoader.create_sync( - engine, - table_name="my-table-name" - ) - docs = loader.lazy_load() + engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") + loader = PostgresSQLLoader.create_sync( + engine, + table_name="my-table-name" + ) + docs = loader.lazy_load() See the full `Document Loader`_ tutorial. -.. _`Document Loader`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/samples/document_loader.ipynb +.. _`Document Loader`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/docs/document_loader.ipynb Chat Message History Usage ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use Chat Message History to store messages and provide conversation history to LLMs. -.. code:: python +.. code-block:: python - from langchain_google_cloud_sql_pg import PostgresChatMessageHistory, PostgresEngine + from langchain_google_cloud_sql_pg import PostgresChatMessageHistory, PostgresEngine - engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") - engine.init_chat_history_table(table_name="my-message-store") - history = PostgresChatMessageHistory.create_sync( - engine, - table_name="my-message-store", - session_id="my-session_id" - ) + engine = PostgresEngine.from_instance("project-id", "region", "my-instance", "my-database") + engine.init_chat_history_table(table_name="my-message-store") + history = PostgresChatMessageHistory.create_sync( + engine, + table_name="my-message-store", + session_id="my-session_id" + ) See the full `Chat Message History`_ tutorial. -.. _`Chat Message History`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/samples/chat_message_history.ipynb +.. _`Chat Message History`: https://github.com/googleapis/langchain-google-cloud-sql-pg-python/tree/main/docs/chat_message_history.ipynb Contributing ~~~~~~~~~~~~ diff --git a/samples/chat_message_history.ipynb b/docs/chat_message_history.ipynb similarity index 99% rename from samples/chat_message_history.ipynb rename to docs/chat_message_history.ipynb index c24d2660..e9493dee 100644 --- a/samples/chat_message_history.ipynb +++ b/docs/chat_message_history.ipynb @@ -555,4 +555,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/samples/document_loader.ipynb b/docs/document_loader.ipynb similarity index 100% rename from samples/document_loader.ipynb rename to docs/document_loader.ipynb diff --git a/samples/vector_store.ipynb b/docs/vector_store.ipynb similarity index 100% rename from samples/vector_store.ipynb rename to docs/vector_store.ipynb diff --git a/noxfile.py b/noxfile.py index 8bf1c4a5..8fb4d61b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -19,6 +19,8 @@ import os import pathlib import shutil +from pathlib import Path +from typing import Optional import nox @@ -28,6 +30,7 @@ # 'docfx' is excluded since it only needs to run in 'docs-presubmit' nox.options.sessions = [ "docs", + "docfx", ] # Error if a python version is missing diff --git a/pyproject.toml b/pyproject.toml index 1f09afa1..084614cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "langchain-google-cloud-sql-pg" dynamic = ["version"] description = "LangChain integrations for Google Cloud SQL for PostgreSQL" -readme = "README.md" +readme = "README.rst" license = {file = "LICENSE"} requires-python = ">=3.8" authors = [ diff --git a/samples/langchain_quick_start.ipynb b/samples/langchain_quick_start.ipynb index 06440a48..c6361566 100644 --- a/samples/langchain_quick_start.ipynb +++ b/samples/langchain_quick_start.ipynb @@ -1016,4 +1016,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git a/src/langchain_google_cloud_sql_pg/engine.py b/src/langchain_google_cloud_sql_pg/engine.py index afb3a659..eaa854ee 100644 --- a/src/langchain_google_cloud_sql_pg/engine.py +++ b/src/langchain_google_cloud_sql_pg/engine.py @@ -17,12 +17,12 @@ import asyncio from dataclasses import dataclass from threading import Thread -from typing import TYPE_CHECKING, Awaitable, Dict, List, Optional, TypeVar +from typing import TYPE_CHECKING, Awaitable, Dict, List, Optional, TypeVar, Union import aiohttp import google.auth # type: ignore import google.auth.transport.requests # type: ignore -from google.cloud.sql.connector import Connector +from google.cloud.sql.connector import Connector, IPTypes from sqlalchemy import MetaData, Table, text from sqlalchemy.exc import InvalidRequestError from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine @@ -111,6 +111,7 @@ def from_instance( database: str, user: Optional[str] = None, password: Optional[str] = None, + ip_type: Union[str, IPTypes] = IPTypes.PUBLIC, ) -> PostgresEngine: # Running a loop in a background thread allows us to support # async methods from non-async environments @@ -122,6 +123,7 @@ def from_instance( region, instance, database, + ip_type, user, password, loop=loop, @@ -136,6 +138,7 @@ async def _create( region: str, instance: str, database: str, + ip_type: Union[str, IPTypes], user: Optional[str] = None, password: Optional[str] = None, loop: Optional[asyncio.AbstractEventLoop] = None, @@ -151,6 +154,7 @@ async def _create( cls._connector = Connector( loop=asyncio.get_event_loop(), user_agent=USER_AGENT ) + # if user and password are given, use basic auth if user and password: enable_iam_auth = False @@ -173,6 +177,7 @@ async def getconn() -> asyncpg.Connection: password=password, db=database, enable_iam_auth=enable_iam_auth, + ip_type=ip_type, ) return conn @@ -191,12 +196,14 @@ async def afrom_instance( database: str, user: Optional[str] = None, password: Optional[str] = None, + ip_type: Union[str, IPTypes] = IPTypes.PUBLIC, ) -> PostgresEngine: return await cls._create( project_id, region, instance, database, + ip_type, user, password, ) diff --git a/src/langchain_google_cloud_sql_pg/version.py b/src/langchain_google_cloud_sql_pg/version.py index 70aace1b..47d56082 100644 --- a/src/langchain_google_cloud_sql_pg/version.py +++ b/src/langchain_google_cloud_sql_pg/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.0" +__version__ = "0.4.0"