Skip to content

standard-tests[major], openai[minor]: Init package & add standard tests to openai #5612

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

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9dfff08
standard-tests[major]: Init package
bracesproul May 30, 2024
1b3a79b
fix build, cleanup
bracesproul May 30, 2024
968a047
base class and unit tests
bracesproul May 31, 2024
6b1c916
format n lint
bracesproul May 31, 2024
359ef3e
updates
bracesproul May 31, 2024
ebca98a
Added standard unit tests to oai and scripts, made getLsParams public
bracesproul May 31, 2024
075ac8a
yarn install
bracesproul May 31, 2024
c292da5
always include api key
bracesproul May 31, 2024
832c015
set env var instead of constructor args
bracesproul May 31, 2024
9d87163
added integration tests
bracesproul May 31, 2024
b36427b
add int tests to openai
bracesproul May 31, 2024
1967eb9
add wso tests
bracesproul May 31, 2024
c6addda
Add to root & turbo, added gh action
bracesproul May 31, 2024
40b8109
Merge branch 'main' into brace/standard-tests
bracesproul May 31, 2024
16feca5
usage metadata tests for streaming and invoke
bracesproul May 31, 2024
16400e4
Added call options arg to integration tests
bracesproul May 31, 2024
7e566a7
tmp run standard test action in pr ci
bracesproul May 31, 2024
d9ec190
remove from pr ci
bracesproul May 31, 2024
fbb379a
test moar things, add readme
bracesproul Jun 1, 2024
dbed9df
chore: lint files
bracesproul Jun 1, 2024
0cc5eff
Merge branch 'main' of https://github.com/langchain-ai/langchainjs in…
bracesproul Jun 1, 2024
b91d7fb
Merge branch 'main' of https://github.com/langchain-ai/langchainjs in…
bracesproul Jun 2, 2024
8489cd4
token usage standard tests non streaming
bracesproul Jun 2, 2024
6e53484
Merge branch 'main' into brace/standard-tests
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
23 changes: 23 additions & 0 deletions .github/workflows/standard-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Standard Tests (Integration)

on:
workflow_dispatch:
schedule:
- cron: '0 13 * * *'

jobs:
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: Run standard tests (integration)
run: yarn test:standard:int --filter=@langchain/openai
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
2 changes: 1 addition & 1 deletion langchain-core/src/language_models/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export abstract class BaseChatModel<
}
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
return {
ls_model_type: "chat",
ls_stop: options.stop,
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class ChatAnthropicMessages<
this.clientOptions = fields?.clientOptions ?? {};
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "openai",
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 @@ -146,7 +146,7 @@ export class ChatCohere<
this.streaming = fields?.streaming ?? this.streaming;
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "cohere",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/chat_models/fireworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ChatFireworks extends ChatOpenAI<ChatFireworksCallOptions> {
this.apiKey = fireworksApiKey;
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = super.getLsParams(options);
params.ls_provider = "fireworks";
return params;
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/chat_models/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class ChatOllama
this.format = fields.format;
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "ollama",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/chat_models/togetherai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ChatTogetherAI extends ChatOpenAI<ChatTogetherAICallOptions> {
});
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = super.getLsParams(options);
params.ls_provider = "together";
return params;
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-google-common/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export abstract class ChatGoogleBase<AuthOptions>
this.buildConnection(fields ?? {}, client);
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "google_vertexai",
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-google-genai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class ChatGoogleGenerativeAI
);
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
return {
ls_provider: "google_genai",
ls_model_name: this.model,
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-mistralai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class ChatMistralAI<
this.model = this.modelName;
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "mistral",
Expand Down
20 changes: 8 additions & 12 deletions libs/langchain-openai/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/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%",
"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 @@ -50,6 +45,7 @@
"@azure/identity": "^4.2.0",
"@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
2 changes: 1 addition & 1 deletion libs/langchain-openai/src/azure/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AzureChatOpenAI extends ChatOpenAI {
super(newFields);
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = super.getLsParams(options);
params.ls_provider = "azure";
return params;
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-openai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export class ChatOpenAI<
};
}

protected getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams {
const params = this.invocationParams(options);
return {
ls_provider: "openai",
Expand Down
51 changes: 51 additions & 0 deletions libs/langchain-openai/src/tests/chat_models.standard.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable no-process-env */
import { test, expect } from "@jest/globals";
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
import { AIMessageChunk } from "@langchain/core/messages";
import { ChatOpenAI, ChatOpenAICallOptions } from "../chat_models.js";

class ChatOpenAIStandardIntegrationTests extends ChatModelIntegrationTests<
ChatOpenAICallOptions,
AIMessageChunk
> {
constructor() {
if (!process.env.OPENAI_API_KEY) {
throw new Error(
"OPENAI_API_KEY must be set to run standard integration tests."
);
}
super({
Cls: ChatOpenAI,
chatModelHasToolCalling: true,
chatModelHasStructuredOutput: true,
constructorArgs: {
model: "gpt-3.5-turbo",
},
});
}

async testToolMessageHistoriesListContent() {
console.warn(
"ChatOpenAI testToolMessageHistoriesListContent test known failure. Skipping..."
);
}

async testUsageMetadataStreaming() {
// ChatOpenAI does not support streaming tokens by
// default, so we must pass in a call option to
// enable streaming tokens.
const callOptions: ChatOpenAI["ParsedCallOptions"] = {
stream_options: {
include_usage: true,
},
};
await super.testUsageMetadataStreaming(callOptions);
}
}

const testClass = new ChatOpenAIStandardIntegrationTests();

test("ChatOpenAIStandardIntegrationTests", async () => {
const testResults = await testClass.runTests();
expect(testResults).toBe(true);
});
39 changes: 39 additions & 0 deletions libs/langchain-openai/src/tests/chat_models.standard.test.ts
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 { ChatOpenAI, ChatOpenAICallOptions } from "../chat_models.js";

class ChatOpenAIStandardUnitTests extends ChatModelUnitTests<
ChatOpenAICallOptions,
AIMessageChunk
> {
constructor() {
super({
Cls: ChatOpenAI,
chatModelHasToolCalling: true,
chatModelHasStructuredOutput: true,
constructorArgs: {},
});
// This must be set so method like `.bindTools` or `.withStructuredOutput`
// which we call after instantiating the model will work.
// (constructor will throw if API key is not set)
process.env.OPENAI_API_KEY = "test";
}

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

const testClass = new ChatOpenAIStandardUnitTests();

test("ChatOpenAIStandardUnitTests", () => {
const testResults = testClass.runTests();
expect(testResults).toBe(true);
});
67 changes: 67 additions & 0 deletions libs/langchain-standard-tests/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module.exports = {
extends: [
"airbnb-base",
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
],
parserOptions: {
ecmaVersion: 12,
parser: "@typescript-eslint/parser",
project: "./tsconfig.json",
sourceType: "module",
},
plugins: ["@typescript-eslint", "no-instanceof"],
ignorePatterns: [
".eslintrc.cjs",
"scripts",
"node_modules",
"dist",
"dist-cjs",
"*.js",
"*.cjs",
"*.d.ts",
],
rules: {
"no-process-env": 2,
"no-instanceof/no-instanceof": 2,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-shadow": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
camelcase: 0,
"class-methods-use-this": 0,
"import/extensions": [2, "ignorePackages"],
"import/no-extraneous-dependencies": [
"error",
{ devDependencies: ["**/*.test.ts"] },
],
"import/no-unresolved": 0,
"import/prefer-default-export": 0,
"keyword-spacing": "error",
"max-classes-per-file": 0,
"max-len": 0,
"no-await-in-loop": 0,
"no-bitwise": 0,
"no-console": 0,
"no-restricted-syntax": 0,
"no-shadow": 0,
"no-continue": 0,
"no-void": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"no-useless-constructor": 0,
"no-return-await": 0,
"consistent-return": 0,
"no-else-return": 0,
"func-names": 0,
"no-lonely-if": 0,
"prefer-rest-params": 0,
"new-cap": ["error", { properties: false, capIsNew: false }],
},
};
7 changes: 7 additions & 0 deletions libs/langchain-standard-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
index.cjs
index.js
index.d.ts
index.d.cts
node_modules
dist
.yarn
19 changes: 19 additions & 0 deletions libs/langchain-standard-tests/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
}
10 changes: 10 additions & 0 deletions libs/langchain-standard-tests/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"github": {
"release": true,
"autoGenerate": true,
"tokenRef": "GITHUB_TOKEN_RELEASE"
},
"npm": {
"versionArgs": ["--workspaces-update=false"]
}
}
21 changes: 21 additions & 0 deletions libs/langchain-standard-tests/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2023 LangChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading
Loading