Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions libs/js/oracledb/langchain-oracledb/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.
128 changes: 128 additions & 0 deletions libs/js/oracledb/langchain-oracledb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# @langchain/cohere

This package contains the LangChain.js integrations for Cohere through their SDK.

## Installation

```bash npm2yarn
npm install @langchain/cohere @langchain/core
```

This package, along with the main LangChain package, depends on [`@langchain/core`](https://npmjs.com/package/@langchain/core/).
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.
You can do so by adding appropriate field to your project's `package.json` like this:

```json
{
"name": "your-project",
"version": "0.0.0",
"dependencies": {
"@langchain/cohere": "^0.0.1",
"@langchain/core": "^0.3.0",
},
"resolutions": {
"@langchain/core": "0.3.0"
},
"overrides": {
"@langchain/core": "0.3.0"
},
"pnpm": {
"overrides": {
"@langchain/core": "0.3.0"
}
}
}
```

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.

## Chat Models

This package contains the `ChatCohere` class, which is the recommended way to interface with the Cohere series of models.

To use, install the requirements, and configure your environment.

```bash
export COHERE_API_KEY=your-api-key
```

Then initialize

```typescript
import { HumanMessage } from "@langchain/core/messages";
import { ChatCohere } from "@langchain/cohere";

const model = new ChatCohere({
apiKey: process.env.COHERE_API_KEY,
});
const response = await model.invoke([new HumanMessage("Hello world!")]);
```

### Streaming

```typescript
import { HumanMessage } from "@langchain/core/messages";
import { ChatCohere } from "@langchain/cohere";

const model = new ChatCohere({
apiKey: process.env.COHERE_API_KEY,
});
const response = await model.stream([new HumanMessage("Hello world!")]);
```

## Embeddings

This package also adds support for `CohereEmbeddings` embeddings model.

```typescript
import { ChatCohere } from "@langchain/cohere";

const embeddings = new ChatCohere({
apiKey: process.env.COHERE_API_KEY,
});
const res = await embeddings.embedQuery("Hello world");
```

## Development

To develop the `@langchain/cohere` package, you'll need to follow these instructions:

### Install dependencies

```bash
yarn install
```

### Build the package

```bash
yarn build
```

Or from the repo root:

```bash
yarn build --filter=@langchain/cohere
```

### Run tests

Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
end in `.int.test.ts`:

```bash
$ yarn test
$ yarn test:int
```

### Lint & Format

Run the linter & formatter to ensure your code is up to standard:

```bash
yarn lint && yarn format
```

### Adding new entrypoints

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.
21 changes: 21 additions & 0 deletions libs/js/oracledb/langchain-oracledb/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest/presets/default-esm",
testEnvironment: "./jest.env.cjs",
modulePathIgnorePatterns: ["dist/", "docs/"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.tsx?$": ["@swc/jest"],
},
transformIgnorePatterns: [
"/node_modules/",
"\\.pnp\\.[^\\/]+$",
"./scripts/jest-setup-after-env.js",
],
setupFiles: ["dotenv/config"],
testTimeout: 20_000,
passWithNoTests: true,
collectCoverageFrom: ["src/**/*.ts"],
};
12 changes: 12 additions & 0 deletions libs/js/oracledb/langchain-oracledb/jest.env.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { TestEnvironment } = require("jest-environment-node");

class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment {
constructor(config, context) {
// Make `instanceof Float32Array` return true in tests
// to avoid https://github.com/xenova/transformers.js/issues/57 and https://github.com/jestjs/jest/issues/2549
super(config, context);
this.global.Float32Array = Float32Array;
}
}

module.exports = AdjustedTestEnvironmentToSupportFloat32Array;
22 changes: 22 additions & 0 deletions libs/js/oracledb/langchain-oracledb/langchain.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";

/**
* @param {string} relativePath
* @returns {string}
*/
function abs(relativePath) {
return resolve(dirname(fileURLToPath(import.meta.url)), relativePath);
}


export const config = {
internals: [/node\:/, /@langchain\/core\//],
entrypoints: {
index: "index",
},
tsConfigPath: resolve("./tsconfig.json"),
cjsSource: "./dist-cjs",
cjsDestination: "./dist",
abs,
}
87 changes: 87 additions & 0 deletions libs/js/oracledb/langchain-oracledb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"name": "@langchain/oracle",
"version": "0.3.1",
"description": "Oracle integration for LangChain.js",
"type": "module",
"engines": {
"node": ">=18"
},
"main": "./index.js",
"types": "./index.d.ts",
"repository": {
"type": "git",
"url": "[email protected]:langchain-ai/langchainjs.git"
},
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-oracle/",
"scripts": {
"build": "tsc",
"build:compile": "tsc -p tsconfig.json",
"lint:eslint": "eslint --cache src/",
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
"lint": "pnpm lint:eslint && pnpm lint:dpdm",
"lint:fix": "pnpm lint:eslint --fix && pnpm lint:dpdm",
"clean": "rm -rf .turbo dist/",
"test": "vitest run",
"test:watch": "vitest",
"test:int": "vitest run --mode int",
"test:standard:unit": "vitest run --mode standard-unit",
"test:standard:int": "vitest run --mode standard-int",
"test:standard": "pnpm test:standard:unit && pnpm test:standard:int",
"format": "prettier --config .prettierrc --write \"src\"",
"format:check": "prettier --config .prettierrc --check \"src\""
},
"author": "LangChain",
"license": "MIT",
"dependencies": {
"htmlparser2": "^10.0.0",
"oracledb": "^6.6.0",
"uuid": "^10.0.0"
},
"peerDependencies": {
"@langchain/core": "^1.0.0",
"@langchain/textsplitters": "^1.0.0"
},
"devDependencies": {
"@cfworker/json-schema": "^4.1.1",
"@jest/globals": "^29.5.0",
"@langchain/core": "^1.0.0",
"@langchain/textsplitters": "^1.0.0",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
"@types/oracledb": "^6.6.0",
"@vitest/coverage-v8": "^3.2.4",
"dotenv": "^16.6.1",
"dpdm": "^3.14.0",
"eslint": "^9.34.0",
"jest": "^29.5.0",
"jest-environment-node": "^29.6.4",
"prettier": "^2.8.3",
"rollup": "^4.5.2",
"ts-jest": "^29.1.0",
"typescript": "~5.8.3",
"vitest": "^3.2.4",
"zod": "^3.25.76"
},
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"types": {
"import": "./index.d.ts",
"require": "./index.d.cts",
"default": "./index.d.ts"
},
"import": "./index.js",
"require": "./index.cjs"
},
"./package.json": "./package.json"
},
"files": [
"dist/",
"index.cjs",
"index.js",
"index.d.ts",
"index.d.cts"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";
import { afterAll, jest } from "@jest/globals";

afterAll(awaitAllCallbacks);

// Allow console.log to be disabled in tests
if (process.env.DISABLE_CONSOLE_LOGS === "true") {
console.log = jest.fn();
}
Loading