Skip to content

Commit 75dd790

Browse files
authored
cohere[minor]: Fix token counts, add usage_metadata (#5732)
* cohere[minor]: Fix token counts, add usage_metadata * chore: lint files * remove skipped token usage tests from cohere standard int test * bump min core version to usage_metadata update * add streamUsage * added cohere to latest/lowest dep tests * conditionally run latest/lowest * nit * cr * cr * cr * revert * test * try just pr * cr * cr * only log files * more tests * toJson * use git to access changed files * fix if statements * fix test * unfocus jest tests and add eslint rule * add eslint-plugin-jest
1 parent ac204f8 commit 75dd790

File tree

13 files changed

+1158
-46
lines changed

13 files changed

+1158
-46
lines changed

.github/workflows/compatibility.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,40 @@ jobs:
221221
run: yarn build --filter=@langchain/standard-tests
222222
- name: Test `@langchain/google-vertexai` with lowest deps
223223
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps
224+
225+
# Cohere
226+
cohere-latest-deps:
227+
runs-on: ubuntu-latest
228+
needs: get-changed-files
229+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-cohere/')
230+
steps:
231+
- uses: actions/checkout@v4
232+
- name: Use Node.js ${{ env.NODE_VERSION }}
233+
uses: actions/setup-node@v3
234+
with:
235+
node-version: ${{ env.NODE_VERSION }}
236+
cache: "yarn"
237+
- name: Install dependencies
238+
run: yarn install --immutable
239+
- name: Build `@langchain/standard-tests`
240+
run: yarn build --filter=@langchain/standard-tests
241+
- name: Test `@langchain/cohere` with latest deps
242+
run: docker compose -f dependency_range_tests/docker-compose.yml run cohere-latest-deps
243+
244+
cohere-lowest-deps:
245+
runs-on: ubuntu-latest
246+
needs: get-changed-files
247+
if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-cohere/')
248+
steps:
249+
- uses: actions/checkout@v4
250+
- name: Use Node.js ${{ env.NODE_VERSION }}
251+
uses: actions/setup-node@v3
252+
with:
253+
node-version: ${{ env.NODE_VERSION }}
254+
cache: "yarn"
255+
- name: Install dependencies
256+
run: yarn install --immutable
257+
- name: Build `@langchain/standard-tests`
258+
run: yarn build --filter=@langchain/standard-tests
259+
- name: Test `@langchain/cohere` with lowest deps
260+
run: docker compose -f dependency_range_tests/docker-compose.yml run cohere-lowest-deps

dependency_range_tests/docker-compose.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,34 @@ services:
142142
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
143143
- ../libs/langchain-google-vertexai:/libs/langchain-google-vertexai
144144
- ./scripts:/scripts
145-
command: bash /scripts/with_standard_tests/google-vertexai/test-with-lowest-deps.sh
145+
command: bash /scripts/with_standard_tests/google-vertexai/test-with-lowest-deps.sh
146+
147+
# Cohere
148+
cohere-latest-deps:
149+
image: node:18
150+
environment:
151+
PUPPETEER_SKIP_DOWNLOAD: "true"
152+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
153+
COHERE_API_KEY: ${COHERE_API_KEY}
154+
working_dir: /app
155+
volumes:
156+
- ../turbo.json:/turbo.json
157+
- ../package.json:/package.json
158+
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
159+
- ../libs/langchain-cohere:/libs/langchain-cohere
160+
- ./scripts:/scripts
161+
command: bash /scripts/with_standard_tests/cohere/test-with-latest-deps.sh
162+
cohere-lowest-deps:
163+
image: node:18
164+
environment:
165+
PUPPETEER_SKIP_DOWNLOAD: "true"
166+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
167+
COHERE_API_KEY: ${COHERE_API_KEY}
168+
working_dir: /app
169+
volumes:
170+
- ../turbo.json:/turbo.json
171+
- ../package.json:/package.json
172+
- ../libs/langchain-standard-tests:/libs/langchain-standard-tests
173+
- ../libs/langchain-cohere:/libs/langchain-cohere
174+
- ./scripts:/scripts
175+
command: bash /scripts/with_standard_tests/cohere/test-with-lowest-deps.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "dependency-range-tests",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "Tests dependency ranges for LangChain.",
6+
"dependencies": {
7+
"semver": "^7.5.4"
8+
}
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require("fs");
2+
const semver = require("semver");
3+
4+
const communityPackageJsonPath = "/app/monorepo/libs/langchain-cohere/package.json";
5+
6+
const currentPackageJson = JSON.parse(fs.readFileSync(communityPackageJsonPath));
7+
8+
if (currentPackageJson.dependencies["@langchain/core"] && !currentPackageJson.dependencies["@langchain/core"].includes("rc")) {
9+
const minVersion = semver.minVersion(
10+
currentPackageJson.dependencies["@langchain/core"]
11+
).version;
12+
currentPackageJson.overrides = {
13+
...currentPackageJson.overrides,
14+
"@langchain/core": minVersion,
15+
};
16+
currentPackageJson.dependencies = {
17+
...currentPackageJson.dependencies,
18+
"@langchain/core": minVersion,
19+
};
20+
}
21+
22+
fs.writeFileSync(communityPackageJsonPath, JSON.stringify(currentPackageJson, null, 2));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
lru-cache@^6.0.0:
6+
version "6.0.0"
7+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
8+
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
9+
dependencies:
10+
yallist "^4.0.0"
11+
12+
semver@^7.5.4:
13+
version "7.5.4"
14+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
15+
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
16+
dependencies:
17+
lru-cache "^6.0.0"
18+
19+
yallist@^4.0.0:
20+
version "4.0.0"
21+
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
22+
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
Lines changed: 22 additions & 0 deletions
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-cohere"
10+
11+
# Run the shared script to copy all necessary folders/files
12+
bash /scripts/with_standard_tests/shared.sh cohere
13+
14+
# Navigate back to monorepo root and install dependencies
15+
cd "$monorepo_dir"
16+
yarn
17+
18+
# Navigate into `@langchain/cohere` to build and run tests
19+
# We need to run inside the cohere directory so turbo repo does
20+
# not try to build the package/its workspace dependencies.
21+
cd "$monorepo_openai_dir"
22+
yarn test
Lines changed: 35 additions & 0 deletions
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_cohere_dir="/app/monorepo/libs/langchain-cohere"
9+
updater_script_dir="/app/updater_script"
10+
updater_script_dir="/app/updater_script"
11+
original_updater_script_dir="/scripts/with_standard_tests/cohere/node"
12+
13+
# Run the shared script to copy all necessary folders/files
14+
bash /scripts/with_standard_tests/shared.sh cohere
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/cohere` to build and run tests
32+
# We need to run inside the cohere directory so turbo repo does
33+
# not try to build the package/its workspace dependencies.
34+
cd "$monorepo_cohere_dir"
35+
yarn test

libs/langchain-cohere/.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
project: "./tsconfig.json",
1212
sourceType: "module",
1313
},
14-
plugins: ["@typescript-eslint", "no-instanceof"],
14+
plugins: ["@typescript-eslint", "no-instanceof", "eslint-plugin-jest"],
1515
ignorePatterns: [
1616
".eslintrc.cjs",
1717
"scripts",
@@ -61,6 +61,7 @@ module.exports = {
6161
"func-names": 0,
6262
"no-lonely-if": 0,
6363
"prefer-rest-params": 0,
64+
'jest/no-focused-tests': 'error',
6465
"new-cap": ["error", { properties: false, capIsNew: false }],
6566
},
6667
overrides: [

libs/langchain-cohere/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"author": "LangChain",
3636
"license": "MIT",
3737
"dependencies": {
38-
"@langchain/core": ">0.1.58 <0.3.0",
39-
"cohere-ai": "^7.9.3"
38+
"@langchain/core": ">=0.2.5 <0.3.0",
39+
"cohere-ai": "^7.10.5"
4040
},
4141
"devDependencies": {
4242
"@jest/globals": "^29.5.0",
@@ -53,6 +53,7 @@
5353
"eslint-config-airbnb-base": "^15.0.0",
5454
"eslint-config-prettier": "^8.6.0",
5555
"eslint-plugin-import": "^2.27.5",
56+
"eslint-plugin-jest": "^27.6.0",
5657
"eslint-plugin-no-instanceof": "^1.0.1",
5758
"eslint-plugin-prettier": "^4.2.1",
5859
"jest": "^29.5.0",

0 commit comments

Comments
 (0)