diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 0cc77569..531cae20 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,9 +1,4 @@ -// Dependency Update Configuration -// -// See https://docs.renovatebot.com/configuration-options/ -// See https://json5.org/ for JSON5 syntax { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base", // https://docs.renovatebot.com/presets-config/#configbase ":semanticCommits", // https://docs.renovatebot.com/presets-default/#semanticcommits @@ -13,7 +8,7 @@ ":prConcurrentLimitNone", // View complete backlog as PRs. https://docs.renovatebot.com/presets-default/#prconcurrentlimitnone ":prNotPending", // https://docs.renovatebot.com/presets-default/#prnotpending ":prHourlyLimitNone", // https://docs.renovatebot.com/presets-default/#prhourlylimitnone - "docker:enableMajor", // https://docs.renovatebot.com/presets-docker/#dockerenablemajor + ":preserveSemverRanges", ], // Synchronized with a 2 week sprint cycle and outside business hours. @@ -35,25 +30,8 @@ "dependencyDashboardLabels": [ "type: process", ], - - "constraints": { - "python": "3.11" - }, - - "pip_requirements": { - "fileMatch": ["requirements-test.txt"] - }, "packageRules": [ - // Tooling & Runtime behaviors. - { - // Covers Dockerfiles, cloudbuild.yaml, and other docker-based tools. - "groupName": "Docker Runtimes", - "matchDatasources": ["docker"], - // TODO: Uncomment if your Dockerfiles are not included in samples. - // Increases build repeatability, image cache use, and supply chain security. - // "pinDigests": true, - }, { "groupName": "GitHub Actions", "matchManagers": ["github-actions"], diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7358c119..7b866f5b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,6 +34,23 @@ jobs: if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" steps: + - name: Remove PR label + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.removeLabel({ + name: 'tests: run', + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + } catch (e) { + console.log('Failed to remove label. Another job may have already removed it!'); + } + - name: Checkout Repository uses: actions/checkout@v3 @@ -43,6 +60,9 @@ jobs: python-version: "3.11" - name: Install requirements + run: pip install -r requirements.txt + + - name: Install module (and test requirements) run: pip install -e .[test] - name: Run linters diff --git a/.gitignore b/.gitignore index d083ea1d..3c0f60e6 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ docs.metadata # Virtual environment env/ venv/ +.python-version # Test logs coverage.xml diff --git a/README.md b/README.md index b5e72f76..0b5f0bca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Spanner for LangChain -*Description* +This package contains the [LangChain][langchain] integrations for Spanner. > **🧪 Preview:** This feature is covered by the Pre-GA Offerings Terms of the Google Cloud Terms of Service. Please note that pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages) @@ -33,12 +33,42 @@ source /bin/activate /bin/pip install langchain-google-spanner ``` -## Usage +## Document Loader Usage + +Use a document loader to load data as LangChain `Document`s. + +```python +from langchain_google_spanner import SpannerLoader + + +loader = SpannerLoader( + instance_id="my-instance", + database_id="my-database", + query="SELECT * from my_table_name" +) +docs = loader.lazy_load() +``` + +See the full [Document Loader][loader] tutorial. + +## Chat Message History Usage + +Use `ChatMessageHistory` to store messages and provide conversation history to LLMs. ```python -from langchain_google_spanner import SpannerVectorstore, SpannerLoader, SpannerChatMessageHistory +from langchain_google_spanner import SpannerChatMessageHistory + + +history = SpannerChatMessageHistory( + instance_id="my-instance", + database_id="my-database", + table_name="my_table_name", + session_id="my-session_id" +) ``` +See the full [Chat Message History][history] tutorial. + ## Contributing Contributions to this library are always welcome and highly encouraged. @@ -61,4 +91,7 @@ This is not an officially supported Google product. [billing]: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project [api]: https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com [auth]: https://googleapis.dev/python/google-api-core/latest/auth.html -[venv]: https://virtualenv.pypa.io/en/latest/ \ No newline at end of file +[venv]: https://virtualenv.pypa.io/en/latest/ +[loader]: ./docs/document_loader.ipynb +[history]: ./docs/chat_message_history.ipynb +[langchain]: https://github.com/langchain-ai/langchain diff --git a/integration.cloudbuild.yaml b/integration.cloudbuild.yaml index bc991c43..1797b270 100644 --- a/integration.cloudbuild.yaml +++ b/integration.cloudbuild.yaml @@ -14,6 +14,11 @@ steps: - id: Install dependencies + name: python:3.11 + entrypoint: pip + args: ["install", "--user", "-r", "requirements.txt"] + + - id: Install module (and test requirements) name: python:3.11 entrypoint: pip args: ["install", ".[test]", "--user"] diff --git a/pyproject.toml b/pyproject.toml index 9b40ed2c..db8f9718 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,9 +5,13 @@ description = "LangChain integrations for Google Cloud Spanner" readme = "README.md" license = {file = "LICENSE"} requires-python = ">=3.8" +authors = [ + {name = "Google LLC", email = "googleapis-packages@google.com"} +] dependencies = [ - "langchain==0.1.1", - "google-cloud-spanner==3.41.0" + "langchain-core>=0.1.25, <1.0.0", + "langchain-community>=0.0.18, <1.0.0", + "google-cloud-spanner>=3.41.0, <4.0.0" ] [tool.setuptools.dynamic] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..3c74edf4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +langchain-core==0.1.25 +langchain-community==0.0.21 +google-cloud-spanner==3.42.0 diff --git a/src/langchain_google_spanner/py.typed b/src/langchain_google_spanner/py.typed new file mode 100644 index 00000000..e69de29b