Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
am-kinetica committed Dec 7, 2023
2 parents 519036a + db6bf8b commit 41e5ace
Show file tree
Hide file tree
Showing 49 changed files with 203 additions and 12,745 deletions.
29 changes: 26 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ It's essential that we maintain great documentation and testing. If you:
- Update any affected example notebooks and documentation. These live in `docs`.
- Update unit and integration tests when relevant.
- Add a feature
- Add a demo notebook in `docs/modules`.
- Add a demo notebook in `docs/docs/`.
- Add unit and integration tests.

We are a small, progress-oriented team. If there's something you'd like to add or change, opening a pull request is the
Expand Down Expand Up @@ -72,9 +72,10 @@ tell Poetry to use the virtualenv python environment (`poetry config virtualenvs

### Core vs. Experimental

This repository contains two separate projects:
This repository contains three separate projects:
- `langchain`: core langchain code, abstractions, and use cases.
- `langchain.experimental`: see the [Experimental README](https://github.com/langchain-ai/langchain/tree/master/libs/experimental/README.md) for more information.
- `langchain_core`: contain interfaces for key abstractions as well as logic for combining them in chains (LCEL).
- `langchain_experimental`: see the [Experimental README](https://github.com/langchain-ai/langchain/tree/master/libs/experimental/README.md) for more information.

Each of these has its own development environment. Docs are run from the top-level makefile, but development
is split across separate test & release flows.
Expand Down Expand Up @@ -128,6 +129,24 @@ make docker_tests

There are also [integration tests and code-coverage](https://github.com/langchain-ai/langchain/tree/master/libs/langchain/tests/README.md) available.

### Only develop langchain_core or langchain_experimental

If you are only developing `langchain_core` or `langchain_experimental`, you can simply install the dependencies for the respective projects and run tests:

```bash
cd libs/core
poetry install --with test
make test
```

Or:

```bash
cd libs/experimental
poetry install --with test
make test
```

### Formatting and Linting

Run these locally before submitting a PR; the CI system will check also.
Expand Down Expand Up @@ -214,6 +233,10 @@ ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogy

Langchain relies heavily on optional dependencies to keep the Langchain package lightweight.

You only need to add a new dependency if a **unit test** relies on the package.
If your package is only required for **integration tests**, then you can skip these
steps and leave all pyproject.toml and poetry.lock files alone.

If you're adding a new dependency to Langchain, assume that it will be an optional dependency, and
that most users won't have it installed.

Expand Down
45 changes: 45 additions & 0 deletions .github/scripts/check_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
import sys

ALL_DIRS = {
"libs/core",
"libs/langchain",
"libs/experimental",
}

if __name__ == "__main__":
files = sys.argv[1:]
dirs_to_run = set()

for file in files:
if any(
file.startswith(dir_)
for dir_ in (
".github/workflows",
".github/tools",
".github/actions",
"libs/core",
".github/scripts/check_diff.py",
)
):
dirs_to_run = ALL_DIRS
break
elif "libs/community" in file:
dirs_to_run.update(
("libs/community", "libs/langchain", "libs/experimental")
)
elif "libs/partners" in file:
partner_dir = file.split("/")[2]
dirs_to_run.update(
(f"libs/partners/{partner_dir}", "libs/langchain", "libs/experimental")
)
elif "libs/langchain" in file:
dirs_to_run.update(("libs/langchain", "libs/experimental"))
elif "libs/experimental" in file:
dirs_to_run.add("libs/experimental")
elif file.startswith("libs/"):
dirs_to_run = ALL_DIRS
break
else:
pass
print(json.dumps(list(dirs_to_run)))
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---
name: libs/langchain CI
name: langchain CI

on:
push:
branches: [ master ]
pull_request:
paths:
- '.github/actions/poetry_setup/action.yml'
- '.github/tools/**'
- '.github/workflows/_lint.yml'
- '.github/workflows/_test.yml'
- '.github/workflows/_pydantic_compatibility.yml'
- '.github/workflows/langchain_ci.yml'
- 'libs/*'
- 'libs/langchain/**'
workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI
workflow_call:
inputs:
working-directory:
required: true
type: string
description: "From which folder this pipeline executes"
workflow_dispatch:
inputs:
working-directory:
required: true
type: choice
default: 'libs/langchain'
options:
- libs/langchain
- libs/core
- libs/experimental


# If another push to the same PR or branch happens while this workflow is still running,
# cancel the earlier run in favor of the next run.
Expand All @@ -23,55 +27,52 @@ on:
# a limited number of job runners to be active at the same time, so it's better to cancel
# pointless jobs early so that more useful jobs can run sooner.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.working-directory }}
cancel-in-progress: true

env:
POETRY_VERSION: "1.6.1"
WORKDIR: "libs/langchain"

jobs:
lint:
uses:
./.github/workflows/_lint.yml
uses: ./.github/workflows/_lint.yml
with:
working-directory: libs/langchain
working-directory: ${{ inputs.working-directory }}
secrets: inherit

test:
uses:
./.github/workflows/_test.yml
uses: ./.github/workflows/_test.yml
with:
working-directory: libs/langchain
working-directory: ${{ inputs.working-directory }}
secrets: inherit

compile-integration-tests:
uses:
./.github/workflows/_compile_integration_test.yml
uses: ./.github/workflows/_compile_integration_test.yml
if: ${{ inputs.working-directory != 'libs/core' }}
with:
working-directory: libs/langchain
working-directory: ${{ inputs.working-directory }}
secrets: inherit

pydantic-compatibility:
uses:
./.github/workflows/_pydantic_compatibility.yml
uses: ./.github/workflows/_pydantic_compatibility.yml
with:
working-directory: libs/langchain
working-directory: ${{ inputs.working-directory }}
secrets: inherit

extended-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKDIR }}
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
if: ${{ inputs.working-directory == 'libs/langchain' }}
name: Python ${{ matrix.python-version }} extended tests
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v4

Expand All @@ -80,7 +81,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: libs/langchain
working-directory: ${{ inputs.working-directory }}
cache-key: extended

- name: Install dependencies
Expand All @@ -89,6 +90,11 @@ jobs:
echo "Running extended tests, installing dependencies with poetry..."
poetry install -E extended_testing
- name: Install langchain core editable
shell: bash
run: |
poetry run pip install -e ../core
- name: Run extended tests
run: make extended_tests

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ jobs:
# It doesn't matter how you change it, any change will cause a cache-bust.
working-directory: ${{ inputs.working-directory }}
run: |
poetry install --with dev,lint,test,typing
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: |
pip install -e "$LANGCHAIN_LOCATION"
poetry run pip install -e "$LANGCHAIN_LOCATION"
- name: Get .mypy_cache to speed up mypy
uses: actions/cache@v3
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/_pydantic_compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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.6.1"
Expand Down Expand Up @@ -40,6 +44,14 @@ jobs:
shell: bash
run: poetry install

- 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: Install the opposite major version of pydantic
# If normal tests use pydantic v1, here we'll use v2, and vice versa.
shell: bash
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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.6.1"
Expand Down Expand Up @@ -38,11 +42,20 @@ jobs:

- name: Install dependencies
shell: bash
run: poetry install
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: make test
run: |
make test
- name: Ensure the tests did not create any additional files
shell: bash
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/check_diffs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Check library diffs

on:
push:
branches: [master]
pull_request:
paths:
- ".github/actions/**"
- ".github/tools/**"
- ".github/workflows/**"
- "libs/**"

# If another push to the same PR or branch happens while this workflow is still running,
# cancel the earlier run in favor of the next run.
#
# There's no point in testing an outdated version of the code. GitHub only allows
# a limited number of job runners to be active at the same time, so it's better to cancel
# pointless jobs early so that more useful jobs can run sooner.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- id: files
uses: Ana06/[email protected]
- id: set-matrix
run: echo "dirs-to-run=$(python .github/scripts/check_diff.py ${{ steps.files.outputs.all }})" >> $GITHUB_OUTPUT
outputs:
dirs-to-run: ${{ steps.set-matrix.outputs.dirs-to-run }}
ci:
needs: [ build ]
strategy:
matrix:
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run) }}
uses: ./.github/workflows/_all_ci.yml
with:
working-directory: ${{ matrix.working-directory }}


Loading

0 comments on commit 41e5ace

Please sign in to comment.