Skip to content

Commit

Permalink
community[minor]: Add standard tests to community chat models
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jun 4, 2024
1 parent e66d30e commit 8d8fac1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
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.35",
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 @@ -211,6 +212,18 @@ export class BedrockChat extends BaseChatModel implements BaseBedrockInput {
this.usesMessagesApi = canUseMessagesApi(this.model);
}

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: this["ParsedCallOptions"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelUnitTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { BedrockChat } from "../bedrock/index.js";
import { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";

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 { 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);
});
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.35
Expand Down

0 comments on commit 8d8fac1

Please sign in to comment.