diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml index cfe5447fa7d3..034fdfd03a73 100644 --- a/.github/workflows/compatibility.yml +++ b/.github/workflows/compatibility.yml @@ -4,9 +4,10 @@ on: push: branches: ["main"] pull_request: - # Do not run this workflow if only docs changed. + # Do not run this workflow if only docs/examples changed. paths-ignore: - 'docs/**' + - 'examples/**' workflow_dispatch: # Allows triggering the workflow manually in GitHub UI # If another push to the same PR or branch happens while this workflow is still running, @@ -28,9 +29,27 @@ env: # Run a separate job for each check in the docker-compose file, # so that they run in parallel instead of overwhelming the default 2 CPU runner. jobs: + get-changed-files: + runs-on: ubuntu-latest + outputs: + changed_files: ${{ steps.get_changes.outputs.changed_files }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - name: Get changes + id: get_changes + run: | + echo "changed_files<> $GITHUB_OUTPUT + git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + # LangChain langchain-latest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain/') || contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-textsplitters/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -43,6 +62,8 @@ jobs: langchain-lowest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -56,6 +77,8 @@ jobs: # Community community-latest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -72,6 +95,8 @@ jobs: community-lowest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -89,6 +114,8 @@ jobs: # OpenAI openai-latest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -105,6 +132,8 @@ jobs: openai-lowest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -122,6 +151,8 @@ jobs: # Anthropic anthropic-latest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-anthropic/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -138,6 +169,8 @@ jobs: anthropic-lowest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-anthropic/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -155,6 +188,8 @@ jobs: # Google VertexAI google-vertexai-latest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-vertexai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-gauth/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-common/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -171,6 +206,8 @@ jobs: google-vertexai-lowest-deps: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-vertexai/') steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ env.NODE_VERSION }} @@ -183,4 +220,4 @@ jobs: - name: Build `@langchain/standard-tests` run: yarn build --filter=@langchain/standard-tests - name: Test `@langchain/google-vertexai` with lowest deps - run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps \ No newline at end of file + run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps diff --git a/.github/workflows/standard-tests.yml b/.github/workflows/standard-tests.yml index d474706a7597..24bd8fb9b557 100644 --- a/.github/workflows/standard-tests.yml +++ b/.github/workflows/standard-tests.yml @@ -6,11 +6,29 @@ on: - cron: '0 13 * * *' jobs: + get-changed-files: + runs-on: ubuntu-latest + outputs: + changed_files: ${{ steps.get_changes.outputs.changed_files }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - name: Get changes + id: get_changes + run: | + echo "changed_files<> $GITHUB_OUTPUT + git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + standard-tests: runs-on: ubuntu-latest + needs: get-changed-files strategy: matrix: package: [anthropic, cohere, google-genai, groq, mistralai] + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-${{ matrix.package }}/') steps: - uses: actions/checkout@v4 - name: Use Node.js 18.x @@ -34,6 +52,8 @@ jobs: # we need separate jobs for each test. standard-tests-openai: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') steps: - uses: actions/checkout@v4 - name: Use Node.js 18.x @@ -52,6 +72,8 @@ jobs: standard-tests-azure-openai: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') steps: - uses: actions/checkout@v4 - name: Use Node.js 18.x @@ -73,6 +95,8 @@ jobs: standard-tests-bedrock: runs-on: ubuntu-latest + needs: get-changed-files + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/') steps: - uses: actions/checkout@v4 - name: Use Node.js 18.x diff --git a/.github/workflows/test-exports.yml b/.github/workflows/test-exports.yml index 22c46d2acb8e..44bf3864216e 100644 --- a/.github/workflows/test-exports.yml +++ b/.github/workflows/test-exports.yml @@ -1,6 +1,15 @@ name: Environment tests on: + pull_request: + # Only run workflow if files in these directories are changed + paths: + - 'langchain/**' + - 'langchain-core/**' + - 'libs/langchain-anthropic/**' + - 'libs/langchain-community/**' + - 'libs/langchain-openai/**' + - 'examples/**' workflow_dispatch: # Allows triggering the workflow manually in GitHub UI workflow_call: # Allows triggering the workflow from another workflow diff --git a/.github/workflows/unit-tests-langchain-integrations.yml b/.github/workflows/unit-tests-integrations.yml similarity index 61% rename from .github/workflows/unit-tests-langchain-integrations.yml rename to .github/workflows/unit-tests-integrations.yml index b3782d02ba27..06af6388b01e 100644 --- a/.github/workflows/unit-tests-langchain-integrations.yml +++ b/.github/workflows/unit-tests-integrations.yml @@ -11,7 +11,6 @@ on: paths: - 'langchain-core/**' - 'libs/**/**' - - '!libs/langchain-community/**' workflow_dispatch: # Allows triggering the workflow manually in GitHub UI @@ -26,12 +25,30 @@ concurrency: cancel-in-progress: true jobs: + get-changed-files: + runs-on: ubuntu-latest + outputs: + changed_files: ${{ steps.get_changes.outputs.changed_files }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - name: Get changes + id: get_changes + run: | + echo "changed_files<> $GITHUB_OUTPUT + git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + unit-tests: name: Unit Tests + needs: get-changed-files strategy: matrix: os: [ubuntu-latest] node-version: [18.x, 20.x] + package: [anthropic, azure-openai, cloudflare, cohere, community, exa, google-common, google-gauth, google-genai, google-vertexai, google-vertexai-web, google-webauth, groq, mistralai, mongo, nomic, openai, pinecone, qdrant, redis, textsplitters, weaviate, yandex] # See Node.js release schedule at https://nodejs.org/en/about/releases/ # include: # - os: windows-latest @@ -39,6 +56,7 @@ jobs: # - os: macos-latest # node-version: 20.x runs-on: ${{ matrix.os }} + if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-${{ matrix.package }}/') env: PUPPETEER_SKIP_DOWNLOAD: "true" PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" @@ -51,5 +69,5 @@ jobs: cache: "yarn" - name: Install dependencies run: yarn install --immutable - - name: Test - run: yarn run test:unit:ci --filter=!@langchain/community --filter=!@langchain/core --filter=!langchain --filter=!api_refs --filter=!core_docs --filter=!create-langchain-integration --filter=!examples + - name: Test '@langchain/${{ matrix.package }}' package + run: yarn test:unit:ci --filter=@langchain/${{ matrix.package }} diff --git a/.github/workflows/unit-tests-langchain-community.yml b/.github/workflows/unit-tests-langchain-community.yml deleted file mode 100644 index 0d3dc85f9f9d..000000000000 --- a/.github/workflows/unit-tests-langchain-community.yml +++ /dev/null @@ -1,54 +0,0 @@ -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs - -name: Unit Tests (LangChain Community) - -on: - push: - branches: ["main"] - pull_request: - # Only run when LangChain Core, or Community code changes. - paths: - - 'langchain-core/**' - - 'libs/langchain-community/**' - workflow_dispatch: # Allows triggering the workflow manually in GitHub UI - - -# If another push to the same PR or branch happens while this workflow is still running, -# cancel the earlier run in favor of the next run. -# -# There's no point in testing an outdated version of the code. GitHub only allows -# a limited number of job runners to be active at the same time, so it's better to cancel -# pointless jobs early so that more useful jobs can run sooner. -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - unit-tests: - name: Unit Tests - strategy: - matrix: - os: [ubuntu-latest] - node-version: [18.x, 20.x] - # See Node.js release schedule at https://nodejs.org/en/about/releases/ - # include: - # - os: windows-latest - # node-version: 20.x - # - os: macos-latest - # node-version: 20.x - runs-on: ${{ matrix.os }} - env: - PUPPETEER_SKIP_DOWNLOAD: "true" - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true" - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: "yarn" - - name: Install dependencies - run: yarn install --immutable - - name: Test - run: yarn run test:unit:ci --filter=@langchain/community diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a07aacf4e240..4837a05c94c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,18 @@ To make creating packages like this easier, we offer the [`create-langchain-inte $ npx create-langchain-integration ``` +After creating the new integration package, you should add it to the [`unit-tests-integrations.yml`](./.github/workflows/unit-tests-integrations.yml) GitHub action workflow so that it is tested in CI. To do this, simply add the integration name inside the `jobs.unit-tests.strategy.matrix.package` array: + +```yaml +jobs: + unit-tests: + name: Unit Tests + strategy: + matrix: + package: [anthropic, azure-openai, cloudflare, ] + ... +``` + ### Want to add a feature that's already in Python? If you're interested in contributing a feature that's already in the [LangChain Python repo](https://github.com/langchain-ai/langchain) and you'd like some help getting started, you can try pasting code snippets and classes into the [LangChain Python to JS translator](https://langchain-translator.vercel.app/). diff --git a/libs/langchain-openai/src/chat_models.ts b/libs/langchain-openai/src/chat_models.ts index a6477039114c..243518c41c2d 100644 --- a/libs/langchain-openai/src/chat_models.ts +++ b/libs/langchain-openai/src/chat_models.ts @@ -274,14 +274,13 @@ export interface ChatOpenAICallOptions /** * Wrapper around OpenAI large language models that use the Chat endpoint. * - * To use you should have the `openai` package installed, with the - * `OPENAI_API_KEY` environment variable set. + * To use you should have the `OPENAI_API_KEY` environment variable set. * - * To use with Azure you should have the `openai` package installed, with the + * To use with Azure you should have the: * `AZURE_OPENAI_API_KEY`, * `AZURE_OPENAI_API_INSTANCE_NAME`, * `AZURE_OPENAI_API_DEPLOYMENT_NAME` - * and `AZURE_OPENAI_API_VERSION` environment variable set. + * and `AZURE_OPENAI_API_VERSION` environment variables set. * `AZURE_OPENAI_BASE_PATH` is optional and will override `AZURE_OPENAI_API_INSTANCE_NAME` if you need to use a custom endpoint. * * @remarks diff --git a/turbo.json b/turbo.json index f69adb6cf3dc..6fbd6d60e925 100644 --- a/turbo.json +++ b/turbo.json @@ -24,7 +24,7 @@ }, "test:ci": { "outputs": [], - "dependsOn": ["test"] + "dependsOn": ["^test", "test"] }, "test:single": { "dependsOn": ["^build", "build"]