Skip to content

Commit

Permalink
Merge branch 'main' into brace/base-with-structured-output
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Jun 12, 2024
2 parents 0f2a402 + ac204f8 commit ece478a
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 72 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
6 changes: 5 additions & 1 deletion langchain/src/chains/openai_moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { BaseChain, ChainInputs } from "./base.js";
export interface OpenAIModerationChainInput
extends ChainInputs,
AsyncCallerParams {
apiKey?: string;
/** @deprecated Use "apiKey" instead. */
openAIApiKey?: string;
openAIOrganization?: string;
throwError?: boolean;
Expand Down Expand Up @@ -86,7 +88,9 @@ export class OpenAIModerationChain
super(fields);
this.throwError = fields?.throwError ?? false;
this.openAIApiKey =
fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");

if (!this.openAIApiKey) {
throw new Error("OpenAI API key not found");
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-azure-openai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/azure-openai",
"version": "0.0.10",
"version": "0.0.11",
"description": "Azure SDK for OpenAI integrations for LangChain.js",
"type": "module",
"engines": {
Expand Down
5 changes: 4 additions & 1 deletion libs/langchain-azure-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export interface ChatOpenAICallOptions
seed?: number;
}

/** @deprecated Import from "@langchain/openai" instead. */
export class AzureChatOpenAI
extends BaseChatModel<ChatOpenAICallOptions>
implements OpenAIChatInput, AzureOpenAIInput
Expand Down Expand Up @@ -267,7 +268,9 @@ export class AzureChatOpenAI
getEnvironmentVariable("AZURE_OPENAI_API_DEPLOYMENT_NAME");

const openAiApiKey =
fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");

this.azureOpenAIApiKey =
fields?.apiKey ??
Expand Down
5 changes: 4 additions & 1 deletion libs/langchain-azure-openai/src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { chunkArray } from "@langchain/core/utils/chunk_array";
import { AzureOpenAIInput, AzureOpenAIEmbeddingsParams } from "./types.js";
import { USER_AGENT_PREFIX } from "./constants.js";

/** @deprecated Import from "@langchain/openai" instead. */
export class AzureOpenAIEmbeddings
extends Embeddings
implements AzureOpenAIEmbeddingsParams, AzureOpenAIInput
Expand Down Expand Up @@ -62,7 +63,9 @@ export class AzureOpenAIEmbeddings
getEnvironmentVariable("AZURE_OPENAI_API_ENDPOINT");

const openAiApiKey =
fields?.openAIApiKey ?? getEnvironmentVariable("OPENAI_API_KEY");
fields?.apiKey ??
fields?.openAIApiKey ??
getEnvironmentVariable("OPENAI_API_KEY");

this.azureOpenAIApiKey =
fields?.apiKey ??
Expand Down
Loading

0 comments on commit ece478a

Please sign in to comment.