@langchain/anthropic 0.0.9 → 0.1.0

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 CHANGED
@@ -17,18 +17,18 @@ You can do so by adding appropriate fields to your project's `package.json` like
17
17
  "name": "your-project",
18
18
  "version": "0.0.0",
19
19
  "dependencies": {
20
- "@langchain/anthropic": "^0.0.0",
20
+ "@langchain/anthropic": "^0.0.9",
21
21
  "langchain": "0.0.207"
22
22
  },
23
23
  "resolutions": {
24
- "@langchain/core": "0.1.2"
24
+ "@langchain/core": "0.1.5"
25
25
  },
26
26
  "overrides": {
27
- "@langchain/core": "0.1.2"
27
+ "@langchain/core": "0.1.5"
28
28
  },
29
29
  "pnpm": {
30
30
  "overrides": {
31
- "@langchain/core": "0.1.2"
31
+ "@langchain/core": "0.1.5"
32
32
  }
33
33
  }
34
34
  }
@@ -111,7 +111,7 @@ yarn lint && yarn format
111
111
 
112
112
  ### Adding new entrypoints
113
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.
114
+ 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.
115
115
 
116
116
  ## Publishing
117
117
 
@@ -15,10 +15,12 @@ const chat_models_1 = require("@langchain/core/language_models/chat_models");
15
15
  * @remarks
16
16
  * Any parameters that are valid to be passed to {@link
17
17
  * https://console.anthropic.com/docs/api/reference |
18
- * `anthropic.beta.messages`} can be passed through {@link invocationKwargs},
18
+ * `anthropic.messages`} can be passed through {@link invocationKwargs},
19
19
  * even if not explicitly available on this class.
20
20
  * @example
21
21
  * ```typescript
22
+ * import { ChatAnthropic } from "@langchain/anthropic";
23
+ *
22
24
  * const model = new ChatAnthropic({
23
25
  * temperature: 0.9,
24
26
  * anthropicApiKey: 'YOUR-API-KEY',
@@ -342,9 +344,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
342
344
  maxRetries: 0,
343
345
  });
344
346
  }
345
- const makeCompletionRequest = async () => this.streamingClient.beta.messages.create(
346
- // TODO: Fix typing once underlying SDK is fixed to not require unnecessary "anthropic-beta" param
347
- {
347
+ const makeCompletionRequest = async () => this.streamingClient.messages.create({
348
348
  ...request,
349
349
  ...this.invocationKwargs,
350
350
  stream: true,
@@ -365,9 +365,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
365
365
  maxRetries: 0,
366
366
  });
367
367
  }
368
- const makeCompletionRequest = async () => this.batchClient.beta.messages.create(
369
- // TODO: Fix typing once underlying SDK is fixed to not require unnecessary "anthropic-beta" param
370
- {
368
+ const makeCompletionRequest = async () => this.batchClient.messages.create({
371
369
  ...request,
372
370
  ...this.invocationKwargs,
373
371
  });
@@ -5,10 +5,10 @@ import { type BaseMessage } from "@langchain/core/messages";
5
5
  import { ChatGenerationChunk, type ChatResult } from "@langchain/core/outputs";
6
6
  import { BaseChatModel, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
7
7
  import { type BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
8
- type AnthropicMessage = Anthropic.Beta.MessageParam;
9
- type AnthropicMessageCreateParams = Omit<Anthropic.Beta.MessageCreateParamsNonStreaming, "anthropic-beta">;
10
- type AnthropicStreamingMessageCreateParams = Omit<Anthropic.Beta.MessageCreateParamsStreaming, "anthropic-beta">;
11
- type AnthropicMessageStreamEvent = Anthropic.Beta.MessageStreamEvent;
8
+ type AnthropicMessage = Anthropic.MessageParam;
9
+ type AnthropicMessageCreateParams = Anthropic.MessageCreateParamsNonStreaming;
10
+ type AnthropicStreamingMessageCreateParams = Anthropic.MessageCreateParamsStreaming;
11
+ type AnthropicMessageStreamEvent = Anthropic.MessageStreamEvent;
12
12
  /**
13
13
  * Input to AnthropicChat class.
14
14
  */
@@ -75,10 +75,12 @@ type Kwargs = Record<string, any>;
75
75
  * @remarks
76
76
  * Any parameters that are valid to be passed to {@link
77
77
  * https://console.anthropic.com/docs/api/reference |
78
- * `anthropic.beta.messages`} can be passed through {@link invocationKwargs},
78
+ * `anthropic.messages`} can be passed through {@link invocationKwargs},
79
79
  * even if not explicitly available on this class.
80
80
  * @example
81
81
  * ```typescript
82
+ * import { ChatAnthropic } from "@langchain/anthropic";
83
+ *
82
84
  * const model = new ChatAnthropic({
83
85
  * temperature: 0.9,
84
86
  * anthropicApiKey: 'YOUR-API-KEY',
@@ -111,13 +113,13 @@ export declare class ChatAnthropicMessages<CallOptions extends BaseLanguageModel
111
113
  /**
112
114
  * Get the parameters used to invoke the model
113
115
  */
114
- invocationParams(options?: this["ParsedCallOptions"]): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages" | "anthropic-beta"> & Kwargs;
116
+ invocationParams(options?: this["ParsedCallOptions"]): Omit<AnthropicMessageCreateParams | AnthropicStreamingMessageCreateParams, "messages"> & Kwargs;
115
117
  /** @ignore */
116
118
  _identifyingParams(): {
119
+ metadata?: Anthropic.Messages.MessageCreateParams.Metadata | undefined;
117
120
  stream?: boolean | undefined;
118
121
  max_tokens: number;
119
122
  model: string;
120
- metadata?: Anthropic.Beta.Messages.MessageCreateParams.Metadata | undefined;
121
123
  stop_sequences?: string[] | undefined;
122
124
  system?: string | undefined;
123
125
  temperature?: number | undefined;
@@ -129,10 +131,10 @@ export declare class ChatAnthropicMessages<CallOptions extends BaseLanguageModel
129
131
  * Get the identifying parameters for the model
130
132
  */
131
133
  identifyingParams(): {
134
+ metadata?: Anthropic.Messages.MessageCreateParams.Metadata | undefined;
132
135
  stream?: boolean | undefined;
133
136
  max_tokens: number;
134
137
  model: string;
135
- metadata?: Anthropic.Beta.Messages.MessageCreateParams.Metadata | undefined;
136
138
  stop_sequences?: string[] | undefined;
137
139
  system?: string | undefined;
138
140
  temperature?: number | undefined;
@@ -161,7 +163,7 @@ export declare class ChatAnthropicMessages<CallOptions extends BaseLanguageModel
161
163
  /** @ignore */
162
164
  protected completionWithRetry(request: AnthropicMessageCreateParams & Kwargs, options: {
163
165
  signal?: AbortSignal;
164
- }): Promise<Anthropic.Beta.Message>;
166
+ }): Promise<Anthropic.Message>;
165
167
  _llmType(): string;
166
168
  /** @ignore */
167
169
  _combineLLMOutput(): never[];
@@ -12,10 +12,12 @@ import { BaseChatModel, } from "@langchain/core/language_models/chat_models";
12
12
  * @remarks
13
13
  * Any parameters that are valid to be passed to {@link
14
14
  * https://console.anthropic.com/docs/api/reference |
15
- * `anthropic.beta.messages`} can be passed through {@link invocationKwargs},
15
+ * `anthropic.messages`} can be passed through {@link invocationKwargs},
16
16
  * even if not explicitly available on this class.
17
17
  * @example
18
18
  * ```typescript
19
+ * import { ChatAnthropic } from "@langchain/anthropic";
20
+ *
19
21
  * const model = new ChatAnthropic({
20
22
  * temperature: 0.9,
21
23
  * anthropicApiKey: 'YOUR-API-KEY',
@@ -339,9 +341,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
339
341
  maxRetries: 0,
340
342
  });
341
343
  }
342
- const makeCompletionRequest = async () => this.streamingClient.beta.messages.create(
343
- // TODO: Fix typing once underlying SDK is fixed to not require unnecessary "anthropic-beta" param
344
- {
344
+ const makeCompletionRequest = async () => this.streamingClient.messages.create({
345
345
  ...request,
346
346
  ...this.invocationKwargs,
347
347
  stream: true,
@@ -362,9 +362,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
362
362
  maxRetries: 0,
363
363
  });
364
364
  }
365
- const makeCompletionRequest = async () => this.batchClient.beta.messages.create(
366
- // TODO: Fix typing once underlying SDK is fixed to not require unnecessary "anthropic-beta" param
367
- {
365
+ const makeCompletionRequest = async () => this.batchClient.messages.create({
368
366
  ...request,
369
367
  ...this.invocationKwargs,
370
368
  });
@@ -4,18 +4,18 @@ import { HumanMessage } from "@langchain/core/messages";
4
4
  import { ChatPromptValue } from "@langchain/core/prompt_values";
5
5
  import { PromptTemplate, ChatPromptTemplate, AIMessagePromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate, } from "@langchain/core/prompts";
6
6
  import { CallbackManager } from "@langchain/core/callbacks/manager";
7
- import { ChatAnthropicMessages } from "../chat_models.js";
8
- test("Test ChatAnthropicMessages", async () => {
9
- const chat = new ChatAnthropicMessages({
7
+ import { ChatAnthropic } from "../chat_models.js";
8
+ test.skip("Test ChatAnthropic", async () => {
9
+ const chat = new ChatAnthropic({
10
10
  modelName: "claude-instant-1.2",
11
11
  maxRetries: 0,
12
12
  });
13
13
  const message = new HumanMessage("Hello!");
14
- const res = await chat.call([message]);
14
+ const res = await chat.invoke([message]);
15
15
  console.log({ res });
16
16
  });
17
- test("Test ChatAnthropicMessages Generate", async () => {
18
- const chat = new ChatAnthropicMessages({
17
+ test("Test ChatAnthropic Generate", async () => {
18
+ const chat = new ChatAnthropic({
19
19
  modelName: "claude-instant-1.2",
20
20
  maxRetries: 0,
21
21
  });
@@ -30,8 +30,8 @@ test("Test ChatAnthropicMessages Generate", async () => {
30
30
  }
31
31
  console.log({ res });
32
32
  });
33
- test("Test ChatAnthropicMessages Generate w/ ClientOptions", async () => {
34
- const chat = new ChatAnthropicMessages({
33
+ test("Test ChatAnthropic Generate w/ ClientOptions", async () => {
34
+ const chat = new ChatAnthropic({
35
35
  modelName: "claude-instant-1.2",
36
36
  maxRetries: 0,
37
37
  clientOptions: {
@@ -51,8 +51,8 @@ test("Test ChatAnthropicMessages Generate w/ ClientOptions", async () => {
51
51
  }
52
52
  console.log({ res });
53
53
  });
54
- test("Test ChatAnthropicMessages Generate with a signal in call options", async () => {
55
- const chat = new ChatAnthropicMessages({
54
+ test("Test ChatAnthropic Generate with a signal in call options", async () => {
55
+ const chat = new ChatAnthropic({
56
56
  modelName: "claude-instant-1.2",
57
57
  maxRetries: 0,
58
58
  });
@@ -68,8 +68,8 @@ test("Test ChatAnthropicMessages Generate with a signal in call options", async
68
68
  return res;
69
69
  }).rejects.toThrow();
70
70
  }, 10000);
71
- test("Test ChatAnthropicMessages tokenUsage with a batch", async () => {
72
- const model = new ChatAnthropicMessages({
71
+ test("Test ChatAnthropic tokenUsage with a batch", async () => {
72
+ const model = new ChatAnthropic({
73
73
  temperature: 0,
74
74
  maxRetries: 0,
75
75
  modelName: "claude-instant-1.2",
@@ -80,10 +80,10 @@ test("Test ChatAnthropicMessages tokenUsage with a batch", async () => {
80
80
  ]);
81
81
  console.log({ res });
82
82
  });
83
- test("Test ChatAnthropicMessages in streaming mode", async () => {
83
+ test("Test ChatAnthropic in streaming mode", async () => {
84
84
  let nrNewTokens = 0;
85
85
  let streamedCompletion = "";
86
- const model = new ChatAnthropicMessages({
86
+ const model = new ChatAnthropic({
87
87
  modelName: "claude-instant-1.2",
88
88
  maxRetries: 0,
89
89
  streaming: true,
@@ -100,10 +100,10 @@ test("Test ChatAnthropicMessages in streaming mode", async () => {
100
100
  expect(nrNewTokens > 0).toBe(true);
101
101
  expect(res.content).toBe(streamedCompletion);
102
102
  });
103
- test("Test ChatAnthropicMessages in streaming mode with a signal", async () => {
103
+ test("Test ChatAnthropic in streaming mode with a signal", async () => {
104
104
  let nrNewTokens = 0;
105
105
  let streamedCompletion = "";
106
- const model = new ChatAnthropicMessages({
106
+ const model = new ChatAnthropic({
107
107
  modelName: "claude-instant-1.2",
108
108
  maxRetries: 0,
109
109
  streaming: true,
@@ -127,8 +127,8 @@ test("Test ChatAnthropicMessages in streaming mode with a signal", async () => {
127
127
  }).rejects.toThrow();
128
128
  console.log({ nrNewTokens, streamedCompletion });
129
129
  }, 5000);
130
- test("Test ChatAnthropicMessages prompt value", async () => {
131
- const chat = new ChatAnthropicMessages({
130
+ test("Test ChatAnthropic prompt value", async () => {
131
+ const chat = new ChatAnthropic({
132
132
  modelName: "claude-instant-1.2",
133
133
  maxRetries: 0,
134
134
  });
@@ -142,8 +142,8 @@ test("Test ChatAnthropicMessages prompt value", async () => {
142
142
  }
143
143
  console.log({ res });
144
144
  });
145
- test("ChatAnthropicMessages, docs, prompt templates", async () => {
146
- const chat = new ChatAnthropicMessages({
145
+ test("ChatAnthropic, docs, prompt templates", async () => {
146
+ const chat = new ChatAnthropic({
147
147
  modelName: "claude-instant-1.2",
148
148
  maxRetries: 0,
149
149
  temperature: 0,
@@ -162,8 +162,8 @@ test("ChatAnthropicMessages, docs, prompt templates", async () => {
162
162
  ]);
163
163
  console.log(responseA.generations);
164
164
  });
165
- test("ChatAnthropicMessages, longer chain of messages", async () => {
166
- const chat = new ChatAnthropicMessages({
165
+ test("ChatAnthropic, longer chain of messages", async () => {
166
+ const chat = new ChatAnthropic({
167
167
  modelName: "claude-1.3",
168
168
  maxRetries: 0,
169
169
  temperature: 0,
@@ -180,10 +180,10 @@ test("ChatAnthropicMessages, longer chain of messages", async () => {
180
180
  ]);
181
181
  console.log(responseA.generations);
182
182
  });
183
- test("ChatAnthropicMessages, Anthropic apiUrl set manually via constructor", async () => {
183
+ test("ChatAnthropic, Anthropic apiUrl set manually via constructor", async () => {
184
184
  // Pass the default URL through (should use this, and work as normal)
185
185
  const anthropicApiUrl = "https://api.anthropic.com";
186
- const chat = new ChatAnthropicMessages({
186
+ const chat = new ChatAnthropic({
187
187
  modelName: "claude-instant-1.2",
188
188
  maxRetries: 0,
189
189
  anthropicApiUrl,
@@ -192,8 +192,8 @@ test("ChatAnthropicMessages, Anthropic apiUrl set manually via constructor", asy
192
192
  const res = await chat.call([message]);
193
193
  console.log({ res });
194
194
  });
195
- test("ChatAnthropicMessages, Claude V2", async () => {
196
- const chat = new ChatAnthropicMessages({
195
+ test("ChatAnthropic, Claude V2", async () => {
196
+ const chat = new ChatAnthropic({
197
197
  modelName: "claude-2.1",
198
198
  maxRetries: 0,
199
199
  temperature: 0,
@@ -210,8 +210,8 @@ test("ChatAnthropicMessages, Claude V2", async () => {
210
210
  ]);
211
211
  console.log(responseA.generations);
212
212
  });
213
- test("Test ChatAnthropicMessages stream method", async () => {
214
- const model = new ChatAnthropicMessages({
213
+ test("Test ChatAnthropic stream method", async () => {
214
+ const model = new ChatAnthropic({
215
215
  maxTokens: 50,
216
216
  maxRetries: 0,
217
217
  modelName: "claude-instant-1.2",
@@ -224,9 +224,9 @@ test("Test ChatAnthropicMessages stream method", async () => {
224
224
  }
225
225
  expect(chunks.length).toBeGreaterThan(1);
226
226
  });
227
- test("Test ChatAnthropicMessages stream method with abort", async () => {
227
+ test("Test ChatAnthropic stream method with abort", async () => {
228
228
  await expect(async () => {
229
- const model = new ChatAnthropicMessages({
229
+ const model = new ChatAnthropic({
230
230
  maxTokens: 500,
231
231
  maxRetries: 0,
232
232
  modelName: "claude-instant-1.2",
@@ -239,8 +239,8 @@ test("Test ChatAnthropicMessages stream method with abort", async () => {
239
239
  }
240
240
  }).rejects.toThrow();
241
241
  });
242
- test("Test ChatAnthropicMessages stream method with early break", async () => {
243
- const model = new ChatAnthropicMessages({
242
+ test("Test ChatAnthropic stream method with early break", async () => {
243
+ const model = new ChatAnthropic({
244
244
  maxTokens: 50,
245
245
  maxRetries: 0,
246
246
  modelName: "claude-instant-1.2",
@@ -255,8 +255,8 @@ test("Test ChatAnthropicMessages stream method with early break", async () => {
255
255
  }
256
256
  }
257
257
  });
258
- test("Test ChatAnthropicMessages headers passed through", async () => {
259
- const chat = new ChatAnthropicMessages({
258
+ test("Test ChatAnthropic headers passed through", async () => {
259
+ const chat = new ChatAnthropic({
260
260
  modelName: "claude-instant-1.2",
261
261
  maxRetries: 0,
262
262
  anthropicApiKey: "NOT_REAL",
package/index.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/anthropic",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "Anthropic integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -12,33 +12,38 @@
12
12
  "type": "git",
13
13
  "url": "git@github.com:langchain-ai/langchainjs.git"
14
14
  },
15
+ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-anthropic/",
15
16
  "scripts": {
16
17
  "build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
17
18
  "build:deps": "yarn run turbo:command build --filter=@langchain/core",
18
19
  "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/",
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",
20
- "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
21
- "build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js",
22
- "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint src",
20
+ "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
21
+ "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
22
+ "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
23
+ "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
23
24
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
24
25
  "lint": "yarn lint:eslint && yarn lint:dpdm",
25
26
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
26
- "clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre",
27
+ "clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn lc-build --config ./langchain.config.js --create-entrypoints --pre",
27
28
  "prepack": "yarn build",
28
29
  "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
29
30
  "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
30
31
  "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
31
- "format": "prettier --write \"src\"",
32
- "format:check": "prettier --check \"src\""
32
+ "format": "prettier --config .prettierrc --write \"src\"",
33
+ "format:check": "prettier --config .prettierrc --check \"src\"",
34
+ "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
35
+ "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
36
+ "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
33
37
  },
34
38
  "author": "LangChain",
35
39
  "license": "MIT",
36
40
  "dependencies": {
37
- "@anthropic-ai/sdk": "^0.12.0",
41
+ "@anthropic-ai/sdk": "^0.14.1",
38
42
  "@langchain/core": "~0.1.5"
39
43
  },
40
44
  "devDependencies": {
41
45
  "@jest/globals": "^29.5.0",
46
+ "@langchain/scripts": "~0.0",
42
47
  "@swc/core": "^1.3.90",
43
48
  "@swc/jest": "^0.2.29",
44
49
  "dpdm": "^3.12.0",
@@ -75,7 +80,11 @@
75
80
  ],
76
81
  "exports": {
77
82
  ".": {
78
- "types": "./index.d.ts",
83
+ "types": {
84
+ "import": "./index.d.ts",
85
+ "require": "./index.d.cts",
86
+ "default": "./index.d.ts"
87
+ },
79
88
  "import": "./index.js",
80
89
  "require": "./index.cjs"
81
90
  },
@@ -85,6 +94,7 @@
85
94
  "dist/",
86
95
  "index.cjs",
87
96
  "index.js",
88
- "index.d.ts"
97
+ "index.d.ts",
98
+ "index.d.cts"
89
99
  ]
90
100
  }