diff --git a/libs/langchain-community/package.json b/libs/langchain-community/package.json index ee6b54930c36..c38b10e992de 100644 --- a/libs/langchain-community/package.json +++ b/libs/langchain-community/package.json @@ -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", @@ -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", diff --git a/libs/langchain-community/src/chat_models/bedrock/web.ts b/libs/langchain-community/src/chat_models/bedrock/web.ts index abf10fe0c208..7021d811f99b 100644 --- a/libs/langchain-community/src/chat_models/bedrock/web.ts +++ b/libs/langchain-community/src/chat_models/bedrock/web.ts @@ -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 { @@ -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"], diff --git a/libs/langchain-community/src/chat_models/tests/chatbedrock.standard.test.ts b/libs/langchain-community/src/chat_models/tests/chatbedrock.standard.test.ts new file mode 100644 index 000000000000..fb90fe3f32b5 --- /dev/null +++ b/libs/langchain-community/src/chat_models/tests/chatbedrock.standard.test.ts @@ -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); +}); diff --git a/libs/langchain-community/src/chat_models/tests/chatfireworks.standard.test.ts b/libs/langchain-community/src/chat_models/tests/chatfireworks.standard.test.ts new file mode 100644 index 000000000000..bde920910676 --- /dev/null +++ b/libs/langchain-community/src/chat_models/tests/chatfireworks.standard.test.ts @@ -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); +}); diff --git a/yarn.lock b/yarn.lock index c39f5664dabd..380161ccb226 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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