mirror of
https://github.com/langchain-ai/langchain-experimental.git
synced 2026-07-01 13:20:51 -04:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f10d5c3247 | |||
| ddd4ea4245 | |||
| dd5731be29 | |||
| bfc545a505 | |||
| 676f118791 | |||
| 157b05ebd9 | |||
| 7a0deecaa2 | |||
| db30b0ffeb | |||
| ee2ae5c063 | |||
| d4833f0c22 | |||
| a6c66481ee | |||
| 06e510c76f | |||
| d1f445dc7f | |||
| bee3035b9c | |||
| 5ec0c48b51 | |||
| 7b61894753 | |||
| 0029a2b44f | |||
| 5cdbf02e37 | |||
| a8cc3e678a |
@@ -1,93 +0,0 @@
|
||||
# An action for setting up poetry install with caching.
|
||||
# Using a custom action since the default action does not
|
||||
# take poetry install groups into account.
|
||||
# Action code from:
|
||||
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
|
||||
name: poetry-install-with-caching
|
||||
description: Poetry install with support for caching of dependency groups.
|
||||
|
||||
inputs:
|
||||
python-version:
|
||||
description: Python version, supporting MAJOR.MINOR only
|
||||
required: true
|
||||
|
||||
poetry-version:
|
||||
description: Poetry version
|
||||
required: true
|
||||
|
||||
cache-key:
|
||||
description: Cache key to use for manual handling of caching
|
||||
required: true
|
||||
|
||||
working-directory:
|
||||
description: Directory whose poetry.lock file should be cached
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/setup-python@v5
|
||||
name: Setup python ${{ inputs.python-version }}
|
||||
id: setup-python
|
||||
with:
|
||||
python-version: ${{ inputs.python-version }}
|
||||
|
||||
- uses: actions/cache@v4
|
||||
id: cache-bin-poetry
|
||||
name: Cache Poetry binary - Python ${{ inputs.python-version }}
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
|
||||
with:
|
||||
path: |
|
||||
/opt/pipx/venvs/poetry
|
||||
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
|
||||
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
|
||||
|
||||
- name: Refresh shell hashtable and fixup softlinks
|
||||
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
|
||||
shell: bash
|
||||
env:
|
||||
POETRY_VERSION: ${{ inputs.poetry-version }}
|
||||
PYTHON_VERSION: ${{ inputs.python-version }}
|
||||
run: |
|
||||
set -eux
|
||||
|
||||
# Refresh the shell hashtable, to ensure correct `which` output.
|
||||
hash -r
|
||||
|
||||
# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
|
||||
# Delete and recreate the softlinks pipx expects to have.
|
||||
rm /opt/pipx/venvs/poetry/bin/python
|
||||
cd /opt/pipx/venvs/poetry/bin
|
||||
ln -s "$(which "python$PYTHON_VERSION")" python
|
||||
chmod +x python
|
||||
cd /opt/pipx_bin/
|
||||
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
|
||||
chmod +x poetry
|
||||
|
||||
# Ensure everything got set up correctly.
|
||||
/opt/pipx/venvs/poetry/bin/python --version
|
||||
/opt/pipx_bin/poetry --version
|
||||
|
||||
- name: Install poetry
|
||||
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
POETRY_VERSION: ${{ inputs.poetry-version }}
|
||||
PYTHON_VERSION: ${{ inputs.python-version }}
|
||||
# Install poetry using the python version installed by setup-python step.
|
||||
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
|
||||
|
||||
- name: Restore pip and poetry cached dependencies
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
|
||||
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
|
||||
with:
|
||||
path: |
|
||||
~/.cache/pip
|
||||
~/.cache/pypoetry/virtualenvs
|
||||
~/.cache/pypoetry/cache
|
||||
~/.cache/pypoetry/artifacts
|
||||
${{ env.WORKDIR }}/.venv
|
||||
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/**/poetry.lock', env.WORKDIR)) }}
|
||||
@@ -0,0 +1,23 @@
|
||||
# TODO: https://docs.astral.sh/uv/guides/integration/github/#caching
|
||||
|
||||
name: uv-install
|
||||
description: Set up Python and uv
|
||||
|
||||
inputs:
|
||||
python-version:
|
||||
description: Python version, supporting MAJOR.MINOR only
|
||||
required: true
|
||||
|
||||
env:
|
||||
UV_VERSION: "0.5.25"
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install uv and set the python version
|
||||
uses: astral-sh/setup-uv@v5
|
||||
with:
|
||||
version: ${{ env.UV_VERSION }}
|
||||
python-version: ${{ inputs.python-version }}
|
||||
@@ -6,15 +6,20 @@ import re
|
||||
|
||||
MIN_VERSION_LIBS = ["langchain-core"]
|
||||
|
||||
SKIP_IF_PULL_REQUEST = ["langchain-core"]
|
||||
|
||||
|
||||
def get_min_version(version: str) -> str:
|
||||
# base regex for x.x.x with cases for rc/post/etc
|
||||
# valid strings: https://peps.python.org/pep-0440/#public-version-identifiers
|
||||
vstring = r"\d+(?:\.\d+){0,2}(?:(?:a|b|rc|\.post|\.dev)\d+)?"
|
||||
# case ^x.x.x
|
||||
_match = re.match(r"^\^(\d+(?:\.\d+){0,2})$", version)
|
||||
_match = re.match(f"^\\^({vstring})$", version)
|
||||
if _match:
|
||||
return _match.group(1)
|
||||
|
||||
# case >=x.x.x,<y.y.y
|
||||
_match = re.match(r"^>=(\d+(?:\.\d+){0,2}),<(\d+(?:\.\d+){0,2})$", version)
|
||||
_match = re.match(f"^>=({vstring}),<({vstring})$", version)
|
||||
if _match:
|
||||
_min = _match.group(1)
|
||||
_max = _match.group(2)
|
||||
@@ -22,31 +27,37 @@ def get_min_version(version: str) -> str:
|
||||
return _min
|
||||
|
||||
# case x.x.x
|
||||
_match = re.match(r"^(\d+(?:\.\d+){0,2})$", version)
|
||||
_match = re.match(f"^({vstring})$", version)
|
||||
if _match:
|
||||
return _match.group(1)
|
||||
|
||||
raise ValueError(f"Unrecognized version format: {version}")
|
||||
|
||||
|
||||
def get_min_version_from_toml(toml_path: str):
|
||||
def get_min_version_from_toml(toml_path: str, versions_for: str):
|
||||
# Parse the TOML file
|
||||
with open(toml_path, "rb") as file:
|
||||
toml_data = tomllib.load(file)
|
||||
|
||||
# Get the dependencies from tool.poetry.dependencies
|
||||
dependencies = toml_data["tool"]["poetry"]["dependencies"]
|
||||
dependencies = toml_data["project"]["dependencies"]
|
||||
|
||||
# Initialize a dictionary to store the minimum versions
|
||||
min_versions = {}
|
||||
|
||||
# Iterate over the libs in MIN_VERSION_LIBS
|
||||
for lib in MIN_VERSION_LIBS:
|
||||
if versions_for == "pull_request" and lib in SKIP_IF_PULL_REQUEST:
|
||||
# some libs only get checked on release because of simultaneous
|
||||
# changes
|
||||
continue
|
||||
# Check if the lib is present in the dependencies
|
||||
if lib in dependencies:
|
||||
# Get the version string
|
||||
version_string = dependencies[lib]
|
||||
|
||||
if isinstance(version_string, dict):
|
||||
version_string = version_string["version"]
|
||||
|
||||
# Use parse_version to get the minimum supported version from version_string
|
||||
min_version = get_min_version(version_string)
|
||||
|
||||
@@ -56,10 +67,13 @@ def get_min_version_from_toml(toml_path: str):
|
||||
return min_versions
|
||||
|
||||
|
||||
# Get the TOML file path from the command line argument
|
||||
toml_file = sys.argv[1]
|
||||
if __name__ == "__main__":
|
||||
# Get the TOML file path from the command line argument
|
||||
toml_file = sys.argv[1]
|
||||
versions_for = sys.argv[2]
|
||||
assert versions_for in ["release", "pull_request"]
|
||||
|
||||
# Call the function to get the minimum versions
|
||||
min_versions = get_min_version_from_toml(toml_file)
|
||||
# Call the function to get the minimum versions
|
||||
min_versions = get_min_version_from_toml(toml_file, versions_for)
|
||||
|
||||
print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))
|
||||
print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))
|
||||
|
||||
@@ -8,8 +8,8 @@ on:
|
||||
type: string
|
||||
description: "From which folder this pipeline executes"
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.7.1"
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -20,29 +20,26 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
python-version:
|
||||
- "3.8"
|
||||
- "3.9"
|
||||
- "3.10"
|
||||
- "3.11"
|
||||
name: "poetry run pytest -m compile tests/integration_tests #${{ matrix.python-version }}"
|
||||
- "3.12"
|
||||
- "3.13"
|
||||
name: "uv run pytest -m compile tests/integration_tests #${{ matrix.python-version }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python ${{ matrix.python-version }} + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: compile-integration
|
||||
|
||||
- name: Install integration dependencies
|
||||
shell: bash
|
||||
run: poetry install --with=test_integration,test
|
||||
run: uv sync --group test --group test_integration
|
||||
|
||||
- name: Check integration tests compile
|
||||
shell: bash
|
||||
run: poetry run pytest -m compile tests/integration_tests
|
||||
run: uv run pytest -m compile tests/integration_tests
|
||||
|
||||
- name: Ensure the tests did not create any additional files
|
||||
shell: bash
|
||||
|
||||
@@ -8,8 +8,10 @@ on:
|
||||
type: string
|
||||
description: "From which folder this pipeline executes"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.7.1"
|
||||
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
|
||||
|
||||
# This env var allows us to get inline annotations when ruff has complaints.
|
||||
@@ -29,30 +31,15 @@ jobs:
|
||||
# Starting new jobs is also relatively slow,
|
||||
# so linting on fewer versions makes CI faster.
|
||||
python-version:
|
||||
- "3.8"
|
||||
- "3.11"
|
||||
- "3.10"
|
||||
- "3.13"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python ${{ matrix.python-version }} + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: lint-with-extras
|
||||
|
||||
- name: Check Poetry File
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
run: |
|
||||
poetry check
|
||||
|
||||
- name: Check lock file
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
run: |
|
||||
poetry lock --check
|
||||
|
||||
- name: Install dependencies
|
||||
# Also installs dev/lint/test/typing dependencies, to ensure we have
|
||||
@@ -65,17 +52,7 @@ 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 lint,typing
|
||||
|
||||
- name: Get .mypy_cache to speed up mypy
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2"
|
||||
with:
|
||||
path: |
|
||||
${{ env.WORKDIR }}/.mypy_cache
|
||||
key: mypy-lint-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', inputs.working-directory)) }}
|
||||
|
||||
uv sync --group lint --group typing
|
||||
|
||||
- name: Analysing the code with our lint
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
@@ -85,16 +62,7 @@ jobs:
|
||||
- name: Install unit+integration test dependencies
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
run: |
|
||||
poetry install --with test,test_integration
|
||||
|
||||
- name: Get .mypy_cache_test to speed up mypy
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2"
|
||||
with:
|
||||
path: |
|
||||
${{ env.WORKDIR }}/.mypy_cache_test
|
||||
key: mypy-test-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', inputs.working-directory)) }}
|
||||
uv sync --group test --group test_integration
|
||||
|
||||
- name: Analysing the code with our lint
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
@@ -13,14 +13,21 @@ on:
|
||||
required: true
|
||||
type: string
|
||||
default: 'libs/experimental'
|
||||
dangerous-nonmaster-release:
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
description: "Release from a non-master branch (danger!)"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
PYTHON_VERSION: "3.11"
|
||||
POETRY_VERSION: "1.7.1"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref == 'refs/heads/main' || inputs.dangerous-nonmaster-release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
outputs:
|
||||
@@ -30,13 +37,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: release
|
||||
|
||||
# We want to keep this build stage *separate* from the release stage,
|
||||
# so that there's no sharing of permissions between them.
|
||||
@@ -50,7 +54,7 @@ jobs:
|
||||
# > from the publish job.
|
||||
# https://github.com/pypa/gh-action-pypi-publish#non-goals
|
||||
- name: Build project for distribution
|
||||
run: poetry build
|
||||
run: uv build
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
- name: Upload build
|
||||
@@ -58,23 +62,33 @@ jobs:
|
||||
with:
|
||||
name: dist
|
||||
path: ${{ inputs.working-directory }}/dist/
|
||||
|
||||
|
||||
- name: Check Version
|
||||
id: check-version
|
||||
shell: bash
|
||||
shell: python
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
run: |
|
||||
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
|
||||
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
|
||||
import os
|
||||
import tomllib
|
||||
with open("pyproject.toml", "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
pkg_name = data["project"]["name"]
|
||||
version = data["project"]["version"]
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
||||
f.write(f"pkg-name={pkg_name}\n")
|
||||
f.write(f"version={version}\n")
|
||||
|
||||
test-pypi-publish:
|
||||
needs:
|
||||
- build
|
||||
uses:
|
||||
./.github/workflows/_test_release.yml
|
||||
permissions: write-all
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
with:
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
dangerous-nonmaster-release: ${{ inputs.dangerous-nonmaster-release }}
|
||||
secrets: inherit
|
||||
|
||||
pre-release-checks:
|
||||
@@ -98,14 +112,17 @@ jobs:
|
||||
# - The package is published, and it breaks on the missing dependency when
|
||||
# used in the real world.
|
||||
|
||||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
- name: Import published package
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: dist
|
||||
path: ${{ inputs.working-directory }}/dist/
|
||||
|
||||
- name: Import dist package
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
env:
|
||||
@@ -121,24 +138,18 @@ jobs:
|
||||
# - attempt install again after 5 seconds if it fails because there is
|
||||
# sometimes a delay in availability on test pypi
|
||||
run: |
|
||||
poetry run pip install \
|
||||
--extra-index-url https://test.pypi.org/simple/ \
|
||||
"$PKG_NAME==$VERSION" || \
|
||||
( \
|
||||
sleep 5 && \
|
||||
poetry run pip install \
|
||||
--extra-index-url https://test.pypi.org/simple/ \
|
||||
"$PKG_NAME==$VERSION" \
|
||||
)
|
||||
uv venv
|
||||
VIRTUAL_ENV=.venv uv pip install dist/*.whl
|
||||
|
||||
# Replace all dashes in the package name with underscores,
|
||||
# since that's how Python imports packages with dashes in the name.
|
||||
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"
|
||||
# also remove _official suffix
|
||||
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g | sed s/_official//g)"
|
||||
|
||||
poetry run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
|
||||
uv run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
|
||||
|
||||
- name: Import test dependencies
|
||||
run: poetry install --with test,test_integration
|
||||
run: uv sync --group test --group test_integration
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
# Overwrite the local version of the package with the test PyPI version.
|
||||
@@ -149,8 +160,9 @@ jobs:
|
||||
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
|
||||
VERSION: ${{ needs.build.outputs.version }}
|
||||
run: |
|
||||
poetry run pip install \
|
||||
uv pip install \
|
||||
--extra-index-url https://test.pypi.org/simple/ \
|
||||
--no-deps \
|
||||
"$PKG_NAME==$VERSION"
|
||||
|
||||
- name: Run unit tests
|
||||
@@ -161,8 +173,8 @@ jobs:
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
id: min-version
|
||||
run: |
|
||||
poetry run pip install packaging
|
||||
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml)"
|
||||
uv pip install packaging
|
||||
min_versions="$(uv run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml release)"
|
||||
echo "min-versions=$min_versions" >> "$GITHUB_OUTPUT"
|
||||
echo "min-versions=$min_versions"
|
||||
|
||||
@@ -171,7 +183,7 @@ jobs:
|
||||
env:
|
||||
MIN_VERSIONS: ${{ steps.min-version.outputs.min-versions }}
|
||||
run: |
|
||||
poetry run pip install $MIN_VERSIONS
|
||||
uv run pip install $MIN_VERSIONS
|
||||
make tests
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
@@ -196,13 +208,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: release
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
@@ -237,13 +246,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: release
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
@@ -258,4 +264,4 @@ jobs:
|
||||
draft: false
|
||||
generateReleaseNotes: true
|
||||
tag: ${{ inputs.working-directory }}/v${{ needs.build.outputs.version }}
|
||||
commit: main
|
||||
commit: ${{ github.sha }}
|
||||
|
||||
@@ -8,8 +8,8 @@ on:
|
||||
type: string
|
||||
description: "From which folder this pipeline executes"
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.7.1"
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -20,25 +20,22 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
python-version:
|
||||
- "3.8"
|
||||
- "3.9"
|
||||
- "3.10"
|
||||
- "3.11"
|
||||
- "3.12"
|
||||
- "3.13"
|
||||
name: "make test #${{ matrix.python-version }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python ${{ matrix.python-version }} + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: core
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: poetry install --with test
|
||||
run: uv sync --all-extras --dev
|
||||
|
||||
- name: Run core tests
|
||||
shell: bash
|
||||
|
||||
@@ -7,14 +7,21 @@ on:
|
||||
required: true
|
||||
type: string
|
||||
description: "From which folder this pipeline executes"
|
||||
dangerous-nonmaster-release:
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
description: "Release from a non-master branch (danger!)"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.7.1"
|
||||
PYTHON_VERSION: "3.10"
|
||||
PYTHON_VERSION: "3.11"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref == 'refs/heads/main' || inputs.dangerous-nonmaster-release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
outputs:
|
||||
@@ -24,13 +31,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
|
||||
uses: "./.github/actions/poetry_setup"
|
||||
- name: Set up Python + uv
|
||||
uses: "./.github/actions/uv_setup"
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
poetry-version: ${{ env.POETRY_VERSION }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
cache-key: release
|
||||
|
||||
# We want to keep this build stage *separate* from the release stage,
|
||||
# so that there's no sharing of permissions between them.
|
||||
@@ -44,7 +48,7 @@ jobs:
|
||||
# > from the publish job.
|
||||
# https://github.com/pypa/gh-action-pypi-publish#non-goals
|
||||
- name: Build project for distribution
|
||||
run: poetry build
|
||||
run: uv build
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
- name: Upload build
|
||||
@@ -55,11 +59,18 @@ jobs:
|
||||
|
||||
- name: Check Version
|
||||
id: check-version
|
||||
shell: bash
|
||||
shell: python
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
run: |
|
||||
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
|
||||
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
|
||||
import os
|
||||
import tomllib
|
||||
with open("pyproject.toml", "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
pkg_name = data["project"]["name"]
|
||||
version = data["project"]["version"]
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
||||
f.write(f"pkg-name={pkg_name}\n")
|
||||
f.write(f"version={version}\n")
|
||||
|
||||
publish:
|
||||
needs:
|
||||
|
||||
@@ -16,8 +16,8 @@ concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.7.1"
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
@@ -4,6 +4,9 @@ This repository contains 1 package with experimental features of LangChain:
|
||||
|
||||
- [langchain-experimental](https://pypi.org/project/langchain-experimental/)
|
||||
|
||||
> [!WARNING]
|
||||
> **`langchain-experimental` is being sunset.** See [#87](https://github.com/langchain-ai/langchain-experimental/issues/87) for details. Thank you to everyone who has contributed ideas, prototypes, fixes, reviews, and maintenance over the years.
|
||||
|
||||
> [!WARNING]
|
||||
> Portions of the code in this package may be dangerous if not properly deployed
|
||||
> in a sandboxed environment. Please be wary of deploying experimental code
|
||||
|
||||
+13
-13
@@ -7,22 +7,22 @@ all: help
|
||||
TEST_FILE ?= tests/unit_tests/
|
||||
|
||||
test:
|
||||
poetry run pytest $(TEST_FILE)
|
||||
uv run --group test pytest $(TEST_FILE)
|
||||
|
||||
tests:
|
||||
poetry run pytest $(TEST_FILE)
|
||||
uv run --group test pytest $(TEST_FILE)
|
||||
|
||||
test_watch:
|
||||
poetry run ptw --now . -- tests/unit_tests
|
||||
uv run --group test ptw --now . -- tests/unit_tests
|
||||
|
||||
extended_tests:
|
||||
poetry run pytest --only-extended tests/unit_tests
|
||||
uv run --group test pytest --only-extended tests/unit_tests
|
||||
|
||||
integration_tests:
|
||||
poetry run pytest tests/integration_tests
|
||||
uv run --group test_integration pytest tests/integration_tests
|
||||
|
||||
check_imports: $(shell find langchain_experimental -name '*.py')
|
||||
poetry run python ./scripts/check_imports.py $^
|
||||
uv run python ./scripts/check_imports.py $^
|
||||
|
||||
|
||||
######################
|
||||
@@ -39,19 +39,19 @@ lint_tests: PYTHON_FILES=tests
|
||||
lint_tests: MYPY_CACHE=.mypy_cache_test
|
||||
|
||||
lint lint_diff lint_package lint_tests:
|
||||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check $(PYTHON_FILES)
|
||||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
|
||||
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
|
||||
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check $(PYTHON_FILES)
|
||||
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES) --diff
|
||||
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && uv run --all-groups mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
|
||||
|
||||
format format_diff:
|
||||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES)
|
||||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I --fix $(PYTHON_FILES)
|
||||
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES)
|
||||
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check --select I --fix $(PYTHON_FILES)
|
||||
|
||||
spell_check:
|
||||
poetry run codespell --toml pyproject.toml
|
||||
uv run --all-groups codespell --toml pyproject.toml
|
||||
|
||||
spell_fix:
|
||||
poetry run codespell --toml pyproject.toml -w
|
||||
uv run --all-groups codespell --toml pyproject.toml -w
|
||||
|
||||
######################
|
||||
# HELP
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
This package holds experimental LangChain code, intended for research and experimental
|
||||
uses.
|
||||
|
||||
> [!WARNING]
|
||||
> **`langchain-experimental` is being sunset.** See [#87](https://github.com/langchain-ai/langchain-experimental/issues/87) for details. Thank you to everyone who has contributed ideas, prototypes, fixes, reviews, and maintenance over the years.
|
||||
|
||||
> [!WARNING]
|
||||
> Portions of the code in this package may be dangerous if not properly deployed
|
||||
> in a sandboxed environment. Please be wary of deploying experimental code
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from importlib import metadata
|
||||
|
||||
try:
|
||||
@@ -6,3 +7,12 @@ except metadata.PackageNotFoundError:
|
||||
# Case where package metadata is not available.
|
||||
__version__ = ""
|
||||
del metadata # optional, avoids polluting the results of dir(__package__)
|
||||
|
||||
warnings.warn(
|
||||
"`langchain-experimental` is being sunset and is no longer actively "
|
||||
"maintained. See "
|
||||
"https://github.com/langchain-ai/langchain-experimental/issues/87 for "
|
||||
"details.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from langchain_experimental.agents.agent_toolkits.pandas.base import (
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain.agents.agent import AgentExecutor
|
||||
from langchain_classic.agents.agent import AgentExecutor
|
||||
from langchain_core.language_models import LanguageModelLike
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ def create_csv_agent(
|
||||
from langchain_experimental.agents import create_csv_agent
|
||||
|
||||
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
||||
agent_executor = create_pandas_dataframe_agent(
|
||||
agent_executor = create_csv_agent(
|
||||
llm,
|
||||
"titanic.csv",
|
||||
agent_type="openai-tools",
|
||||
|
||||
@@ -3,21 +3,21 @@
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Literal, Optional, Sequence, Union, cast
|
||||
|
||||
from langchain.agents import (
|
||||
from langchain_classic.agents import (
|
||||
AgentType,
|
||||
create_openai_tools_agent,
|
||||
create_react_agent,
|
||||
create_tool_calling_agent,
|
||||
)
|
||||
from langchain.agents.agent import (
|
||||
from langchain_classic.agents.agent import (
|
||||
AgentExecutor,
|
||||
BaseMultiActionAgent,
|
||||
BaseSingleActionAgent,
|
||||
RunnableAgent,
|
||||
RunnableMultiActionAgent,
|
||||
)
|
||||
from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS
|
||||
from langchain.agents.openai_functions_agent.base import (
|
||||
from langchain_classic.agents.mrkl.prompt import FORMAT_INSTRUCTIONS
|
||||
from langchain_classic.agents.openai_functions_agent.base import (
|
||||
OpenAIFunctionsAgent,
|
||||
create_openai_functions_agent,
|
||||
)
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from langchain.agents.agent import AgentExecutor, BaseSingleActionAgent
|
||||
from langchain.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
|
||||
from langchain.agents.types import AgentType
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.agents.agent import AgentExecutor, BaseSingleActionAgent
|
||||
from langchain_classic.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain_classic.agents.openai_functions_agent.base import OpenAIFunctionsAgent
|
||||
from langchain_classic.agents.types import AgentType
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.base import BaseCallbackManager
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import SystemMessage
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.agents.agent import AgentExecutor
|
||||
from langchain.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.agents.agent import AgentExecutor
|
||||
from langchain_classic.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.base import BaseCallbackManager
|
||||
from langchain_core.language_models import BaseLLM
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.agents.agent import AgentExecutor
|
||||
from langchain.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.agents.agent import AgentExecutor
|
||||
from langchain_classic.agents.mrkl.base import ZeroShotAgent
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.base import BaseCallbackManager
|
||||
from langchain_core.language_models import BaseLLM
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.memory import ChatMessageHistory
|
||||
from langchain.schema import (
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.memory import ChatMessageHistory
|
||||
from langchain_classic.schema import (
|
||||
BaseChatMessageHistory,
|
||||
Document,
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from langchain.memory.chat_memory import BaseChatMemory
|
||||
from langchain.memory.utils import get_prompt_input_key
|
||||
from langchain_classic.memory.chat_memory import BaseChatMemory
|
||||
from langchain_classic.memory.utils import get_prompt_input_key
|
||||
from langchain_core.vectorstores import VectorStoreRetriever
|
||||
from pydantic import Field
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from collections import deque
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.vectorstores import VectorStore
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import List
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_experimental.autonomous_agents.hugginggpt.repsonse_generator import (
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.callbacks.manager import Callbacks
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
+2
-2
@@ -63,9 +63,9 @@ class Task:
|
||||
if k == "image":
|
||||
new_args["image"] = load_image(v)
|
||||
if self.task in ["video_generator", "image_generator", "text_reader"]:
|
||||
self.product = self.tool(**new_args)
|
||||
self.product = self.tool.invoke(**new_args)
|
||||
else:
|
||||
self.result = self.tool(**new_args)
|
||||
self.result = self.tool.invoke(**new_args)
|
||||
except Exception as e:
|
||||
self.status = "failed"
|
||||
self.message = str(e)
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ import re
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.callbacks.manager import Callbacks
|
||||
from langchain_core.prompts.chat import (
|
||||
AIMessagePromptTemplate,
|
||||
|
||||
@@ -4,7 +4,7 @@ for Llama-2-chat, Llama-2-instruct and Vicuna models.
|
||||
|
||||
from typing import Any, List, Optional, cast
|
||||
|
||||
from langchain.schema import (
|
||||
from langchain_classic.schema import (
|
||||
AIMessage,
|
||||
BaseMessage,
|
||||
ChatGeneration,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from pydantic import model_validator
|
||||
|
||||
|
||||
@@ -82,13 +82,11 @@ class BaseModeration:
|
||||
if isinstance(message, HumanMessage):
|
||||
messages[self.chat_message_index] = HumanMessage(
|
||||
content=text,
|
||||
example=message.example,
|
||||
additional_kwargs=message.additional_kwargs,
|
||||
)
|
||||
if isinstance(message, AIMessage):
|
||||
messages[self.chat_message_index] = AIMessage(
|
||||
content=text,
|
||||
example=message.example,
|
||||
additional_kwargs=message.additional_kwargs,
|
||||
)
|
||||
return ChatPromptValue(messages=messages)
|
||||
|
||||
@@ -5,13 +5,13 @@ CPAL Chain and its subchains
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Type
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Type, cast
|
||||
|
||||
import pydantic
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.output_parsers import PydanticOutputParser
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.output_parsers import PydanticOutputParser
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.prompts.prompt import PromptTemplate
|
||||
|
||||
@@ -165,7 +165,8 @@ class CPALChain(_BaseStoryElementChain):
|
||||
causal_chain: Optional[CausalChain] = None
|
||||
intervention_chain: Optional[InterventionChain] = None
|
||||
query_chain: Optional[QueryChain] = None
|
||||
_story: StoryModel = pydantic.PrivateAttr(default=None) # TODO: change name ?
|
||||
# TODO: change name of _story?
|
||||
_story: Optional[StoryModel] = pydantic.PrivateAttr(default=None)
|
||||
|
||||
@classmethod
|
||||
def from_univariate_prompt(
|
||||
@@ -300,4 +301,4 @@ class CPALChain(_BaseStoryElementChain):
|
||||
>>> cpal_chain.draw(path="graph.svg")
|
||||
>>> SVG('graph.svg')
|
||||
"""
|
||||
self._story._networkx_wrapper.draw_graphviz(**kwargs)
|
||||
cast(StoryModel, self._story)._networkx_wrapper.draw_graphviz(**kwargs)
|
||||
|
||||
@@ -4,9 +4,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.schema import BasePromptTemplate
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.schema import BasePromptTemplate
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
|
||||
@@ -28,7 +28,7 @@ class FallacyChain(Chain):
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.llms import OpenAI
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_experimental.fallacy import FallacyChain
|
||||
from langchain_experimental.fallacy_removal.models import LogicalFallacy
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
@@ -3,10 +3,10 @@ import re
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains import LLMChain
|
||||
from langchain.retrievers import TimeWeightedVectorStoreRetriever
|
||||
from langchain.schema import BaseMemory, Document
|
||||
from langchain.utils import mock_now
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_classic.retrievers import TimeWeightedVectorStoreRetriever
|
||||
from langchain_classic.schema import BaseMemory, Document
|
||||
from langchain_classic.utils import mock_now
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from enum import Enum
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
import requests
|
||||
from langchain.utils import get_from_env
|
||||
from langchain_classic.utils import get_from_env
|
||||
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship
|
||||
from langchain_core.documents import Document
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ def optional_enum_field(
|
||||
enum=parsed_enum_values, # type: ignore[call-arg]
|
||||
description=f"{description}. Available options are {parsed_enum_values}",
|
||||
**field_kwargs,
|
||||
)
|
||||
) # type: ignore[call-overload]
|
||||
elif enum_values:
|
||||
return Field(
|
||||
...,
|
||||
|
||||
@@ -6,9 +6,9 @@ import logging
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.schema import BasePromptTemplate, OutputParserException
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.schema import BasePromptTemplate, OutputParserException
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from pydantic import ConfigDict, Field, model_validator
|
||||
@@ -25,7 +25,7 @@ class LLMBashChain(Chain):
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from langchain.chains import LLMBashChain
|
||||
from langchain_classic.chains import LLMBashChain
|
||||
from langchain_community.llms import OpenAI
|
||||
llm_bash = LLMBashChain.from_llm(OpenAI())
|
||||
"""
|
||||
|
||||
@@ -5,9 +5,9 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
CallbackManagerForChainRun,
|
||||
@@ -28,7 +28,7 @@ class LLMSymbolicMathChain(Chain):
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
from langchain.chains import LLMSymbolicMathChain
|
||||
from langchain_classic.chains import LLMSymbolicMathChain
|
||||
from langchain_community.llms import OpenAI
|
||||
llm_symbolic_math = LLMSymbolicMathChain.from_llm(OpenAI())
|
||||
"""
|
||||
|
||||
@@ -3,11 +3,32 @@ from collections import defaultdict
|
||||
from html.parser import HTMLParser
|
||||
from typing import Any, DefaultDict, Dict, List, Optional, cast
|
||||
|
||||
from langchain.schema import (
|
||||
from langchain_classic.schema import (
|
||||
ChatGeneration,
|
||||
ChatResult,
|
||||
)
|
||||
from langchain_community.chat_models.anthropic import ChatAnthropic
|
||||
|
||||
try:
|
||||
from langchain_community.chat_models.anthropic import ChatAnthropic
|
||||
except ImportError as e:
|
||||
_IMPORT_ERROR = e
|
||||
|
||||
class ChatAnthropic: # type: ignore[no-redef]
|
||||
"""Stub for environments where `langchain-community` no longer ships
|
||||
`langchain_community.chat_models.anthropic` (removed in 0.4.2)."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
raise ImportError(
|
||||
"`AnthropicFunctions` depends on `langchain_community.chat_"
|
||||
"models.anthropic.ChatAnthropic`, which was removed in "
|
||||
"`langchain-community>=0.4.2`. Anthropic now supports tool "
|
||||
"calling natively; use `langchain_anthropic.ChatAnthropic` "
|
||||
"with `bind_tools` instead. Note: `langchain-experimental` is "
|
||||
"being sunset; see "
|
||||
"https://github.com/langchain-ai/langchain-experimental/issues/87."
|
||||
) from _IMPORT_ERROR
|
||||
|
||||
|
||||
from langchain_core._api.deprecation import deprecated
|
||||
from langchain_core.callbacks.manager import (
|
||||
CallbackManagerForLLMRun,
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import (
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from langchain.schema import (
|
||||
from langchain_classic.schema import (
|
||||
ChatGeneration,
|
||||
ChatResult,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, List, Optional
|
||||
|
||||
from langchain.schema import LLMResult
|
||||
from langchain_classic.schema import LLMResult
|
||||
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
||||
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
|
||||
from pydantic import Field
|
||||
|
||||
@@ -12,9 +12,29 @@ from typing import (
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
|
||||
from langchain_community.chat_models.ollama import ChatOllama
|
||||
try:
|
||||
from langchain_community.chat_models.ollama import ChatOllama
|
||||
except ImportError as e:
|
||||
_IMPORT_ERROR = e
|
||||
|
||||
class ChatOllama: # type: ignore[no-redef]
|
||||
"""Stub for environments where `langchain-community` no longer ships
|
||||
`langchain_community.chat_models.ollama` (removed in 0.4.2)."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
raise ImportError(
|
||||
"`OllamaFunctions` depends on `langchain_community.chat_models."
|
||||
"ollama.ChatOllama`, which was removed in "
|
||||
"`langchain-community>=0.4.2`. Use `langchain_ollama.ChatOllama`"
|
||||
" directly instead. Note: `langchain-experimental` is being "
|
||||
"sunset; see "
|
||||
"https://github.com/langchain-ai/langchain-experimental/issues/87."
|
||||
) from _IMPORT_ERROR
|
||||
|
||||
|
||||
from langchain_core._api import deprecated
|
||||
from langchain_core.callbacks import (
|
||||
AsyncCallbackManagerForLLMRun,
|
||||
@@ -86,7 +106,7 @@ def convert_to_ollama_tool(tool: Any) -> Dict:
|
||||
schema = tool.model_construct().model_json_schema()
|
||||
name = schema["title"]
|
||||
elif isinstance(tool, BaseTool):
|
||||
schema = tool.tool_call_schema.model_json_schema()
|
||||
schema = cast(BaseModel, tool.tool_call_schema).model_json_schema()
|
||||
name = tool.get_name()
|
||||
description = tool.description
|
||||
elif is_basemodel_instance(tool):
|
||||
@@ -148,7 +168,7 @@ class OllamaFunctions(ChatOllama):
|
||||
self,
|
||||
tools: Sequence[Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]],
|
||||
**kwargs: Any,
|
||||
) -> Runnable[LanguageModelInput, BaseMessage]:
|
||||
) -> Runnable[LanguageModelInput, AIMessage]:
|
||||
return self.bind(functions=tools, **kwargs)
|
||||
|
||||
def with_structured_output(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# flake8: noqa
|
||||
|
||||
# For backwards compatibility.
|
||||
from langchain.agents.openai_assistant.base import (
|
||||
from langchain_classic.agents.openai_assistant.base import (
|
||||
OpenAIAssistantAction,
|
||||
OpenAIAssistantFinish,
|
||||
OpenAIAssistantRunnable,
|
||||
|
||||
@@ -10,8 +10,8 @@ from __future__ import annotations
|
||||
import ast
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from pydantic import ConfigDict, Field, model_validator
|
||||
@@ -28,6 +28,13 @@ COMMAND_EXECUTION_FUNCTIONS = [
|
||||
"eval",
|
||||
"__import__",
|
||||
"compile",
|
||||
"globals",
|
||||
"setattr",
|
||||
"locals",
|
||||
"vars",
|
||||
"getattr",
|
||||
"dir",
|
||||
"format",
|
||||
]
|
||||
COMMAND_EXECUTION_ATTRIBUTES = [
|
||||
"__import__",
|
||||
@@ -40,6 +47,29 @@ COMMAND_EXECUTION_ATTRIBUTES = [
|
||||
"__mro__",
|
||||
"__base__",
|
||||
]
|
||||
DANGEROUS_SUBSCRIPT_STRINGS = [
|
||||
"__builtins__",
|
||||
"__globals__",
|
||||
"__import__",
|
||||
"__subclasses__",
|
||||
"__getattribute__",
|
||||
"__code__",
|
||||
"__bases__",
|
||||
"__mro__",
|
||||
"__base__",
|
||||
"eval",
|
||||
"exec",
|
||||
"open",
|
||||
"compile",
|
||||
"system",
|
||||
"globals",
|
||||
"locals",
|
||||
"vars",
|
||||
"getattr",
|
||||
"setattr",
|
||||
"dir",
|
||||
"format",
|
||||
]
|
||||
|
||||
|
||||
class PALValidation:
|
||||
@@ -225,8 +255,7 @@ class PALChain(Chain):
|
||||
raise ValueError(f"Generated code is not valid python code: {code}")
|
||||
except TypeError:
|
||||
raise ValueError(
|
||||
f"Generated code is expected to be a string, "
|
||||
f"instead found {type(code)}"
|
||||
f"Generated code is expected to be a string, instead found {type(code)}"
|
||||
)
|
||||
except OverflowError:
|
||||
raise ValueError(
|
||||
@@ -312,6 +341,60 @@ class PALChain(Chain):
|
||||
f"{node.func.attr} in code {code}"
|
||||
)
|
||||
|
||||
if isinstance(node, ast.Subscript):
|
||||
if isinstance(node.slice, ast.Constant):
|
||||
if node.slice.value in DANGEROUS_SUBSCRIPT_STRINGS:
|
||||
raise ValueError(
|
||||
f"Found illegal subscript access to "
|
||||
f"'{node.slice.value}' in code {code}"
|
||||
)
|
||||
elif isinstance(node.slice, ast.Str):
|
||||
if node.slice.s in DANGEROUS_SUBSCRIPT_STRINGS:
|
||||
raise ValueError(
|
||||
f"Found illegal subscript access to "
|
||||
f"'{node.slice.s}' in code {code}"
|
||||
)
|
||||
|
||||
if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):
|
||||
if isinstance(node.left, ast.Constant) and isinstance(
|
||||
node.right, ast.Constant
|
||||
):
|
||||
if isinstance(node.left.value, str) and isinstance(
|
||||
node.right.value, str
|
||||
):
|
||||
combined = node.left.value + node.right.value
|
||||
if combined in DANGEROUS_SUBSCRIPT_STRINGS:
|
||||
raise ValueError(
|
||||
f"Found dangerous string concatenation: "
|
||||
f"'{combined}' in code {code}"
|
||||
)
|
||||
elif isinstance(node.left, ast.Str) and isinstance(
|
||||
node.right, ast.Str
|
||||
):
|
||||
combined = node.left.s + node.right.s
|
||||
if combined in DANGEROUS_SUBSCRIPT_STRINGS:
|
||||
raise ValueError(
|
||||
f"Found dangerous string concatenation: "
|
||||
f"'{combined}' in code {code}"
|
||||
)
|
||||
|
||||
# Check for f-strings and format strings
|
||||
if isinstance(node, ast.JoinedStr):
|
||||
for value in node.values:
|
||||
if isinstance(value, ast.FormattedValue):
|
||||
# Check if the expression uses dangerous patterns
|
||||
if (
|
||||
hasattr(value.value, "id")
|
||||
and value.value.id in DANGEROUS_SUBSCRIPT_STRINGS
|
||||
):
|
||||
raise ValueError(
|
||||
f"Found dangerous f-string pattern in code {code}"
|
||||
)
|
||||
|
||||
# Check for lambda expressions
|
||||
if isinstance(node, ast.Lambda):
|
||||
raise ValueError(f"Lambda expressions not allowed in code {code}")
|
||||
|
||||
if (not code_validations.allow_imports) and (
|
||||
isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom)
|
||||
):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
CallbackManagerForChainRun,
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
from langchain.agents.agent import AgentExecutor
|
||||
from langchain.agents.structured_chat.base import StructuredChatAgent
|
||||
from langchain_classic.agents.agent import AgentExecutor
|
||||
from langchain_classic.agents.structured_chat.base import StructuredChatAgent
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Any
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import Callbacks
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import Callbacks
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import re
|
||||
|
||||
from langchain.chains import LLMChain
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import SystemMessage
|
||||
from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
|
||||
|
||||
@@ -2,9 +2,9 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Mapping, Optional, cast
|
||||
|
||||
from langchain.chains import LLMChain
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
from langchain_classic.chains import LLMChain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.schema.language_model import BaseLanguageModel
|
||||
from langchain_core.callbacks.manager import (
|
||||
CallbackManagerForChainRun,
|
||||
)
|
||||
|
||||
@@ -16,8 +16,8 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.prompts import (
|
||||
BasePromptTemplate,
|
||||
|
||||
@@ -3,8 +3,8 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.prompts import BasePromptTemplate
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.input import get_colored_text
|
||||
from langchain.schema import LLMResult, PromptValue
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.input import get_colored_text
|
||||
from langchain_classic.schema import LLMResult, PromptValue
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.prompts.base import BasePromptTemplate
|
||||
from langchain_core.prompts.chat import (
|
||||
@@ -244,13 +244,13 @@ class SmartLLMChain(Chain):
|
||||
)
|
||||
|
||||
def ideation_prompt(self) -> ChatPromptTemplate:
|
||||
return ChatPromptTemplate.from_strings(self.get_prompt_strings("ideation"))
|
||||
return ChatPromptTemplate.from_messages(self.get_prompt_strings("ideation"))
|
||||
|
||||
def critique_prompt(self) -> ChatPromptTemplate:
|
||||
return ChatPromptTemplate.from_strings(self.get_prompt_strings("critique"))
|
||||
return ChatPromptTemplate.from_messages(self.get_prompt_strings("critique"))
|
||||
|
||||
def resolve_prompt(self) -> ChatPromptTemplate:
|
||||
return ChatPromptTemplate.from_strings(self.get_prompt_strings("resolve"))
|
||||
return ChatPromptTemplate.from_messages(self.get_prompt_strings("resolve"))
|
||||
|
||||
def _ideate(
|
||||
self,
|
||||
|
||||
@@ -5,10 +5,14 @@ from __future__ import annotations
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.chains.sql_database.prompt import DECIDER_PROMPT, PROMPT, SQL_PROMPTS
|
||||
from langchain.schema import BasePromptTemplate
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.chains.sql_database.prompt import (
|
||||
DECIDER_PROMPT,
|
||||
PROMPT,
|
||||
SQL_PROMPTS,
|
||||
)
|
||||
from langchain_classic.schema import BasePromptTemplate
|
||||
from langchain_community.tools.sql_database.prompt import QUERY_CHECKER
|
||||
from langchain_community.utilities.sql_database import SQLDatabase
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
|
||||
@@ -4,8 +4,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.chains.sql_database.prompt import PROMPT, SQL_PROMPTS
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.chains.sql_database.prompt import PROMPT, SQL_PROMPTS
|
||||
from langchain_community.tools.sql_database.prompt import QUERY_CHECKER
|
||||
from langchain_community.utilities.sql_database import SQLDatabase
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import asyncio
|
||||
from typing import Any, Dict, List, Optional, Union, cast
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts.few_shot import FewShotPromptTemplate
|
||||
from langchain_core.utils.pydantic import is_basemodel_instance
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
from typing import Any, Dict, Optional, Type, Union
|
||||
|
||||
from langchain.chains.openai_functions import create_structured_output_chain
|
||||
from langchain.schema import BaseLLMOutputParser, BasePromptTemplate
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_classic.chains.openai_functions import create_structured_output_chain
|
||||
from langchain_classic.schema import BaseLLMOutputParser, BasePromptTemplate
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
from pydantic import BaseModel
|
||||
|
||||
try:
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
except ImportError as e:
|
||||
_IMPORT_ERROR = e
|
||||
|
||||
class ChatOpenAI: # type: ignore[no-redef]
|
||||
"""Stub for environments where `langchain-community` no longer exports
|
||||
`ChatOpenAI` (removed in 0.4.2)."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
raise ImportError(
|
||||
"`langchain_experimental.tabular_synthetic_data.openai` depends "
|
||||
"on `langchain_community.chat_models.ChatOpenAI`, which was "
|
||||
"removed in `langchain-community>=0.4.2`. Use "
|
||||
"`langchain_openai.ChatOpenAI` directly instead. Note: "
|
||||
"`langchain-experimental` is being sunset; see "
|
||||
"https://github.com/langchain-ai/langchain-experimental/issues/87."
|
||||
) from _IMPORT_ERROR
|
||||
|
||||
|
||||
from langchain_experimental.tabular_synthetic_data.base import SyntheticDataGenerator
|
||||
|
||||
OPENAI_TEMPLATE = PromptTemplate(input_variables=["example"], template="{example}")
|
||||
|
||||
@@ -160,7 +160,7 @@ class SemanticChunker(BaseDocumentTransformer):
|
||||
return cast(
|
||||
float,
|
||||
np.percentile(distance_gradient, self.breakpoint_threshold_amount),
|
||||
), distance_gradient
|
||||
), cast(List[float], distance_gradient)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Got unexpected `breakpoint_threshold_type`: "
|
||||
|
||||
@@ -92,8 +92,8 @@ class PythonAstREPLTool(BaseTool):
|
||||
"When using this tool, sometimes output is abbreviated - "
|
||||
"make sure it does not look abbreviated before using it in your answer."
|
||||
)
|
||||
globals: Optional[Dict] = Field(default_factory=dict)
|
||||
locals: Optional[Dict] = Field(default_factory=dict)
|
||||
globals: Optional[Dict] = Field(default_factory=dict) # type: ignore[arg-type]
|
||||
locals: Optional[Dict] = Field(default_factory=dict) # type: ignore[arg-type]
|
||||
sanitize_input: bool = True
|
||||
args_schema: Type[BaseModel] = PythonInputs
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ from __future__ import annotations
|
||||
from textwrap import indent
|
||||
from typing import Any, Dict, List, Optional, Type
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.base_language import BaseLanguageModel
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
CallbackManagerForChainRun,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
|
||||
from langchain_experimental.tot.thought import ThoughtValidity
|
||||
|
||||
@@ -10,7 +10,7 @@ exploration.
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.prompts.base import BasePromptTemplate
|
||||
from pydantic import Field
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ def warn_once() -> None:
|
||||
class PythonREPL(BaseModel):
|
||||
"""Simulates a standalone Python REPL."""
|
||||
|
||||
globals: Optional[Dict] = Field(default_factory=dict, alias="_globals")
|
||||
locals: Optional[Dict] = Field(default_factory=dict, alias="_locals")
|
||||
globals: Optional[Dict] = Field(default_factory=dict, alias="_globals") # type: ignore[arg-type]
|
||||
locals: Optional[Dict] = Field(default_factory=dict, alias="_locals") # type: ignore[arg-type]
|
||||
|
||||
@staticmethod
|
||||
def sanitize_input(query: str) -> str:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain_classic.chains.base import Chain
|
||||
from langchain_core.callbacks import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
@@ -2,7 +2,7 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from langchain.schema import Document
|
||||
from langchain_classic.schema import Document
|
||||
from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
|
||||
from langchain_community.document_loaders.assemblyai import TranscriptFormat
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
from langchain_classic.chains.llm import LLMChain
|
||||
from langchain_classic.schema.language_model import BaseLanguageModel
|
||||
from langchain_core.callbacks.manager import CallbackManagerForChainRun
|
||||
|
||||
from langchain_experimental.video_captioning.models import (
|
||||
|
||||
Generated
-3814
File diff suppressed because it is too large
Load Diff
@@ -1,2 +0,0 @@
|
||||
[virtualenvs]
|
||||
in-project = true
|
||||
@@ -1,30 +1,65 @@
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
requires = ["pdm-backend"]
|
||||
build-backend = "pdm.backend"
|
||||
|
||||
[tool.poetry]
|
||||
name = "langchain-experimental"
|
||||
version = "0.3.4"
|
||||
description = "Building applications with LLMs through composability"
|
||||
[project]
|
||||
authors = []
|
||||
license = "MIT"
|
||||
license = {text = "MIT"}
|
||||
requires-python = "<4.0,>=3.10"
|
||||
dependencies = [
|
||||
"langchain-core<2.0.0,>=1.4.0",
|
||||
"langchain-community<1.0.0,>=0.4.2",
|
||||
]
|
||||
name = "langchain-experimental"
|
||||
version = "0.4.2"
|
||||
description = "Building applications with LLMs through composability"
|
||||
readme = "README.md"
|
||||
|
||||
[project.urls]
|
||||
"Source Code" = "https://github.com/langchain-ai/langchain-experimental/tree/main/libs/experimental"
|
||||
"Release Notes" = "https://github.com/langchain-ai/langchain-experimental/releases"
|
||||
repository = "https://github.com/langchain-ai/langchain-experimental"
|
||||
|
||||
[dependency-groups]
|
||||
lint = [
|
||||
"ruff<0.6,>=0.5",
|
||||
]
|
||||
typing = [
|
||||
"mypy<1.12,>=1.10",
|
||||
"types-pyyaml<7.0.0.0,>=6.0.12.2",
|
||||
"types-requests<3.0.0.0,>=2.28.11.5",
|
||||
"langchain-classic @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/langchain",
|
||||
"langchain-core @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/core",
|
||||
"langchain-community @ git+https://github.com/langchain-ai/langchain-community.git#subdirectory=libs/community",
|
||||
]
|
||||
dev = [
|
||||
"jupyter<2.0.0,>=1.0.0",
|
||||
"setuptools>=67.6.1,<79.0.0",
|
||||
"langchain-classic @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/langchain",
|
||||
"langchain-core @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/core",
|
||||
"langchain-community @ git+https://github.com/langchain-ai/langchain-community.git#subdirectory=libs/community",
|
||||
]
|
||||
test = [
|
||||
"pytest>=7.3.0,<10.0.0",
|
||||
"pytest-asyncio<2.0.0,>=1.3.0",
|
||||
"langchain-classic @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/langchain",
|
||||
"langchain-core @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/core",
|
||||
"langchain-community @ git+https://github.com/langchain-ai/langchain-community.git#subdirectory=libs/community",
|
||||
"langchain-text-splitters @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/text-splitters",
|
||||
]
|
||||
test_integration = [
|
||||
"langchain-classic @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/langchain",
|
||||
"langchain-core @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/core",
|
||||
"langchain-community @ git+https://github.com/langchain-ai/langchain-community.git#subdirectory=libs/community",
|
||||
"langchain-openai @ git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/partners/openai",
|
||||
]
|
||||
|
||||
|
||||
[tool.mypy]
|
||||
ignore_missing_imports = "True"
|
||||
disallow_untyped_defs = "True"
|
||||
exclude = ["notebooks", "examples", "example_data"]
|
||||
|
||||
[tool.poetry.urls]
|
||||
"Source Code" = "https://github.com/langchain-ai/langchain-experimental/tree/main/libs/experimental"
|
||||
"Release Notes" = "https://github.com/langchain-ai/langchain-experimental/releases"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.9,<4.0"
|
||||
langchain-core = "^0.3.28"
|
||||
langchain-community = "^0.3.0"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["E", "F", "I", "T201"]
|
||||
|
||||
@@ -39,57 +74,3 @@ markers = [
|
||||
"compile: mark placeholder test used to compile integration tests without running them",
|
||||
]
|
||||
asyncio_mode = "auto"
|
||||
|
||||
[tool.poetry.group.lint]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.typing]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.dev]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.test]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.test_integration]
|
||||
optional = true
|
||||
|
||||
[tool.poetry.group.lint.dependencies]
|
||||
ruff = "^0.5"
|
||||
|
||||
[tool.poetry.group.typing.dependencies]
|
||||
mypy = "^1.10"
|
||||
types-pyyaml = "^6.0.12.2"
|
||||
types-requests = "^2.28.11.5"
|
||||
langchain = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/langchain" }
|
||||
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
||||
langchain-community = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/community" }
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
jupyter = "^1.0.0"
|
||||
setuptools = "^67.6.1"
|
||||
langchain = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/langchain" }
|
||||
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
||||
langchain-community = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/community" }
|
||||
|
||||
[tool.poetry.group.test.dependencies]
|
||||
pytest = "^7.3.0"
|
||||
pytest-asyncio = "^0.20.3"
|
||||
langchain = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/langchain" }
|
||||
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
||||
langchain-community = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/community" }
|
||||
langchain-text-splitters = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/text-splitters" }
|
||||
[[tool.poetry.group.test.dependencies.numpy]]
|
||||
version = "^1.24.0"
|
||||
python = "<3.12"
|
||||
|
||||
[[tool.poetry.group.test.dependencies.numpy]]
|
||||
version = "^1.26.0"
|
||||
python = ">=3.12"
|
||||
|
||||
[tool.poetry.group.test_integration.dependencies]
|
||||
langchain = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/langchain" }
|
||||
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
||||
langchain-community = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/community" }
|
||||
langchain-openai = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/partners/openai" }
|
||||
|
||||
@@ -7,7 +7,7 @@ from unittest import mock
|
||||
|
||||
import pydantic
|
||||
import pytest
|
||||
from langchain.output_parsers import PydanticOutputParser
|
||||
from langchain_classic.output_parsers import PydanticOutputParser
|
||||
from langchain_community.llms import OpenAI
|
||||
from langchain_core.prompts.prompt import PromptTemplate
|
||||
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import pytest
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_core.prompts.few_shot import FewShotPromptTemplate
|
||||
from pydantic import BaseModel
|
||||
|
||||
try:
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
except ImportError:
|
||||
pytest.skip(
|
||||
"`langchain_community.chat_models.ChatOpenAI` was removed in "
|
||||
"`langchain-community>=0.4.2`; use `langchain_openai.ChatOpenAI` "
|
||||
"instead.",
|
||||
allow_module_level=True,
|
||||
)
|
||||
|
||||
from langchain_core.prompts.few_shot import FewShotPromptTemplate # noqa: E402
|
||||
from pydantic import BaseModel # noqa: E402
|
||||
|
||||
from langchain_experimental.tabular_synthetic_data.base import SyntheticDataGenerator
|
||||
from langchain_experimental.tabular_synthetic_data.openai import (
|
||||
|
||||
@@ -2,10 +2,23 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from langchain_community.chat_models.anthropic import ChatAnthropic
|
||||
from langchain_community.chat_models.bedrock import BedrockChat
|
||||
import pytest
|
||||
|
||||
from langchain_experimental.llms.anthropic_functions import AnthropicFunctions
|
||||
try:
|
||||
from langchain_community.chat_models.anthropic import ChatAnthropic
|
||||
from langchain_community.chat_models.bedrock import BedrockChat
|
||||
except ImportError:
|
||||
pytest.skip(
|
||||
"`langchain_community.chat_models.anthropic` and "
|
||||
"`langchain_community.chat_models.bedrock` were removed in "
|
||||
"`langchain-community>=0.4.2`; use `langchain_anthropic.ChatAnthropic` "
|
||||
"and `langchain_aws.ChatBedrock` instead.",
|
||||
allow_module_level=True,
|
||||
)
|
||||
|
||||
from langchain_experimental.llms.anthropic_functions import ( # noqa: E402
|
||||
AnthropicFunctions,
|
||||
)
|
||||
|
||||
|
||||
class TestAnthropicFunctions(unittest.TestCase):
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_video_captioning_hard() -> None:
|
||||
chain = VideoCaptioningChain( # type: ignore[call-arg]
|
||||
llm=ChatOpenAI(
|
||||
model="gpt-4",
|
||||
max_tokens=4000,
|
||||
max_completion_tokens=4000,
|
||||
)
|
||||
)
|
||||
srt_content = chain.run(video_file_path=URL)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from langchain.schema import AIMessage, HumanMessage, SystemMessage
|
||||
from langchain_classic.schema import AIMessage, HumanMessage, SystemMessage
|
||||
|
||||
from langchain_experimental.chat_models import Mixtral
|
||||
from tests.unit_tests.chat_models.test_llm_wrapper_llama2chat import FakeLLM
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from langchain.schema import OutputParserException
|
||||
from langchain_classic.schema import OutputParserException
|
||||
|
||||
from langchain_experimental.llm_bash.base import LLMBashChain
|
||||
from langchain_experimental.llm_bash.prompt import _PROMPT_TEMPLATE, BashOutputParser
|
||||
|
||||
@@ -2,10 +2,20 @@ import json
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from langchain_core.prompts import ChatPromptTemplate
|
||||
from pydantic import BaseModel
|
||||
import pytest
|
||||
|
||||
from langchain_experimental.llms.ollama_functions import OllamaFunctions
|
||||
pytest.importorskip(
|
||||
"langchain_community.chat_models.ollama",
|
||||
reason=(
|
||||
"`langchain_community.chat_models.ollama` was removed in "
|
||||
"`langchain-community>=0.4.2`; `OllamaFunctions` is unusable without it."
|
||||
),
|
||||
)
|
||||
|
||||
from langchain_core.prompts import ChatPromptTemplate # noqa: E402
|
||||
from pydantic import BaseModel # noqa: E402
|
||||
|
||||
from langchain_experimental.llms.ollama_functions import OllamaFunctions # noqa: E402
|
||||
|
||||
|
||||
class Schema(BaseModel):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from langchain.memory import ConversationBufferMemory
|
||||
from langchain.output_parsers.list import CommaSeparatedListOutputParser
|
||||
from langchain_classic.memory import ConversationBufferMemory
|
||||
from langchain_classic.output_parsers.list import CommaSeparatedListOutputParser
|
||||
from langchain_community.utilities import SQLDatabase
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
|
||||
Generated
+4112
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user