Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partners[minor]: Add standard chat model tests to partner packages #5660

Merged
merged 30 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4820bf9
partners[minor]: Add standard chat model tests to partner packages
bracesproul Jun 4, 2024
400b04b
google genai
bracesproul Jun 4, 2024
efb7f3f
yarn
bracesproul Jun 4, 2024
1510d62
groq
bracesproul Jun 4, 2024
74d2fe9
groq nit and mistral
bracesproul Jun 4, 2024
f694aad
add to azure in chat openai
bracesproul Jun 4, 2024
f9b4d85
chore: lint files
bracesproul Jun 4, 2024
5a8767e
drop azure openai pkg
bracesproul Jun 4, 2024
bdb4d55
add generic constructor args to standard tests pkg
bracesproul Jun 4, 2024
de2259c
implement cloudflare standard tests
bracesproul Jun 4, 2024
8991340
implement cohere standard tests
bracesproul Jun 4, 2024
183816c
google genai package standard tests
bracesproul Jun 4, 2024
b96008e
groq
bracesproul Jun 4, 2024
3f4a3b3
allow for custom function call ids, fix mistral
bracesproul Jun 4, 2024
ded3663
azure tests
bracesproul Jun 4, 2024
18c748e
chore: lint files
bracesproul Jun 4, 2024
20d16d2
update standard tests gh action to run all pkgs
bracesproul Jun 4, 2024
cc4f4e7
chore: lint files
bracesproul Jun 4, 2024
63de31e
revert workflow file rename
bracesproul Jun 4, 2024
c323fab
fix workflow job naming issue
bracesproul Jun 4, 2024
50971e2
add anthropic, fix api keys
bracesproul Jun 4, 2024
01573ab
cache deps?
bracesproul Jun 4, 2024
f978653
fix build
bracesproul Jun 4, 2024
ca50201
Merge branch 'main' into brace/standard-tests-partners
bracesproul Jun 4, 2024
74da454
update standard tests
bracesproul Jun 4, 2024
ee55ad9
cr
bracesproul Jun 4, 2024
31aa8f8
fix
bracesproul Jun 4, 2024
d607d2b
remove dep on job which doesnt exist
bracesproul Jun 4, 2024
4c0789b
cr
bracesproul Jun 4, 2024
e66d30e
cr
bracesproul Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions .github/workflows/standard-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ name: Standard Tests (Integration)
on:
workflow_dispatch:
schedule:
- cron: '0 13 * * *'
- cron: '0 13 * * *'

jobs:
openai:
standard-tests:
runs-on: ubuntu-latest
strategy:
matrix:
package: [anthropic, cohere, google-genai, groq, mistralai]
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
Expand All @@ -17,7 +20,53 @@ jobs:
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
- name: Run standard tests (integration)
run: yarn test:standard:int --filter=@langchain/openai
- name: Run standard tests (integration) for ${{ matrix.package }}
run: yarn test:standard:int --filter=@langchain/${{ matrix.package }}
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}

# The `@langchain/openai` package contains standard tests for ChatOpenAI and AzureChatOpenAI
# We want to run these separately, so we need to pass the exact path for each test, which means
# we need separate jobs for each test.
standard-tests-openai:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
- name: Build `@langchain/openai`
run: yarn build --filter=@langchain/openai
- name: Run standard tests (integration) for ChatOpenAI
run: yarn workspace @langchain/openai test:single src/tests/chat_models.standard.int.test.ts
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

standard-tests-azure-openai:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
- name: Build `@langchain/openai`
run: yarn build --filter=@langchain/openai
- name: Run standard tests (integration) for `@langchain/openai` AzureChatOpenAI
run: yarn workspace @langchain/openai test:single src/tests/azure/chat_models.standard.int.test.ts
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_API_DEPLOYMENT_NAME: "chat"
AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_BASE_PATH: ${{ secrets.AZURE_OPENAI_BASE_PATH }}
17 changes: 5 additions & 12 deletions libs/langchain-azure-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,18 @@
"scripts": {
"build": "yarn turbo:command build:internal --filter=@langchain/azure-openai",
"build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking",
"build:deps": "yarn run turbo:command build --filter=@langchain/core",
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/",
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
"build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
"build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
"lint": "yarn lint:eslint && yarn lint:dpdm",
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
"clean": "rm -rf .turbo dist/",
"prepack": "yarn build",
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"format": "prettier --config .prettierrc --write \"src\"",
"format:check": "prettier --config .prettierrc --check \"src\"",
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
"create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
"check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
"format:check": "prettier --config .prettierrc --check \"src\""
},
"author": "LangChain",
"license": "MIT",
Expand All @@ -50,6 +42,7 @@
"@azure/identity": "^4.0.1",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! 👋 I noticed that this PR adds a new dependency "@langchain/standard-tests". This comment is just to flag this change for the maintainers to review, in case it affects any peer/dev/hard dependencies. Keep up the great work! 🚀

"@jest/globals": "^29.5.0",
"@langchain/scripts": "~0.0.14",
"@langchain/standard-tests": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"dpdm": "^3.12.0",
Expand Down
13 changes: 5 additions & 8 deletions libs/langchain-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"scripts": {
"build": "yarn turbo:command build:internal --filter=@langchain/cloudflare",
"build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking",
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests",
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs",
"build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
"build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
"lint": "yarn lint:eslint && yarn lint:dpdm",
Expand All @@ -30,11 +26,11 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard": "yarn test:standard:unit && yarn test:standard:int",
"format": "prettier --config .prettierrc --write \"src\"",
"format:check": "prettier --config .prettierrc --check \"src\"",
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
"create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
"check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
"format:check": "prettier --config .prettierrc --check \"src\""
},
"author": "LangChain",
"license": "MIT",
Expand All @@ -47,6 +43,7 @@
"@cloudflare/workers-types": "^4.20231218.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! 👋 Just wanted to flag that the addition of "@langchain/standard-tests" as a dependency in the package.json file might impact the dev dependencies of the project. This is for the maintainers to review and ensure it aligns with the project's requirements. Thank you!

"@jest/globals": "^29.5.0",
"@langchain/scripts": "~0.0.14",
"@langchain/standard-tests": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
Expand Down
10 changes: 10 additions & 0 deletions libs/langchain-cloudflare/src/chat_models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
LangSmithParams,
SimpleChatModel,
type BaseChatModelParams,
} from "@langchain/core/language_models/chat_models";
Expand Down Expand Up @@ -81,6 +82,15 @@ export class ChatCloudflareWorkersAI
}
}

getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
return {
ls_provider: "openai",
ls_model_name: this.model,
ls_model_type: "chat",
ls_stop: options.stop,
};
}

get lc_secrets(): { [key: string]: string } | undefined {
return {
cloudflareApiToken: "CLOUDFLARE_API_TOKEN",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-process-env */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey team, just a heads up that I've flagged the latest change in the PR for review. It includes explicit checks for environment variables using process.env, so it's important for maintainers to take a look. Keep up the great work!

import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import {
ChatCloudflareWorkersAI,
ChatCloudflareWorkersAICallOptions,
} from "../chat_models.js";

class ChatCloudflareWorkersAIStandardIntegrationTests extends ChatModelIntegrationTests<
ChatCloudflareWorkersAICallOptions,
AIMessageChunk
> {
constructor() {
if (
!process.env.CLOUDFLARE_ACCOUNT_ID ||
!process.env.CLOUDFLARE_API_TOKEN
) {
throw new Error(
"Skipping Cloudflare Workers AI integration tests because CLOUDFLARE_ACCOUNT_ID or CLOUDFLARE_API_TOKEN is not set"
);
}
super({
Cls: ChatCloudflareWorkersAI,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
}

async testUsageMetadataStreaming() {
this.skipTestMessage(
"testUsageMetadataStreaming",
"ChatCloudflareWorkersAI",
"Streaming tokens is not currently supported."
);
}

async testUsageMetadata() {
this.skipTestMessage(
"testUsageMetadata",
"ChatCloudflareWorkersAI",
"Usage metadata tokens is not currently supported."
);
}
}

const testClass = new ChatCloudflareWorkersAIStandardIntegrationTests();

test("ChatCloudflareWorkersAIStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
50 changes: 50 additions & 0 deletions libs/langchain-cloudflare/src/tests/chat_models.standard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { LangSmithParams } from "@langchain/core/language_models/chat_models";
import {
ChatCloudflareWorkersAI,
ChatCloudflareWorkersAICallOptions,
} from "../chat_models.js";

class ChatCloudflareWorkersAIStandardUnitTests extends ChatModelUnitTests<
ChatCloudflareWorkersAICallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatCloudflareWorkersAI,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
}

testChatModelInitApiKey() {
this.skipTestMessage(
"testChatModelInitApiKey",
"ChatCloudflareWorkersAI",
this.multipleApiKeysRequiredMessage
);
}

expectedLsParams(): Partial<LangSmithParams> {
console.warn(
"Overriding testStandardParams. ChatCloudflareWorkersAI does not support temperature or max tokens."
);
return {
ls_provider: "string",
ls_model_name: "string",
ls_model_type: "chat",
ls_stop: ["Array<string>"],
};
}
}

const testClass = new ChatCloudflareWorkersAIStandardUnitTests();

test("ChatCloudflareWorkersAIStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
13 changes: 5 additions & 8 deletions libs/langchain-cohere/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"scripts": {
"build": "yarn turbo:command build:internal --filter=@langchain/cohere",
"build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking",
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests",
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs",
"build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
"build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
"lint": "yarn lint:eslint && yarn lint:dpdm",
Expand All @@ -30,11 +26,11 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard": "yarn test:standard:unit && yarn test:standard:int",
"format": "prettier --config .prettierrc --write \"src\"",
"format:check": "prettier --config .prettierrc --check \"src\"",
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
"create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
"check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
"format:check": "prettier --config .prettierrc --check \"src\""
},
"author": "LangChain",
"license": "MIT",
Expand All @@ -45,6 +41,7 @@
"devDependencies": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! I noticed that a new devDependency "@langchain/standard-tests" has been added to the package.json file. This change is being flagged for your review to ensure it aligns with the project's dependency management strategy. Keep up the great work!

"@jest/globals": "^29.5.0",
"@langchain/scripts": "~0.0.14",
"@langchain/standard-tests": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-cohere/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface TokenUsage {
totalTokens?: number;
}

interface CohereChatCallOptions
export interface CohereChatCallOptions
extends BaseLanguageModelCallOptions,
Partial<Omit<Cohere.ChatRequest, "message">>,
Partial<Omit<Cohere.ChatStreamRequest, "message">> {}
Expand Down
47 changes: 47 additions & 0 deletions libs/langchain-cohere/src/tests/chat_models.standard.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-process-env */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey team, just a heads up that I've flagged the latest change in the PR for your review. It looks like the code is explicitly accessing the COHERE_API_KEY environment variable using process.env, so it's important to ensure this is handled correctly. Let me know if you need any further assistance with this.

import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatCohere, CohereChatCallOptions } from "../chat_models.js";

class ChatCohereStandardIntegrationTests extends ChatModelIntegrationTests<
CohereChatCallOptions,
AIMessageChunk
> {
constructor() {
if (!process.env.COHERE_API_KEY) {
throw new Error(
"Can not run Cohere integration tests because COHERE_API_KEY is not set"
);
}
super({
Cls: ChatCohere,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
}

async testUsageMetadataStreaming() {
this.skipTestMessage(
"testUsageMetadataStreaming",
"ChatCohere",
"Streaming tokens is not currently supported."
);
}

async testUsageMetadata() {
this.skipTestMessage(
"testUsageMetadata",
"ChatCohere",
"Usage metadata tokens is not currently supported."
);
}
}

const testClass = new ChatCohereStandardIntegrationTests();

test("ChatCohereStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
Loading
Loading