Skip to content

Commit

Permalink
refactor: Move langchain/core to a peer dep (langchain-ai#6698)
Browse files Browse the repository at this point in the history
Co-authored-by: Brace Sproul <[email protected]>
Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
3 people authored and FilipZmijewski committed Sep 27, 2024
1 parent c85d16e commit f1afa6d
Show file tree
Hide file tree
Showing 665 changed files with 2,727 additions and 19,748 deletions.
4 changes: 2 additions & 2 deletions .github/DISCUSSION_TEMPLATE/q-a.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ body:
Relevant links to check before opening a question to see if your question has already been answered, fixed or
if there's another way to solve your problem:
[LangChain.js documentation with the integrated search](https://js.langchain.com/v0.2/docs/introduction),
[API Reference](https://v02.api.js.langchain.com/),
[LangChain.js documentation with the integrated search](https://js.langchain.com/docs/introduction),
[API Reference](https://api.js.langchain.com/),
[GitHub search](https://github.com/langchain-ai/langchainjs),
[LangChain.js Github Discussions](https://github.com/langchain-ai/langchainjs/discussions),
[LangChain.js Github Issues](https://github.com/langchain-ai/langchainjs/issues?q=is%3Aissue),
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ body:
Relevant links to check before filing a bug report to see if your issue has already been reported, fixed or
if there's another way to solve your problem:
[LangChain.js documentation with the integrated search](https://js.langchain.com/v0.2/docs/introduction),
[API Reference](https://v02.api.js.langchain.com/),
[LangChain.js documentation with the integrated search](https://js.langchain.com/docs/introduction),
[API Reference](https://api.js.langchain.com/),
[GitHub search](https://github.com/langchain-ai/langchainjs),
[LangChain.js Github Discussions](https://github.com/langchain-ai/langchainjs/discussions),
[LangChain.js Github Issues](https://github.com/langchain-ai/langchainjs/issues?q=is%3Aissue),
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ body:
If you're in the wrong place, here are some helpful links to find a better
place to ask your question:
[LangChain.js documentation with the integrated search](https://js.langchain.com/v0.2/docs/introduction),
[API Reference](https://v02.api.js.langchain.com/),
[LangChain.js documentation with the integrated search](https://js.langchain.com/docs/introduction),
[API Reference](https://api.js.langchain.com/),
[GitHub search](https://github.com/langchain-ai/langchainjs),
[LangChain.js Github Discussions](https://github.com/langchain-ai/langchainjs/discussions),
[LangChain.js Github Issues](https://github.com/langchain-ai/langchainjs/issues?q=is%3Aissue),
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/validate_new_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ jobs:
run: |
notebooks=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ' ' '\n' | grep '^docs/core_docs/.*\.ipynb$' || true)
if [ -n "$notebooks" ]; then
failed_notebooks=()
for notebook in $notebooks; do
absolute_path="$GITHUB_WORKSPACE/$notebook"
set +e
yarn workspace @langchain/scripts notebook_validate "$absolute_path"
if [ $? -ne 0 ]; then
failed_notebooks+=("$notebook")
fi
set -e
done
if [ ${#failed_notebooks[@]} -ne 0 ]; then
echo "The following notebooks failed validation:"
printf '%s\n' "${failed_notebooks[@]}"
exit 1
fi
else
echo "No notebooks in docs/core_docs to validate."
fi
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LangChain supports several different types of integrations with third-party prov

We welcome such contributions, but ask that you read our dedicated [integration contribution guide](https://github.com/langchain-ai/langchainjs/blob/main/.github/contributing/INTEGRATIONS.md) for specific details and patterns to consider before opening a pull request.

You can also check out the [guides on extending LangChain.js](https://js.langchain.com/v0.2/docs/how_to/#custom) in our docs.
You can also check out the [guides on extending LangChain.js](https://js.langchain.com/docs/how_to/#custom) in our docs.

#### Integration packages

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ LangChain is written in TypeScript and can be used in:
- **Reason**: rely on a language model to reason (about how to answer based on provided context, what actions to take, etc.)

This framework consists of several parts.
- **Open-source libraries**: Build your applications using LangChain's open-source [building blocks](https://js.langchain.com/v0.2/docs/concepts#langchain-expression-language), [components](https://js.langchain.com/v0.2/docs/concepts), and [third-party integrations](https://js.langchain.com/v0.2/docs/integrations/platforms/).
Use [LangGraph.js](https://js.langchain.com/v0.2/docs/concepts/#langgraphjs) to build stateful agents with first-class streaming and human-in-the-loop support.
- **Open-source libraries**: Build your applications using LangChain's open-source [building blocks](https://js.langchain.com/docs/concepts#langchain-expression-language), [components](https://js.langchain.com/docs/concepts), and [third-party integrations](https://js.langchain.com/docs/integrations/platforms/).
Use [LangGraph.js](https://js.langchain.com/docs/concepts/#langgraphjs) to build stateful agents with first-class streaming and human-in-the-loop support.
- **Productionization**: Use [LangSmith](https://docs.smith.langchain.com/) to inspect, monitor and evaluate your chains, so that you can continuously optimize and deploy with confidence.
- **Deployment**: Turn your LangGraph applications into production-ready APIs and Assistants with [LangGraph Cloud](https://langchain-ai.github.io/langgraph/cloud/) (currently Python-only).
- **Deployment**: Turn your LangGraph applications into production-ready APIs and Assistants with [LangGraph Cloud](https://langchain-ai.github.io/langgraph/cloud/).

The LangChain libraries themselves are made up of several different packages.
- **[`@langchain/core`](https://github.com/langchain-ai/langchainjs/blob/main/langchain-core)**: Base abstractions and LangChain Expression Language.
Expand All @@ -53,12 +53,12 @@ This library aims to assist in the development of those types of applications. C

**❓Question Answering over specific documents**

- [Documentation](https://js.langchain.com/v0.2/docs/tutorials/rag/)
- [Documentation](https://js.langchain.com/docs/tutorials/rag/)
- End-to-end Example: [Doc-Chatbot](https://github.com/dissorial/doc-chatbot)

**💬 Chatbots**

- [Documentation](https://js.langchain.com/v0.2/docs/tutorials/chatbot)
- [Documentation](https://js.langchain.com/docs/tutorials/chatbot)
- End-to-end Example: [Chat-LangChain](https://github.com/langchain-ai/chat-langchain)

## 🚀 How does LangChain help?
Expand All @@ -81,15 +81,15 @@ Data Augmented Generation involves specific types of chains that first interact

**🤖 Agents:**

Agents allow an LLM autonomy over how a task is accomplished. Agents make decisions about which Actions to take, then take that Action, observe the result, and repeat until the task is complete. LangChain provides a [standard interface for agents](https://js.langchain.com/v0.2/docs/concepts/#agents), along with [LangGraph.js](https://github.com/langchain-ai/langgraphjs/) for building custom agents.
Agents allow an LLM autonomy over how a task is accomplished. Agents make decisions about which Actions to take, then take that Action, observe the result, and repeat until the task is complete. LangChain provides a [standard interface for agents](https://js.langchain.com/docs/concepts/#agents), along with [LangGraph.js](https://github.com/langchain-ai/langgraphjs/) for building custom agents.

## 📖 Documentation

Please see [here](https://js.langchain.com) for full documentation, which includes:

- [Getting started](https://js.langchain.com/v0.2/docs/introduction): installation, setting up the environment, simple examples
- Overview of the [interfaces](https://js.langchain.com/v0.2/docs/how_to/lcel_cheatsheet/), [modules](https://js.langchain.com/v0.2/docs/concepts) and [integrations](https://js.langchain.com/v0.2/docs/integrations/platforms/)
- [Tutorial](https://js.langchain.com/v0.2/docs/tutorials/) walkthroughs
- [Getting started](https://js.langchain.com/docs/introduction): installation, setting up the environment, simple examples
- Overview of the [interfaces](https://js.langchain.com/docs/how_to/lcel_cheatsheet/), [modules](https://js.langchain.com/docs/concepts) and [integrations](https://js.langchain.com/docs/integrations/platforms/)
- [Tutorial](https://js.langchain.com/docs/tutorials/) walkthroughs
- [Reference](https://api.js.langchain.com): full API docs

## 💁 Contributing
Expand Down
2 changes: 1 addition & 1 deletion cookbook/rag_fusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"source": [
"## Setup\n",
"\n",
"For this example we'll use an in memory store as our vectorstore/retriever, and some fake data. You can swap out the vectorstore for your [preferred LangChain.js option](https://js.langchain.com/v0.2/docs/integrations/vectorstores) later.\n"
"For this example we'll use an in memory store as our vectorstore/retriever, and some fake data. You can swap out the vectorstore for your [preferred LangChain.js option](https://js.langchain.com/docs/integrations/vectorstores) later.\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require("fs");

const communityPackageJsonPath = "package.json";
const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
currentPackageJson.peerDependencies["@langchain/core"] = "latest";
}

// Stupid hack
currentPackageJson.resolutions = {
...currentPackageJson.resolutions,
"jackspeak": "2.1.1"
};

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@ const communityPackageJsonPath = "package.json";

const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.dependencies["@langchain/core"] && !currentPackageJson.dependencies["@langchain/core"].includes("rc")) {
if (currentPackageJson.peerDependencies["@langchain/core"] && !currentPackageJson.peerDependencies["@langchain/core"].includes("rc")) {
const minVersion = semver.minVersion(
currentPackageJson.dependencies["@langchain/core"]
currentPackageJson.peerDependencies["@langchain/core"]
).version;
currentPackageJson.overrides = {
...currentPackageJson.overrides,
"@langchain/core": minVersion,
};
currentPackageJson.dependencies = {
...currentPackageJson.dependencies,
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/core": minVersion,
};
}

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
}

if (currentPackageJson.dependencies["@langchain/openai"] && !currentPackageJson.dependencies["@langchain/openai"].includes("rc")) {
const minVersion = semver.minVersion(
currentPackageJson.dependencies["@langchain/openai"]
).version;
currentPackageJson.overrides = {
...currentPackageJson.overrides,
"@langchain/openai": minVersion,
};
currentPackageJson.dependencies = {
...currentPackageJson.dependencies,
"@langchain/openai": minVersion,
Expand All @@ -37,14 +33,16 @@ if (currentPackageJson.dependencies["@langchain/textsplitters"] && !currentPacka
const minVersion = semver.minVersion(
currentPackageJson.dependencies["@langchain/textsplitters"]
).version;
currentPackageJson.overrides = {
...currentPackageJson.overrides,
"@langchain/textsplitters": minVersion,
};
currentPackageJson.dependencies = {
...currentPackageJson.dependencies,
"@langchain/textsplitters": minVersion,
};
}

// Stupid hack
currentPackageJson.resolutions = {
...currentPackageJson.resolutions,
"jackspeak": "2.1.1"
};

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
12 changes: 12 additions & 0 deletions dependency_range_tests/scripts/langchain/test-with-latest-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ shopt -s extglob
# avoid copying build artifacts from the host
cp -r ../langchain/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) ./

mkdir -p /updater_script
cp -r /scripts/langchain/node/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) /updater_script/

cd /updater_script

yarn

cd /app

node /updater_script/update_resolutions_latest.js

yarn
yarn add @langchain/core

# Check the test command completes successfully
NODE_OPTIONS=--experimental-vm-modules yarn run jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ cd /app

node /updater_script/update_resolutions_lowest.js

# Read the @langchain/core version from peerDependencies
core_version=$(node -p "require('./package.json').peerDependencies['@langchain/core']")

yarn
yarn add @langchain/core@$core_version

# Check the test command completes successfully
NODE_OPTIONS=--experimental-vm-modules yarn run jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");

const communityPackageJsonPath = "/app/monorepo/libs/langchain-anthropic/package.json";
const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
currentPackageJson.peerDependencies["@langchain/core"] = "latest";
}

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const communityPackageJsonPath = "/app/monorepo/libs/langchain-anthropic/package

const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.dependencies["@langchain/core"] && !currentPackageJson.dependencies["@langchain/core"].includes("rc")) {
if (currentPackageJson.peerDependencies["@langchain/core"] && !currentPackageJson.peerDependencies["@langchain/core"].includes("rc")) {
const minVersion = semver.minVersion(
currentPackageJson.dependencies["@langchain/core"]
currentPackageJson.peerDependencies["@langchain/core"]
).version;
currentPackageJson.overrides = {
...currentPackageJson.overrides,
"@langchain/core": minVersion,
};
currentPackageJson.dependencies = {
...currentPackageJson.dependencies,
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/core": minVersion,
};
}

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
}

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cd "$updater_script_dir"
# Update any workspace dep to the latest version since not all workspaces are
# available in the test enviroment.
node "update_workspace_deps.js"
node "update_resolutions_latest.js"

# Navigate back to monorepo root and install dependencies
cd "$monorepo_dir"
Expand All @@ -32,4 +33,6 @@ yarn
# We need to run inside the anthropic directory so turbo repo does
# not try to build the package/its workspace dependencies.
cd "$monorepo_anthropic_dir"

yarn add @langchain/core
yarn test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euxo pipefail
export CI=true

monorepo_dir="/app/monorepo"
monorepo_openai_dir="/app/monorepo/libs/langchain-anthropic"
monorepo_anthropic_dir="/app/monorepo/libs/langchain-anthropic"
updater_script_dir="/app/updater_script"
original_updater_script_dir="/scripts/with_standard_tests/anthropic/node"

Expand All @@ -20,8 +20,8 @@ cp "$original_updater_script_dir"/* "$updater_script_dir/"
cd "$updater_script_dir"
yarn
# Run the updater script
node "update_resolutions_lowest.js"
node "update_workspace_deps.js"
node "update_resolutions_lowest.js"

# Navigate back to monorepo root and install dependencies
cd "$monorepo_dir"
Expand All @@ -30,5 +30,11 @@ yarn
# Navigate into `@langchain/anthropic` to build and run tests
# We need to run inside the package directory so turbo repo does
# not try to build the package/its workspace dependencies.
cd "$monorepo_openai_dir"
cd "$monorepo_anthropic_dir"

# Read the @langchain/core version from peerDependencies
core_version=$(node -p "require('./package.json').peerDependencies['@langchain/core']")

# Install @langchain/core at the specified version
yarn add @langchain/core@$core_version
yarn test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");

const communityPackageJsonPath = "/app/monorepo/libs/langchain-cohere/package.json";
const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
currentPackageJson.peerDependencies["@langchain/core"] = "latest";
}

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const communityPackageJsonPath = "/app/monorepo/libs/langchain-cohere/package.js

const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));

if (currentPackageJson.dependencies["@langchain/core"] && !currentPackageJson.dependencies["@langchain/core"].includes("rc")) {
if (currentPackageJson.peerDependencies["@langchain/core"] && !currentPackageJson.peerDependencies["@langchain/core"].includes("rc")) {
const minVersion = semver.minVersion(
currentPackageJson.dependencies["@langchain/core"]
currentPackageJson.peerDependencies["@langchain/core"]
).version;
currentPackageJson.overrides = {
...currentPackageJson.overrides,
"@langchain/core": minVersion,
};
currentPackageJson.dependencies = {
...currentPackageJson.dependencies,
currentPackageJson.peerDependencies = {
...currentPackageJson.peerDependencies,
"@langchain/core": minVersion,
};
}

if (currentPackageJson.devDependencies["@langchain/core"]) {
delete currentPackageJson.devDependencies["@langchain/core"];
}

fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ export CI=true

# New monorepo directory paths
monorepo_dir="/app/monorepo"
monorepo_openai_dir="/app/monorepo/libs/langchain-cohere"
monorepo_cohere_dir="/app/monorepo/libs/langchain-cohere"

# Updater script will not live inside the monorepo
updater_script_dir="/app/updater_script"

# Original directory paths
original_updater_script_dir="/scripts/with_standard_tests/cohere/node"

# Run the shared script to copy all necessary folders/files
bash /scripts/with_standard_tests/shared.sh cohere

mkdir -p "$updater_script_dir"
cp "$original_updater_script_dir"/* "$updater_script_dir/"
cd "$updater_script_dir"
# Update any workspace dep to the latest version since not all workspaces are
# available in the test enviroment.
node "update_resolutions_latest.js"

# Navigate back to monorepo root and install dependencies
cd "$monorepo_dir"
yarn

# Navigate into `@langchain/cohere` to build and run tests
# We need to run inside the cohere directory so turbo repo does
# not try to build the package/its workspace dependencies.
cd "$monorepo_openai_dir"
cd "$monorepo_cohere_dir"

yarn add @langchain/core
yarn test
Loading

0 comments on commit f1afa6d

Please sign in to comment.