Skip to content

Commit

Permalink
ci[patch]: Only run CI testsing if specific package touched (#5733)
Browse files Browse the repository at this point in the history
* ci[patch]: Only run latest/lowest if specific package touched

* matrix it!

* docs for new integration ci testsing

* make change to core to test

* Update chat.ts

* fix if statements

* fix if integrations

* test

* revert

* conditionally run test exports

* conditionally run standard tests too and make oai change to trigger

---------

Co-authored-by: Jacob Lee <[email protected]>
  • Loading branch information
bracesproul and jacoblee93 authored Jun 12, 2024
1 parent 13f392a commit ac204f8
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 64 deletions.
41 changes: 39 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<<EOF" >> $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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps
24 changes: 24 additions & 0 deletions .github/workflows/standard-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF" >> $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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/test-exports.yml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
paths:
- 'langchain-core/**'
- 'libs/**/**'
- '!libs/langchain-community/**'
workflow_dispatch: # Allows triggering the workflow manually in GitHub UI


Expand All @@ -26,19 +25,38 @@ 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<<EOF" >> $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
# node-version: 20.x
# - 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"
Expand All @@ -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 }}
54 changes: 0 additions & 54 deletions .github/workflows/unit-tests-langchain-community.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, <your package name>]
...
```

### 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/).
Expand Down
7 changes: 3 additions & 4 deletions libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"test:ci": {
"outputs": [],
"dependsOn": ["test"]
"dependsOn": ["^test", "test"]
},
"test:single": {
"dependsOn": ["^build", "build"]
Expand Down

0 comments on commit ac204f8

Please sign in to comment.