Skip to content

Commit

Permalink
init pkg (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Mar 1, 2024
1 parent a355a20 commit a813258
Show file tree
Hide file tree
Showing 32 changed files with 5,553 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Dict

LIB_DIRS = ["libs/{lib}"]
LIB_DIRS = ["libs/astradb"]

if __name__ == "__main__":
files = sys.argv[1:]
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
required: true
type: string
description: "From which folder this pipeline executes"
langchain-location:
required: false
type: string
description: "Relative path to the langchain library folder"

env:
POETRY_VERSION: "1.7.1"
Expand Down Expand Up @@ -71,14 +67,6 @@ jobs:
run: |
poetry install --with lint,typing
- name: Install langchain editable
working-directory: ${{ inputs.working-directory }}
if: ${{ inputs.langchain-location }}
env:
LANGCHAIN_LOCATION: ${{ inputs.langchain-location }}
run: |
poetry run pip install -e "$LANGCHAIN_LOCATION"
- name: Get .mypy_cache to speed up mypy
uses: actions/cache@v4
env:
Expand All @@ -93,22 +81,7 @@ jobs:
working-directory: ${{ inputs.working-directory }}
run: |
make lint_package
- name: Install unit test dependencies
# Also installs dev/lint/test/typing dependencies, to ensure we have
# type hints for as many of our libraries as possible.
# This helps catch errors that require dependencies to be spotted, for example:
# https://github.com/langchain-ai/langchain/pull/10249/files#diff-935185cd488d015f026dcd9e19616ff62863e8cde8c0bee70318d3ccbca98341
#
# If you change this configuration, make sure to change the `cache-key`
# in the `poetry_setup` action above to stop using the old cache.
# It doesn't matter how you change it, any change will cause a cache-bust.
if: ${{ ! startsWith(inputs.working-directory, 'libs/partners/') }}
working-directory: ${{ inputs.working-directory }}
run: |
poetry install --with test
- name: Install unit+integration test dependencies
if: ${{ startsWith(inputs.working-directory, 'libs/partners/') }}
working-directory: ${{ inputs.working-directory }}
run: |
poetry install --with test,test_integration
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
working-directory:
required: true
type: string
default: 'libs/vertexai'
default: 'libs/astradb'

env:
PYTHON_VERSION: "3.11"
Expand Down Expand Up @@ -158,7 +158,9 @@ jobs:

- name: Run integration tests
env:
PARTNER_API_KEY: ${{ secrets.PARTNER_API_KEY }}
ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }}
ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }}
ASTRA_DB_KEYSPACE: ${{ secrets.ASTRA_DB_KEYSPACE }}
run: make integration_tests
working-directory: ${{ inputs.working-directory }}

Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
required: true
type: string
description: "From which folder this pipeline executes"
langchain-location:
required: false
type: string
description: "Relative path to the langchain library folder"

env:
POETRY_VERSION: "1.7.1"
Expand Down Expand Up @@ -44,14 +40,6 @@ jobs:
shell: bash
run: poetry install --with test

- name: Install langchain editable
working-directory: ${{ inputs.working-directory }}
if: ${{ inputs.langchain-location }}
env:
LANGCHAIN_LOCATION: ${{ inputs.langchain-location }}
run: |
poetry run pip install -e "$LANGCHAIN_LOCATION"
- name: Run core tests
shell: bash
run: |
Expand Down
24 changes: 2 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
# 🦜️🔗 LangChain {partner}

This repository contains {n} packages with {partner} integrations with LangChain:
This repository contains 1 package with Datastax integrations with LangChain:

- [langchain-{package}](https://pypi.org/project/langchain-{package}/) integrates [{product}}]({product_link}).
{- ... if more packages}

## Initial Repo Checklist (Remove this section after completing)

This setup assumes that the partner package is already split. For those instructions,
see [these docs](https://python.langchain.com/docs/contributing/integrations#partner-packages).

- [ ] Fill out the readme above (for folks that follow pypi link)
- [ ] Copy package into /libs folder
- [ ] Update these fields in /libs/*/pyproject.toml

- `tool.poetry.repository`
- `tool.poetry.urls["Source Code"]`

- [ ] Add integration testing secrets in Github (ask Erick for help)
- [ ] Add secrets as env vars in .github/workflows/_release.yml
- [ ] Configure `LIB_DIRS` in .github/scripts/check_diff.py
- [ ] Add partner collaborators in Github (ask Erick for help)
- [ ] Add new repo to test-pypi and pypi trusted publishing (ask Erick for help)
- [ ] Populate .github/workflows/_release.yml with `on.workflow_dispatch.inputs.working-directory.default`
- [langchain-astradb](https://pypi.org/project/langchain-astradb/) integrates [AstraDB](https://www.datastax.com/products/datastax-astra).
5 changes: 5 additions & 0 deletions libs/astradb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__
*.env
.mypy_cache
.ruff_cache
.pytest_cache
21 changes: 21 additions & 0 deletions libs/astradb/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 LangChain, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions libs/astradb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
SHELL := /bin/bash
.PHONY: all format lint test tests integration_test integration_tests spell_check help

# Default target executed when no arguments are given to make.
all: help

# Define a variable for the test file path.
TEST_FILE ?= tests/unit_tests/
INTEGRATION_TEST_FILE ?= tests/integration_tests/

test:
poetry run pytest $(TEST_FILE)

tests:
poetry run pytest $(TEST_FILE)

integration_test:
poetry run pytest $(INTEGRATION_TEST_FILE)

integration_tests:
poetry run pytest $(INTEGRATION_TEST_FILE)

######################
# LINTING AND FORMATTING
######################

# Define a variable for Python and notebook files.
PYTHON_FILES=.
MYPY_CACHE=.mypy_cache
lint format: PYTHON_FILES=.
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/astradb --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
lint_package: PYTHON_FILES=langchain_astradb
lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test

lint lint_diff lint_package lint_tests:
poetry run ruff .
poetry run ruff format $(PYTHON_FILES) --diff
poetry run ruff --select I $(PYTHON_FILES)
mkdir -p $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)

format format_diff:
poetry run ruff format $(PYTHON_FILES)
poetry run ruff --select I --fix $(PYTHON_FILES)

spell_check:
poetry run codespell --toml pyproject.toml

spell_fix:
poetry run codespell --toml pyproject.toml -w

check_imports: $(shell find langchain_astradb -name '*.py')
poetry run python ./scripts/check_imports.py $^

######################
# HELP
######################

help:
@echo '----'
@echo 'check_imports - check imports'
@echo 'format - run code formatters'
@echo 'lint - run linters'
@echo 'test - run unit tests'
@echo 'tests - run unit tests'
@echo 'test TEST_FILE=<test_file> - run all tests in file'
68 changes: 68 additions & 0 deletions libs/astradb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# langchain-astradb

This package contains the LangChain integrations for using DataStax Astra DB.

> DataStax [Astra DB](https://docs.datastax.com/en/astra/home/astra.html) is a serverless vector-capable database built on Apache Cassandra® and made conveniently available
> through an easy-to-use JSON API.
_**Note.** For a short transitional period, only some of the Astra DB integration classes are contained in this package (the remaining ones being still in `langchain-community`). In a short while, and surely by version 0.2 of LangChain, all of the Astra DB support will be removed from `langchain-community` and included in this package._

## Installation and Setup

Installation of this partner package:

```bash
pip install langchain-astradb
```

## Integrations overview

### Vector Store

```python
from langchain_astradb import AstraDBVectorStore

my_store = AstraDBVectorStore(
embedding=my_embeddings,
collection_name="my_store",
api_endpoint="https://...",
token="AstraCS:...",
)
```

### Chat message history

```python
from langchain_astradb import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint="...",
token="...",
)
```

### Store

```python
from langchain_astradb import AstraDBStore
store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)
```

### Byte Store

```python
from langchain_astradb import AstraDBByteStore
store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)
```

## Reference

See the [LangChain docs page](https://python.langchain.com/docs/integrations/providers/astradb) for a more detailed listing.
10 changes: 10 additions & 0 deletions libs/astradb/langchain_astradb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from langchain_astradb.chat_message_histories import AstraDBChatMessageHistory
from langchain_astradb.storage import AstraDBByteStore, AstraDBStore
from langchain_astradb.vectorstores import AstraDBVectorStore

__all__ = [
"AstraDBByteStore",
"AstraDBStore",
"AstraDBChatMessageHistory",
"AstraDBVectorStore",
]
Loading

0 comments on commit a813258

Please sign in to comment.