Skip to content

Commit 37e0e4f

Browse files
committed
- Add langchain-oracle-js
1 parent 28bf80c commit 37e0e4f

26 files changed

+2643
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2023 LangChain
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# @langchain/cohere
2+
3+
This package contains the LangChain.js integrations for Cohere through their SDK.
4+
5+
## Installation
6+
7+
```bash npm2yarn
8+
npm install @langchain/cohere @langchain/core
9+
```
10+
11+
This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
12+
If you are using this package with other LangChain packages, you should make sure that all of the packages depend on the same instance of @langchain/core.
13+
You can do so by adding appropriate field to your project's `package.json` like this:
14+
15+
```json
16+
{
17+
"name": "your-project",
18+
"version": "0.0.0",
19+
"dependencies": {
20+
"@langchain/cohere": "^0.0.1",
21+
"@langchain/core": "^0.3.0",
22+
},
23+
"resolutions": {
24+
"@langchain/core": "0.3.0"
25+
},
26+
"overrides": {
27+
"@langchain/core": "0.3.0"
28+
},
29+
"pnpm": {
30+
"overrides": {
31+
"@langchain/core": "0.3.0"
32+
}
33+
}
34+
}
35+
```
36+
37+
The field you need depends on the package manager you're using, but we recommend adding a field for the common `yarn`, `npm`, and `pnpm` to maximize compatibility.
38+
39+
## Chat Models
40+
41+
This package contains the `ChatCohere` class, which is the recommended way to interface with the Cohere series of models.
42+
43+
To use, install the requirements, and configure your environment.
44+
45+
```bash
46+
export COHERE_API_KEY=your-api-key
47+
```
48+
49+
Then initialize
50+
51+
```typescript
52+
import { HumanMessage } from "@langchain/core/messages";
53+
import { ChatCohere } from "@langchain/cohere";
54+
55+
const model = new ChatCohere({
56+
apiKey: process.env.COHERE_API_KEY,
57+
});
58+
const response = await model.invoke([new HumanMessage("Hello world!")]);
59+
```
60+
61+
### Streaming
62+
63+
```typescript
64+
import { HumanMessage } from "@langchain/core/messages";
65+
import { ChatCohere } from "@langchain/cohere";
66+
67+
const model = new ChatCohere({
68+
apiKey: process.env.COHERE_API_KEY,
69+
});
70+
const response = await model.stream([new HumanMessage("Hello world!")]);
71+
```
72+
73+
## Embeddings
74+
75+
This package also adds support for `CohereEmbeddings` embeddings model.
76+
77+
```typescript
78+
import { ChatCohere } from "@langchain/cohere";
79+
80+
const embeddings = new ChatCohere({
81+
apiKey: process.env.COHERE_API_KEY,
82+
});
83+
const res = await embeddings.embedQuery("Hello world");
84+
```
85+
86+
## Development
87+
88+
To develop the `@langchain/cohere` package, you'll need to follow these instructions:
89+
90+
### Install dependencies
91+
92+
```bash
93+
yarn install
94+
```
95+
96+
### Build the package
97+
98+
```bash
99+
yarn build
100+
```
101+
102+
Or from the repo root:
103+
104+
```bash
105+
yarn build --filter=@langchain/cohere
106+
```
107+
108+
### Run tests
109+
110+
Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
111+
end in `.int.test.ts`:
112+
113+
```bash
114+
$ yarn test
115+
$ yarn test:int
116+
```
117+
118+
### Lint & Format
119+
120+
Run the linter & formatter to ensure your code is up to standard:
121+
122+
```bash
123+
yarn lint && yarn format
124+
```
125+
126+
### Adding new entrypoints
127+
128+
If you add a new file to be exported, either import & re-export from `src/index.ts`, or add it to the `entrypoints` field in the `config` variable located inside `langchain.config.js` and run `yarn build` to generate the new entrypoint.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest/presets/default-esm",
4+
testEnvironment: "./jest.env.cjs",
5+
modulePathIgnorePatterns: ["dist/", "docs/"],
6+
moduleNameMapper: {
7+
"^(\\.{1,2}/.*)\\.js$": "$1",
8+
},
9+
transform: {
10+
"^.+\\.tsx?$": ["@swc/jest"],
11+
},
12+
transformIgnorePatterns: [
13+
"/node_modules/",
14+
"\\.pnp\\.[^\\/]+$",
15+
"./scripts/jest-setup-after-env.js",
16+
],
17+
setupFiles: ["dotenv/config"],
18+
testTimeout: 20_000,
19+
passWithNoTests: true,
20+
collectCoverageFrom: ["src/**/*.ts"],
21+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { TestEnvironment } = require("jest-environment-node");
2+
3+
class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment {
4+
constructor(config, context) {
5+
// Make `instanceof Float32Array` return true in tests
6+
// to avoid https://github.com/xenova/transformers.js/issues/57 and https://github.com/jestjs/jest/issues/2549
7+
super(config, context);
8+
this.global.Float32Array = Float32Array;
9+
}
10+
}
11+
12+
module.exports = AdjustedTestEnvironmentToSupportFloat32Array;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { resolve, dirname } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
4+
/**
5+
* @param {string} relativePath
6+
* @returns {string}
7+
*/
8+
function abs(relativePath) {
9+
return resolve(dirname(fileURLToPath(import.meta.url)), relativePath);
10+
}
11+
12+
13+
export const config = {
14+
internals: [/node\:/, /@langchain\/core\//],
15+
entrypoints: {
16+
index: "index",
17+
},
18+
tsConfigPath: resolve("./tsconfig.json"),
19+
cjsSource: "./dist-cjs",
20+
cjsDestination: "./dist",
21+
abs,
22+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"name": "@langchain/oracle",
3+
"version": "0.3.1",
4+
"description": "Oracle integration for LangChain.js",
5+
"type": "module",
6+
"engines": {
7+
"node": ">=18"
8+
},
9+
"main": "./index.js",
10+
"types": "./index.d.ts",
11+
"repository": {
12+
"type": "git",
13+
"url": "[email protected]:langchain-ai/langchainjs.git"
14+
},
15+
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-oracle/",
16+
"scripts": {
17+
"build": "turbo build:compile --filter @langchain/oracle",
18+
"build:compile": "pnpm --filter @langchain/build compile @langchain/oracle",
19+
"lint:eslint": "eslint --cache src/",
20+
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
21+
"lint": "pnpm lint:eslint && pnpm lint:dpdm",
22+
"lint:fix": "pnpm lint:eslint --fix && pnpm lint:dpdm",
23+
"clean": "rm -rf .turbo dist/",
24+
"test": "vitest run",
25+
"test:watch": "vitest",
26+
"test:int": "vitest run --mode int",
27+
"test:standard:unit": "vitest run --mode standard-unit",
28+
"test:standard:int": "vitest run --mode standard-int",
29+
"test:standard": "pnpm test:standard:unit && pnpm test:standard:int",
30+
"format": "prettier --config .prettierrc --write \"src\"",
31+
"format:check": "prettier --config .prettierrc --check \"src\""
32+
},
33+
"author": "LangChain",
34+
"license": "MIT",
35+
"dependencies": {
36+
"htmlparser2": "^10.0.0",
37+
"oracledb": "^6.6.0",
38+
"uuid": "^10.0.0"
39+
},
40+
"peerDependencies": {
41+
"@langchain/core": "^1.0.0",
42+
"@langchain/textsplitters": "^1.0.0"
43+
},
44+
"devDependencies": {
45+
"@cfworker/json-schema": "^4.1.1",
46+
"@jest/globals": "^29.5.0",
47+
"@langchain/core": "workspace:*",
48+
"@langchain/eslint": "workspace:*",
49+
"@langchain/standard-tests": "workspace:*",
50+
"@langchain/textsplitters": "workspace:*",
51+
"@swc/jest": "^0.2.29",
52+
"@tsconfig/recommended": "^1.0.3",
53+
"@types/oracledb": "^6.6.0",
54+
"@vitest/coverage-v8": "^3.2.4",
55+
"dotenv": "^16.6.1",
56+
"dpdm": "^3.14.0",
57+
"eslint": "^9.34.0",
58+
"jest": "^29.5.0",
59+
"jest-environment-node": "^29.6.4",
60+
"prettier": "^2.8.3",
61+
"rollup": "^4.5.2",
62+
"ts-jest": "^29.1.0",
63+
"typescript": "~5.8.3",
64+
"vitest": "^3.2.4",
65+
"zod": "^3.25.76"
66+
},
67+
"publishConfig": {
68+
"access": "public"
69+
},
70+
"exports": {
71+
".": {
72+
"types": {
73+
"import": "./index.d.ts",
74+
"require": "./index.d.cts",
75+
"default": "./index.d.ts"
76+
},
77+
"import": "./index.js",
78+
"require": "./index.cjs"
79+
},
80+
"./package.json": "./package.json"
81+
},
82+
"files": [
83+
"dist/",
84+
"index.cjs",
85+
"index.js",
86+
"index.d.ts",
87+
"index.d.cts"
88+
]
89+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";
2+
import { afterAll, jest } from "@jest/globals";
3+
4+
afterAll(awaitAllCallbacks);
5+
6+
// Allow console.log to be disabled in tests
7+
if (process.env.DISABLE_CONSOLE_LOGS === "true") {
8+
console.log = jest.fn();
9+
}

0 commit comments

Comments
 (0)