Skip to content

Commit ef9b85c

Browse files
authored
google-vertexai[minor] Add standard tests (#5721)
* google-vertexai[minor] Add standard tests * moved tests to vertex * fixed tests * fixed latest/lowest ci * chore: lint files * chore: lint files
1 parent 3bc9b8e commit ef9b85c

File tree

18 files changed

+244
-822
lines changed

18 files changed

+244
-822
lines changed

.github/workflows/compatibility.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ jobs:
152152
- name: Test `@langchain/anthropic` with lowest deps
153153
run: docker compose -f dependency_range_tests/docker-compose.yml run anthropic-lowest-deps
154154

155-
# VertexAI
156-
vertexai-latest-deps:
155+
# Google VertexAI
156+
google-vertexai-latest-deps:
157157
runs-on: ubuntu-latest
158158
steps:
159159
- uses: actions/checkout@v4
@@ -162,10 +162,14 @@ jobs:
162162
with:
163163
node-version: ${{ env.NODE_VERSION }}
164164
cache: "yarn"
165+
- name: Install dependencies
166+
run: yarn install --immutable
167+
- name: Build `@langchain/standard-tests`
168+
run: yarn build --filter=@langchain/standard-tests
165169
- name: Test `@langchain/google-vertexai` with latest deps
166-
run: docker compose -f dependency_range_tests/docker-compose.yml run vertexai-latest-deps
170+
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-latest-deps
167171

168-
vertexai-lowest-deps:
172+
google-vertexai-lowest-deps:
169173
runs-on: ubuntu-latest
170174
steps:
171175
- uses: actions/checkout@v4
@@ -174,5 +178,9 @@ jobs:
174178
with:
175179
node-version: ${{ env.NODE_VERSION }}
176180
cache: "yarn"
181+
- name: Install dependencies
182+
run: yarn install --immutable
183+
- name: Build `@langchain/standard-tests`
184+
run: yarn build --filter=@langchain/standard-tests
177185
- name: Test `@langchain/google-vertexai` with lowest deps
178-
run: docker compose -f dependency_range_tests/docker-compose.yml run vertexai-lowest-deps
186+
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps

dependency_range_tests/docker-compose.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,32 @@ services:
114114
- ./scripts:/scripts
115115
command: bash /scripts/with_standard_tests/anthropic/test-with-lowest-deps.sh
116116

117-
# VertexAI
118-
vertexai-latest-deps:
117+
# Google VertexAI
118+
google-vertexai-latest-deps:
119119
image: node:18
120120
environment:
121121
PUPPETEER_SKIP_DOWNLOAD: "true"
122122
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
123+
COHERE_API_KEY: ${COHERE_API_KEY}
123124
working_dir: /app
124125
volumes:
126+
- ../turbo.json:/turbo.json
127+
- ../package.json:/package.json
128+
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
125129
- ../libs/langchain-google-vertexai:/libs/langchain-google-vertexai
126130
- ./scripts:/scripts
127-
command: bash /scripts/vertexai/test-with-latest-deps.sh
128-
vertexai-lowest-deps:
131+
command: bash /scripts/with_standard_tests/google-vertexai/test-with-latest-deps.sh
132+
google-vertexai-lowest-deps:
129133
image: node:18
130134
environment:
131135
PUPPETEER_SKIP_DOWNLOAD: "true"
132136
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
137+
COHERE_API_KEY: ${COHERE_API_KEY}
133138
working_dir: /app
134139
volumes:
140+
- ../turbo.json:/turbo.json
141+
- ../package.json:/package.json
142+
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
135143
- ../libs/langchain-google-vertexai:/libs/langchain-google-vertexai
136144
- ./scripts:/scripts
137-
command: bash /scripts/vertexai/test-with-lowest-deps.sh
138-
145+
command: bash /scripts/with_standard_tests/google-vertexai/test-with-lowest-deps.sh

dependency_range_tests/scripts/vertexai/test-with-latest-deps.sh

-16
This file was deleted.

dependency_range_tests/scripts/vertexai/test-with-lowest-deps.sh

-27
This file was deleted.

dependency_range_tests/scripts/vertexai/node/update_resolutions_lowest.js renamed to dependency_range_tests/scripts/with_standard_tests/google-vertexai/node/update_resolutions_lowest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require("fs");
22
const semver = require("semver");
33

4-
const communityPackageJsonPath = "package.json";
4+
const communityPackageJsonPath = "/app/monorepo/libs/langchain-google-vertexai/package.json";
55

66
const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
export CI=true
6+
7+
# New monorepo directory paths
8+
monorepo_dir="/app/monorepo"
9+
monorepo_openai_dir="/app/monorepo/libs/langchain-google-vertexai"
10+
11+
# Run the shared script to copy all necessary folders/files
12+
bash /scripts/with_standard_tests/shared.sh google-vertexai
13+
14+
# Navigate back to monorepo root and install dependencies
15+
cd "$monorepo_dir"
16+
yarn
17+
18+
# Navigate into `@langchain/google-vertexai` to build and run tests
19+
# We need to run inside the google-vertexai directory so turbo repo does
20+
# not try to build the package/its workspace dependencies.
21+
cd "$monorepo_openai_dir"
22+
yarn test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
export CI=true
6+
7+
monorepo_dir="/app/monorepo"
8+
monorepo_openai_dir="/app/monorepo/libs/langchain-google-vertexai"
9+
updater_script_dir="/app/updater_script"
10+
updater_script_dir="/app/updater_script"
11+
original_updater_script_dir="/scripts/with_standard_tests/google-vertexai/node"
12+
13+
# Run the shared script to copy all necessary folders/files
14+
bash /scripts/with_standard_tests/shared.sh google-vertexai
15+
16+
# Copy the updater script to the monorepo
17+
mkdir -p "$updater_script_dir"
18+
cp "$original_updater_script_dir"/* "$updater_script_dir/"
19+
20+
# Install deps (e.g semver) for the updater script
21+
cd "$updater_script_dir"
22+
yarn
23+
# Run the updater script
24+
node "update_resolutions_lowest.js"
25+
26+
27+
# Navigate back to monorepo root and install dependencies
28+
cd "$monorepo_dir"
29+
yarn
30+
31+
# Navigate into `@langchain/package` to build and run tests
32+
# We need to run inside the package directory so turbo repo does
33+
# not try to build the package/its workspace dependencies.
34+
cd "$monorepo_openai_dir"
35+
yarn test

libs/langchain-google-gauth/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"devDependencies": {
4343
"@jest/globals": "^29.5.0",
4444
"@langchain/scripts": "~0.0.14",
45-
"@langchain/standard-tests": "0.0.0",
4645
"@swc/core": "^1.3.90",
4746
"@swc/jest": "^0.2.29",
4847
"@tsconfig/recommended": "^1.0.3",

libs/langchain-google-vertexai-web/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
2828
"clean": "rm -rf .turbo dist/",
2929
"prepack": "yarn build",
30-
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
31-
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32-
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33-
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
30+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
31+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32+
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33+
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
3434
"format": "prettier --config .prettierrc --write \"src\"",
3535
"format:check": "prettier --config .prettierrc --check \"src\"",
3636
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",

libs/langchain-google-vertexai/package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
2828
"clean": "rm -rf .turbo dist/",
2929
"prepack": "yarn build",
30-
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
31-
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32-
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33-
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
30+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
31+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32+
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33+
"test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
34+
"test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
35+
"test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
36+
"test:standard": "yarn test:standard:unit && yarn test:standard:int",
3437
"format": "prettier --config .prettierrc --write \"src\"",
3538
"format:check": "prettier --config .prettierrc --check \"src\"",
3639
"move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
@@ -45,7 +48,9 @@
4548
},
4649
"devDependencies": {
4750
"@jest/globals": "^29.5.0",
51+
"@langchain/google-common": "latest",
4852
"@langchain/scripts": "~0.0.14",
53+
"@langchain/standard-tests": "0.0.0",
4954
"@swc/core": "^1.3.90",
5055
"@swc/jest": "^0.2.29",
5156
"@tsconfig/recommended": "^1.0.3",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* eslint-disable no-process-env */
2+
import { test, expect } from "@jest/globals";
3+
import { ChatModelIntegrationTests } from "@langchain/standard-tests";
4+
import { AIMessageChunk } from "@langchain/core/messages";
5+
import { GoogleAIBaseLanguageModelCallOptions } from "@langchain/google-common";
6+
import { ChatVertexAI } from "../chat_models.js";
7+
8+
class ChatVertexAIStandardIntegrationTests extends ChatModelIntegrationTests<
9+
GoogleAIBaseLanguageModelCallOptions,
10+
AIMessageChunk
11+
> {
12+
constructor() {
13+
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
14+
throw new Error(
15+
"GOOGLE_APPLICATION_CREDENTIALS must be set to run standard integration tests."
16+
);
17+
}
18+
super({
19+
Cls: ChatVertexAI,
20+
chatModelHasToolCalling: true,
21+
chatModelHasStructuredOutput: true,
22+
constructorArgs: {
23+
model: "gemini-1.5-pro",
24+
},
25+
});
26+
}
27+
28+
async testUsageMetadataStreaming() {
29+
this.skipTestMessage(
30+
"testUsageMetadataStreaming",
31+
"ChatVertexAI",
32+
"Streaming tokens is not currently supported."
33+
);
34+
}
35+
36+
async testUsageMetadata() {
37+
this.skipTestMessage(
38+
"testUsageMetadata",
39+
"ChatVertexAI",
40+
"Usage metadata tokens is not currently supported."
41+
);
42+
}
43+
44+
async testToolMessageHistoriesListContent() {
45+
this.skipTestMessage(
46+
"testToolMessageHistoriesListContent",
47+
"ChatVertexAI",
48+
"Not implemented."
49+
);
50+
}
51+
}
52+
53+
const testClass = new ChatVertexAIStandardIntegrationTests();
54+
55+
test("ChatVertexAIStandardIntegrationTests", async () => {
56+
const testResults = await testClass.runTests();
57+
expect(testResults).toBe(true);
58+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* eslint-disable no-process-env */
2+
import { test, expect } from "@jest/globals";
3+
import { ChatModelUnitTests } from "@langchain/standard-tests";
4+
import { AIMessageChunk } from "@langchain/core/messages";
5+
import { GoogleAIBaseLanguageModelCallOptions } from "@langchain/google-common";
6+
import { ChatVertexAI } from "../chat_models.js";
7+
8+
class ChatVertexAIStandardUnitTests extends ChatModelUnitTests<
9+
GoogleAIBaseLanguageModelCallOptions,
10+
AIMessageChunk
11+
> {
12+
constructor() {
13+
super({
14+
Cls: ChatVertexAI,
15+
chatModelHasToolCalling: true,
16+
chatModelHasStructuredOutput: true,
17+
constructorArgs: {},
18+
});
19+
// This must be set so method like `.bindTools` or `.withStructuredOutput`
20+
// which we call after instantiating the model will work.
21+
// (constructor will throw if API key is not set)
22+
process.env.GOOGLE_APPLICATION_CREDENTIALS = "test";
23+
}
24+
25+
testChatModelInitApiKey() {
26+
this.skipTestMessage(
27+
"testChatModelInitApiKey",
28+
"ChatVertexAI (gauth)",
29+
this.multipleApiKeysRequiredMessage
30+
);
31+
}
32+
}
33+
34+
const testClass = new ChatVertexAIStandardUnitTests();
35+
36+
test("ChatVertexAIStandardUnitTests", () => {
37+
const testResults = testClass.runTests();
38+
expect(testResults).toBe(true);
39+
});

0 commit comments

Comments
 (0)