@langchain/anthropic 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1 +1,122 @@
|
|
|
1
|
-
# langchain
|
|
1
|
+
# @langchain/anthropic
|
|
2
|
+
|
|
3
|
+
This package contains the LangChain.js integrations for Anthropic through their SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash npm2yarn
|
|
8
|
+
npm install @langchain/anthropic
|
|
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 fields 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/anthropic": "^0.0.0",
|
|
21
|
+
"langchain": "0.0.207"
|
|
22
|
+
},
|
|
23
|
+
"resolutions": {
|
|
24
|
+
"@langchain/core": "0.1.1"
|
|
25
|
+
},
|
|
26
|
+
"overrides": {
|
|
27
|
+
"@langchain/core": "0.1.1"
|
|
28
|
+
},
|
|
29
|
+
"pnpm": {
|
|
30
|
+
"overrides": {
|
|
31
|
+
"@langchain/core": "0.1.1"
|
|
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 `ChatAnthropic` class, which is the recommended way to interface with the Anthropic series of models.
|
|
42
|
+
|
|
43
|
+
To use, install the requirements, and configure your environment.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
export ANTHROPIC_API_KEY=your-api-key
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then initialize
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
53
|
+
|
|
54
|
+
const model = new ChatAnthropic({
|
|
55
|
+
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
56
|
+
});
|
|
57
|
+
const response = await model.invoke(new HumanMessage("Hello world!"));
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Streaming
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
64
|
+
|
|
65
|
+
const model = new ChatAnthropic({
|
|
66
|
+
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
67
|
+
modelName: "claude-2",
|
|
68
|
+
});
|
|
69
|
+
const response = await model.stream(new HumanMessage("Hello world!"));
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
To develop the Anthropic package, you'll need to follow these instructions:
|
|
75
|
+
|
|
76
|
+
### Install dependencies
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
yarn install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Build the package
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
yarn build
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or from the repo root:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
yarn build --filter=@langchain/anthropic
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Run tests
|
|
95
|
+
|
|
96
|
+
Test files should live within a `tests/` file in the `src/` folder. Unit tests should end in `.test.ts` and integration tests should
|
|
97
|
+
end in `.int.test.ts`:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
$ yarn test
|
|
101
|
+
$ yarn test:int
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Lint & Format
|
|
105
|
+
|
|
106
|
+
Run the linter & formatter to ensure your code is up to standard:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
yarn lint && yarn format
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Adding new entrypoints
|
|
113
|
+
|
|
114
|
+
If you add a new file to be exported, either import & re-export from `src/index.ts`, or add it to `scripts/create-entrypoints.js` and run `yarn build` to generate the new entrypoint.
|
|
115
|
+
|
|
116
|
+
## Publishing
|
|
117
|
+
|
|
118
|
+
After running `yarn build`, publish a new version with:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
$ npm publish
|
|
122
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/anthropic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Anthropic integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"url": "git@github.com:langchain-ai/langchainjs.git"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
|
|
16
|
+
"build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
|
|
17
|
+
"build:deps": "yarn run turbo:command build --filter=@langchain/core",
|
|
17
18
|
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/",
|
|
18
19
|
"build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && node scripts/move-cjs-to-dist.js && rimraf dist-cjs",
|
|
19
20
|
"build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
|
|
@@ -25,9 +26,9 @@
|
|
|
25
26
|
"clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre",
|
|
26
27
|
"prepack": "yarn build",
|
|
27
28
|
"release": "release-it --only-version --config .release-it.json",
|
|
28
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
29
|
-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
30
|
-
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
29
|
+
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
30
|
+
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
31
|
+
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
31
32
|
"format": "prettier --write \"src\"",
|
|
32
33
|
"format:check": "prettier --check \"src\""
|
|
33
34
|
},
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"license": "MIT",
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@anthropic-ai/sdk": "^0.10.0",
|
|
38
|
-
"@langchain/core": "~0.1.
|
|
39
|
+
"@langchain/core": "~0.1.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@jest/globals": "^29.5.0",
|