Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
8d8fac1
community[minor]: Add standard tests to community chat models
bracesproul Jun 4, 2024
77111c7
Merge branch 'main' into brace/standard-tests-community
bracesproul Jun 4, 2024
b2367b9
integration tests
bracesproul Jun 5, 2024
2a1af54
chore: lint files
bracesproul Jun 5, 2024
404fdae
Merge branch 'main' into brace/standard-tests-community
bracesproul Jun 5, 2024
d7f7d45
add bedrock test
bracesproul Jun 5, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/standard-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,23 @@ jobs:
AZURE_OPENAI_API_DEPLOYMENT_NAME: "chat"
AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_BASE_PATH: ${{ secrets.AZURE_OPENAI_BASE_PATH }}

standard-tests-bedrock:
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/community`
run: yarn build --filter=@langchain/community
- name: Run standard tests (integration) for `@langchain/community` BedrockChat
run: yarn workspace @langchain/community test:single src/chat_models/tests/chatbedrock.standard.int.test.ts
env:
BEDROCK_AWS_REGION: "us-east-1"
BEDROCK_AWS_SECRET_ACCESS_KEY: ${{ secrets.BEDROCK_AWS_SECRET_ACCESS_KEY }}
BEDROCK_AWS_ACCESS_KEY_ID: ${{ secrets.BEDROCK_AWS_ACCESS_KEY_ID }}
22 changes: 9 additions & 13 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,21 @@
"scripts": {
"build": "yarn turbo:command build:internal --filter=@langchain/community",
"build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking --gen-maps",
"build:deps": "yarn run turbo:command build --filter=@langchain/core --filter=@langchain/openai --filter=langchain --filter=@langchain/anthropic --concurrency=1",
"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",
"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:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"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%",
"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 Down Expand Up @@ -84,6 +79,7 @@
"@huggingface/inference": "^2.6.4",
"@jest/globals": "^29.5.0",
"@langchain/scripts": "~0.0.14",
"@langchain/standard-tests": "workspace:*",
"@layerup/layerup-security": "^1.5.12",
"@mendable/firecrawl-js": "^0.0.13",
"@mlc-ai/web-llm": "^0.2.40",
Expand Down
13 changes: 13 additions & 0 deletions libs/langchain-community/src/chat_models/bedrock/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
import {
type BaseChatModelParams,
BaseChatModel,
LangSmithParams,
} from "@langchain/core/language_models/chat_models";
import { getEnvironmentVariable } from "@langchain/core/utils/env";
import {
Expand Down Expand Up @@ -305,6 +306,18 @@ export class BedrockChat extends BaseChatModel implements BaseBedrockInput {
this.guardrailConfig = fields?.guardrailConfig;
}

getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "bedrock",
ls_model_name: this.model,
ls_model_type: "chat",
ls_temperature: params.temperature ?? undefined,
ls_max_tokens: params.max_tokens ?? undefined,
ls_stop: options.stop,
};
}

async _generate(
messages: BaseMessage[],
options: Partial<BaseChatModelParams>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 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.

Great work on the PR! I've noticed that the code explicitly accesses environment variables using process.env, so I've flagged this for maintainers to review. Keep up the good work!

import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
import { BedrockChat } from "../bedrock/index.js";

class BedrockChatStandardIntegrationTests extends ChatModelIntegrationTests<
BaseChatModelCallOptions,
AIMessageChunk
> {
constructor() {
const region = process.env.BEDROCK_AWS_REGION ?? "us-east-1";
super({
Cls: BedrockChat,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {
region,
model: "amazon.titan-text-express-v1",
credentials: {
secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY,
accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID,
},
},
});
}

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

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

const testClass = new BedrockChatStandardIntegrationTests();

test("BedrockChatStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* 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 there! I've noticed that this PR includes changes that explicitly access and set environment variables using process.env. I've flagged this for the maintainers to review and ensure that the handling of environment variables aligns with best practices. Great work on the PR!

import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
import { BedrockChat } from "../bedrock/index.js";

class BedrockChatStandardUnitTests extends ChatModelUnitTests<
BaseChatModelCallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: BedrockChat,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
process.env.BEDROCK_AWS_SECRET_ACCESS_KEY = "test";
process.env.BEDROCK_AWS_ACCESS_KEY_ID = "test";
process.env.BEDROCK_AWS_SESSION_TOKEN = "test";
process.env.AWS_DEFAULT_REGION = "us-east-1";
}

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

const testClass = new BedrockChatStandardUnitTests();

test("BedrockChatStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatFireworks, ChatFireworksCallOptions } from "../fireworks.js";

class ChatFireworksStandardIntegrationTests extends ChatModelIntegrationTests<
ChatFireworksCallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatFireworks,
chatModelHasToolCalling: true,
chatModelHasStructuredOutput: true,
constructorArgs: {
model: "accounts/fireworks/models/firefunction-v1",
},
});
}

async testToolMessageHistoriesListContent() {
this.skipTestMessage(
"testToolMessageHistoriesListContent",
"ChatFireworks",
"Not implemented."
);
}
}

const testClass = new ChatFireworksStandardIntegrationTests();

test("ChatFireworksStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* 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, I've reviewed the code and noticed that the addition of environment variable manipulation via process.env in this PR. I've flagged this for your attention to ensure it aligns with our best practices. Keep up the great work!

import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatFireworks, ChatFireworksCallOptions } from "../fireworks.js";

class ChatFireworksStandardUnitTests extends ChatModelUnitTests<
ChatFireworksCallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatFireworks,
chatModelHasToolCalling: true,
chatModelHasStructuredOutput: true,
constructorArgs: {},
});
process.env.FIREWORKS_API_KEY = "test";
}

testChatModelInitApiKey() {
// Unset the API key env var here so this test can properly check
// the API key class arg.
process.env.FIREWORKS_API_KEY = "";
super.testChatModelInitApiKey();
// Re-set the API key env var here so other tests can run properly.
process.env.FIREWORKS_API_KEY = "test";
}
}

const testClass = new ChatFireworksStandardUnitTests();

test("ChatFireworksStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatOllama, ChatOllamaCallOptions } from "../ollama.js";

class ChatOllamaStandardUnitTests extends ChatModelUnitTests<
ChatOllamaCallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatOllama,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
}

testChatModelInitApiKey() {
this.skipTestMessage(
"testChatModelInitApiKey",
"ChatOllama",
"API key not required."
);
}
}

const testClass = new ChatOllamaStandardUnitTests();

test("ChatOllamaStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatTogetherAI, ChatTogetherAICallOptions } from "../togetherai.js";

class ChatTogetherAIStandardIntegrationTests extends ChatModelIntegrationTests<
ChatTogetherAICallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatTogetherAI,
chatModelHasToolCalling: true,
chatModelHasStructuredOutput: true,
constructorArgs: {},
});
}
}

const testClass = new ChatTogetherAIStandardIntegrationTests();

test("ChatTogetherAIStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* 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 as it explicitly adds and accesses environment variables via process.env. It's always good to double-check these changes for security and best practices. Keep up the great work!

import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatTogetherAI, ChatTogetherAICallOptions } from "../togetherai.js";

class ChatTogetherAIStandardUnitTests extends ChatModelUnitTests<
ChatTogetherAICallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatTogetherAI,
chatModelHasToolCalling: false,
chatModelHasStructuredOutput: false,
constructorArgs: {},
});
process.env.TOGETHER_AI_API_KEY = "test";
}

testChatModelInitApiKey() {
// Unset the API key env var here so this test can properly check
// the API key class arg.
process.env.TOGETHER_AI_API_KEY = "";
super.testChatModelInitApiKey();
// Re-set the API key env var here so other tests can run properly.
process.env.TOGETHER_AI_API_KEY = "test";
}
}

const testClass = new ChatTogetherAIStandardUnitTests();

test("ChatTogetherAIStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9101,6 +9101,7 @@ __metadata:
"@langchain/core": ~0.2.0
"@langchain/openai": ~0.1.0
"@langchain/scripts": ~0.0.14
"@langchain/standard-tests": "workspace:*"
"@layerup/layerup-security": ^1.5.12
"@mendable/firecrawl-js": ^0.0.13
"@mlc-ai/web-llm": ^0.2.40
Expand Down