@langchain/anthropic 1.3.17 → 1.3.18
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/CHANGELOG.md +24 -0
- package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +11 -7
- package/dist/chat_models.cjs +56 -70
- package/dist/chat_models.cjs.map +1 -1
- package/dist/chat_models.d.cts +0 -1
- package/dist/chat_models.d.cts.map +1 -1
- package/dist/chat_models.d.ts +0 -1
- package/dist/chat_models.d.ts.map +1 -1
- package/dist/chat_models.js +28 -42
- package/dist/chat_models.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/output_parsers.cjs +9 -11
- package/dist/output_parsers.cjs.map +1 -1
- package/dist/output_parsers.js +2 -4
- package/dist/output_parsers.js.map +1 -1
- package/dist/profiles.cjs +96 -29
- package/dist/profiles.cjs.map +1 -1
- package/dist/profiles.js +96 -29
- package/dist/profiles.js.map +1 -1
- package/dist/tools/bash.cjs +3 -3
- package/dist/tools/bash.cjs.map +1 -1
- package/dist/tools/bash.d.cts +7 -7
- package/dist/tools/bash.d.cts.map +1 -1
- package/dist/tools/bash.d.ts +7 -7
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/codeExecution.cjs.map +1 -1
- package/dist/tools/codeExecution.d.cts +0 -1
- package/dist/tools/codeExecution.d.cts.map +1 -1
- package/dist/tools/codeExecution.d.ts +0 -1
- package/dist/tools/codeExecution.d.ts.map +1 -1
- package/dist/tools/codeExecution.js.map +1 -1
- package/dist/tools/computer.cjs +4 -4
- package/dist/tools/computer.cjs.map +1 -1
- package/dist/tools/computer.d.cts +101 -101
- package/dist/tools/computer.d.cts.map +1 -1
- package/dist/tools/computer.d.ts +101 -101
- package/dist/tools/computer.d.ts.map +1 -1
- package/dist/tools/computer.js.map +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/mcpToolset.cjs.map +1 -1
- package/dist/tools/mcpToolset.d.cts +0 -1
- package/dist/tools/mcpToolset.d.cts.map +1 -1
- package/dist/tools/mcpToolset.d.ts +0 -1
- package/dist/tools/mcpToolset.d.ts.map +1 -1
- package/dist/tools/mcpToolset.js.map +1 -1
- package/dist/tools/memory.cjs +3 -3
- package/dist/tools/memory.cjs.map +1 -1
- package/dist/tools/memory.d.cts +27 -28
- package/dist/tools/memory.d.cts.map +1 -1
- package/dist/tools/memory.d.ts +25 -26
- package/dist/tools/memory.d.ts.map +1 -1
- package/dist/tools/memory.js.map +1 -1
- package/dist/tools/textEditor.cjs +3 -3
- package/dist/tools/textEditor.cjs.map +1 -1
- package/dist/tools/textEditor.d.cts +19 -19
- package/dist/tools/textEditor.d.cts.map +1 -1
- package/dist/tools/textEditor.d.ts +21 -21
- package/dist/tools/textEditor.d.ts.map +1 -1
- package/dist/tools/textEditor.js.map +1 -1
- package/dist/tools/toolSearch.cjs.map +1 -1
- package/dist/tools/toolSearch.d.cts +0 -1
- package/dist/tools/toolSearch.d.cts.map +1 -1
- package/dist/tools/toolSearch.d.ts +0 -1
- package/dist/tools/toolSearch.d.ts.map +1 -1
- package/dist/tools/toolSearch.js.map +1 -1
- package/dist/tools/types.cjs +2 -2
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.d.cts +0 -1
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +0 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/webFetch.cjs.map +1 -1
- package/dist/tools/webFetch.d.cts +0 -1
- package/dist/tools/webFetch.d.cts.map +1 -1
- package/dist/tools/webFetch.d.ts +0 -1
- package/dist/tools/webFetch.d.ts.map +1 -1
- package/dist/tools/webFetch.js.map +1 -1
- package/dist/tools/webSearch.cjs.map +1 -1
- package/dist/tools/webSearch.d.cts +0 -1
- package/dist/tools/webSearch.d.cts.map +1 -1
- package/dist/tools/webSearch.d.ts +0 -1
- package/dist/tools/webSearch.d.ts.map +1 -1
- package/dist/tools/webSearch.js.map +1 -1
- package/dist/types.d.cts +0 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/content.cjs +3 -3
- package/dist/utils/content.cjs.map +1 -1
- package/dist/utils/content.js.map +1 -1
- package/dist/utils/errors.cjs +4 -1
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.js +4 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/message_inputs.cjs +79 -100
- package/dist/utils/message_inputs.cjs.map +1 -1
- package/dist/utils/message_inputs.js +73 -94
- package/dist/utils/message_inputs.js.map +1 -1
- package/dist/utils/message_outputs.cjs +28 -32
- package/dist/utils/message_outputs.cjs.map +1 -1
- package/dist/utils/message_outputs.js +13 -17
- package/dist/utils/message_outputs.js.map +1 -1
- package/dist/utils/prompts.cjs +1 -2
- package/dist/utils/prompts.cjs.map +1 -1
- package/dist/utils/prompts.d.cts +0 -1
- package/dist/utils/prompts.d.cts.map +1 -1
- package/dist/utils/prompts.d.ts +0 -1
- package/dist/utils/prompts.d.ts.map +1 -1
- package/dist/utils/prompts.js +1 -2
- package/dist/utils/prompts.js.map +1 -1
- package/dist/utils/standard.cjs +2 -4
- package/dist/utils/standard.cjs.map +1 -1
- package/dist/utils/standard.js +2 -4
- package/dist/utils/standard.js.map +1 -1
- package/dist/utils/tools.cjs +4 -3
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.js +1 -1
- package/dist/utils/tools.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @langchain/anthropic
|
|
2
2
|
|
|
3
|
+
## 1.3.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10077](https://github.com/langchain-ai/langchainjs/pull/10077) [`05396f7`](https://github.com/langchain-ai/langchainjs/commit/05396f7ce0a91c49a3bae4bbcd3dbdd6cbd18089) Thanks [@christian-bromann](https://github.com/christian-bromann)! - feat(core): add ContextOverflowError, raise in anthropic and openai
|
|
8
|
+
|
|
9
|
+
- [#10081](https://github.com/langchain-ai/langchainjs/pull/10081) [`5a6f26b`](https://github.com/langchain-ai/langchainjs/commit/5a6f26bbaed80195dc538c538b96219a8b03f38f) Thanks [@hntrl](https://github.com/hntrl)! - feat(core): add namespace-based symbol branding for error class hierarchies
|
|
10
|
+
|
|
11
|
+
Introduces `createNamespace` utility for hierarchical symbol-based branding of class hierarchies.
|
|
12
|
+
All LangChain error classes now use this pattern, replacing hand-rolled duck-type `isInstance` checks
|
|
13
|
+
with reliable cross-realm `Symbol.for`-based identity.
|
|
14
|
+
- New `LangChainError` base class that all LangChain errors extend
|
|
15
|
+
- New `createNamespace` / `Namespace` API in `@langchain/core/utils/namespace`
|
|
16
|
+
- Refactored `ModelAbortError`, `ContextOverflowError` to use namespace branding
|
|
17
|
+
- Added `ContextOverflowError.fromError()` static factory method
|
|
18
|
+
- Deprecated `addLangChainErrorFields` in favor of `LangChainError` subclasses
|
|
19
|
+
- Migrated Google provider errors (`GoogleError`, `ConfigurationError`, etc.) to namespace branding
|
|
20
|
+
- Updated Anthropic and OpenAI providers to use `ContextOverflowError.fromError()`
|
|
21
|
+
|
|
22
|
+
- [#10078](https://github.com/langchain-ai/langchainjs/pull/10078) [`7be50a7`](https://github.com/langchain-ai/langchainjs/commit/7be50a7014d7622e0ab8d303dfc9c633ebc96333) Thanks [@christian-bromann](https://github.com/christian-bromann)! - chore(\*): update model profiles
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`27186c5`](https://github.com/langchain-ai/langchainjs/commit/27186c54884cfe7c2522fa50b42c3ca0ccaefdba), [`05396f7`](https://github.com/langchain-ai/langchainjs/commit/05396f7ce0a91c49a3bae4bbcd3dbdd6cbd18089), [`5a6f26b`](https://github.com/langchain-ai/langchainjs/commit/5a6f26bbaed80195dc538c538b96219a8b03f38f)]:
|
|
25
|
+
- @langchain/core@1.1.25
|
|
26
|
+
|
|
3
27
|
## 1.3.17
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
package/dist/chat_models.cjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_output_parsers = require('./output_parsers.cjs');
|
|
3
3
|
const require_tools = require('./utils/tools.cjs');
|
|
4
4
|
const require_message_inputs = require('./utils/message_inputs.cjs');
|
|
5
5
|
const require_message_outputs = require('./utils/message_outputs.cjs');
|
|
6
6
|
const require_errors = require('./utils/errors.cjs');
|
|
7
7
|
const require_profiles = require('./profiles.cjs');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
let _anthropic_ai_sdk = require("@anthropic-ai/sdk");
|
|
9
|
+
let _anthropic_ai_sdk_lib_transform_json_schema = require("@anthropic-ai/sdk/lib/transform-json-schema");
|
|
10
|
+
let _langchain_core_messages = require("@langchain/core/messages");
|
|
11
|
+
let _langchain_core_outputs = require("@langchain/core/outputs");
|
|
12
|
+
let _langchain_core_utils_env = require("@langchain/core/utils/env");
|
|
13
|
+
let _langchain_core_language_models_chat_models = require("@langchain/core/language_models/chat_models");
|
|
14
|
+
let _langchain_core_language_models_base = require("@langchain/core/language_models/base");
|
|
15
|
+
let _langchain_core_utils_json_schema = require("@langchain/core/utils/json_schema");
|
|
16
|
+
let _langchain_core_output_parsers = require("@langchain/core/output_parsers");
|
|
17
|
+
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
18
|
+
let _langchain_core_utils_types = require("@langchain/core/utils/types");
|
|
19
|
+
let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
|
|
20
20
|
|
|
21
21
|
//#region src/chat_models.ts
|
|
22
22
|
const MODEL_DEFAULT_MAX_OUTPUT_TOKENS = {
|
|
@@ -37,8 +37,7 @@ const MODEL_DEFAULT_MAX_OUTPUT_TOKENS = {
|
|
|
37
37
|
const FALLBACK_MAX_OUTPUT_TOKENS = 2048;
|
|
38
38
|
function defaultMaxOutputTokensForModel(model) {
|
|
39
39
|
if (!model) return FALLBACK_MAX_OUTPUT_TOKENS;
|
|
40
|
-
|
|
41
|
-
return maxTokens ?? FALLBACK_MAX_OUTPUT_TOKENS;
|
|
40
|
+
return Object.entries(MODEL_DEFAULT_MAX_OUTPUT_TOKENS).find(([key]) => model.startsWith(key))?.[1] ?? FALLBACK_MAX_OUTPUT_TOKENS;
|
|
42
41
|
}
|
|
43
42
|
function _toolsInParams(params) {
|
|
44
43
|
return !!(params.tools && params.tools.length > 0);
|
|
@@ -54,14 +53,13 @@ function _thinkingInParams(params) {
|
|
|
54
53
|
return !!(params.thinking && (params.thinking.type === "enabled" || params.thinking.type === "adaptive"));
|
|
55
54
|
}
|
|
56
55
|
function _compactionInParams(params) {
|
|
57
|
-
|
|
58
|
-
return !!cm?.edits?.some((e) => e.type === "compact_20260112");
|
|
56
|
+
return !!params.context_management?.edits?.some((e) => e.type === "compact_20260112");
|
|
59
57
|
}
|
|
60
58
|
function isAnthropicTool(tool) {
|
|
61
59
|
return "input_schema" in tool;
|
|
62
60
|
}
|
|
63
61
|
function isBuiltinTool(tool) {
|
|
64
|
-
|
|
62
|
+
return typeof tool === "object" && tool !== null && "type" in tool && ("name" in tool || "mcp_server_name" in tool) && typeof tool.type === "string" && [
|
|
65
63
|
"text_editor_",
|
|
66
64
|
"computer_",
|
|
67
65
|
"bash_",
|
|
@@ -73,8 +71,7 @@ function isBuiltinTool(tool) {
|
|
|
73
71
|
"memory_",
|
|
74
72
|
"tool_search_",
|
|
75
73
|
"mcp_toolset"
|
|
76
|
-
];
|
|
77
|
-
return typeof tool === "object" && tool !== null && "type" in tool && ("name" in tool || "mcp_server_name" in tool) && typeof tool.type === "string" && builtInToolPrefixes.some((prefix) => typeof tool.type === "string" && tool.type.startsWith(prefix));
|
|
74
|
+
].some((prefix) => typeof tool.type === "string" && tool.type.startsWith(prefix));
|
|
78
75
|
}
|
|
79
76
|
function _combineBetas(a, b, ...rest) {
|
|
80
77
|
return Array.from(new Set([
|
|
@@ -87,7 +84,6 @@ function extractToken(chunk) {
|
|
|
87
84
|
if (typeof chunk.content === "string") return chunk.content;
|
|
88
85
|
else if (Array.isArray(chunk.content) && chunk.content.length >= 1 && "input" in chunk.content[0]) return typeof chunk.content[0].input === "string" ? chunk.content[0].input : JSON.stringify(chunk.content[0].input);
|
|
89
86
|
else if (Array.isArray(chunk.content) && chunk.content.length >= 1 && "text" in chunk.content[0] && typeof chunk.content[0].text === "string") return chunk.content[0].text;
|
|
90
|
-
return void 0;
|
|
91
87
|
}
|
|
92
88
|
/**
|
|
93
89
|
* Anthropic chat model integration.
|
|
@@ -605,7 +601,7 @@ function extractToken(chunk) {
|
|
|
605
601
|
*
|
|
606
602
|
* <br />
|
|
607
603
|
*/
|
|
608
|
-
var ChatAnthropicMessages = class extends
|
|
604
|
+
var ChatAnthropicMessages = class extends _langchain_core_language_models_chat_models.BaseChatModel {
|
|
609
605
|
static lc_name() {
|
|
610
606
|
return "ChatAnthropic";
|
|
611
607
|
}
|
|
@@ -648,7 +644,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
648
644
|
createClient;
|
|
649
645
|
constructor(fields) {
|
|
650
646
|
super(fields ?? {});
|
|
651
|
-
this.anthropicApiKey = fields?.apiKey ?? fields?.anthropicApiKey ?? (0,
|
|
647
|
+
this.anthropicApiKey = fields?.apiKey ?? fields?.anthropicApiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("ANTHROPIC_API_KEY");
|
|
652
648
|
if (!this.anthropicApiKey && !fields?.createClient) throw new Error("Anthropic API key not found");
|
|
653
649
|
this.clientOptions = fields?.clientOptions ?? {};
|
|
654
650
|
/** Keep anthropicApiKey for backwards compatibility */
|
|
@@ -670,7 +666,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
670
666
|
this.outputConfig = fields?.outputConfig ?? this.outputConfig;
|
|
671
667
|
this.inferenceGeo = fields?.inferenceGeo ?? this.inferenceGeo;
|
|
672
668
|
this.betas = fields?.betas ?? this.betas;
|
|
673
|
-
this.createClient = fields?.createClient ?? ((options) => new
|
|
669
|
+
this.createClient = fields?.createClient ?? ((options) => new _anthropic_ai_sdk.Anthropic(options));
|
|
674
670
|
}
|
|
675
671
|
getLsParams(options) {
|
|
676
672
|
const params = this.invocationParams(options);
|
|
@@ -690,20 +686,20 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
690
686
|
* @returns {AnthropicTool[] | undefined} The formatted tools, or undefined if none are passed.
|
|
691
687
|
*/
|
|
692
688
|
formatStructuredToolToAnthropic(tools) {
|
|
693
|
-
if (!tools) return
|
|
689
|
+
if (!tools) return;
|
|
694
690
|
return tools.map((tool) => {
|
|
695
|
-
if ((0,
|
|
691
|
+
if ((0, _langchain_core_utils_function_calling.isLangChainTool)(tool) && tool.extras?.providerToolDefinition) return tool.extras.providerToolDefinition;
|
|
696
692
|
if (isBuiltinTool(tool)) return tool;
|
|
697
693
|
if (isAnthropicTool(tool)) return tool;
|
|
698
|
-
if ((0,
|
|
694
|
+
if ((0, _langchain_core_language_models_base.isOpenAITool)(tool)) return {
|
|
699
695
|
name: tool.function.name,
|
|
700
696
|
description: tool.function.description,
|
|
701
697
|
input_schema: tool.function.parameters
|
|
702
698
|
};
|
|
703
|
-
if ((0,
|
|
699
|
+
if ((0, _langchain_core_utils_function_calling.isLangChainTool)(tool)) return {
|
|
704
700
|
name: tool.name,
|
|
705
701
|
description: tool.description,
|
|
706
|
-
input_schema: (0,
|
|
702
|
+
input_schema: (0, _langchain_core_utils_types.isInteropZodSchema)(tool.schema) ? (0, _langchain_core_utils_json_schema.toJsonSchema)(tool.schema) : tool.schema,
|
|
707
703
|
...tool.extras ? require_tools.AnthropicToolExtrasSchema.parse(tool.extras) : {}
|
|
708
704
|
};
|
|
709
705
|
throw new Error(`Unknown tool type passed to ChatAnthropic: ${JSON.stringify(tool, null, 2)}`);
|
|
@@ -735,8 +731,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
735
731
|
if (options?.outputFormat && !base.format) base.format = options.outputFormat;
|
|
736
732
|
return Object.keys(base).length > 0 ? base : void 0;
|
|
737
733
|
})();
|
|
738
|
-
const
|
|
739
|
-
const compactionBetas = hasCompaction ? ["compact-2026-01-12"] : [];
|
|
734
|
+
const compactionBetas = this.contextManagement?.edits?.some((e) => e.type === "compact_20260112") ? ["compact-2026-01-12"] : [];
|
|
740
735
|
const output = {
|
|
741
736
|
model: this.model,
|
|
742
737
|
stop_sequences: options?.stop ?? this.stopSequences,
|
|
@@ -806,8 +801,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
806
801
|
if (!result) continue;
|
|
807
802
|
const { chunk } = result;
|
|
808
803
|
const token = extractToken(chunk);
|
|
809
|
-
const generationChunk = new
|
|
810
|
-
message: new
|
|
804
|
+
const generationChunk = new _langchain_core_outputs.ChatGenerationChunk({
|
|
805
|
+
message: new _langchain_core_messages.AIMessageChunk({
|
|
811
806
|
content: chunk.content,
|
|
812
807
|
additional_kwargs: chunk.additional_kwargs,
|
|
813
808
|
tool_call_chunks: chunk.tool_call_chunks,
|
|
@@ -825,14 +820,13 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
825
820
|
async _generateNonStreaming(messages, params, requestOptions, cacheControl) {
|
|
826
821
|
let formattedMessages = require_message_inputs._convertMessagesToAnthropicPayload(messages);
|
|
827
822
|
if (cacheControl) formattedMessages = require_message_inputs.applyCacheControlToPayload(formattedMessages, cacheControl);
|
|
828
|
-
const
|
|
823
|
+
const { content, ...additionalKwargs } = await this.completionWithRetry({
|
|
829
824
|
...params,
|
|
830
825
|
stream: false,
|
|
831
826
|
...formattedMessages
|
|
832
827
|
}, requestOptions);
|
|
833
|
-
const { content,...additionalKwargs } = response;
|
|
834
828
|
const generations = require_message_outputs.anthropicResponseToChatMessages(content, additionalKwargs);
|
|
835
|
-
const { role: _role, type: _type
|
|
829
|
+
const { role: _role, type: _type, ...rest } = additionalKwargs;
|
|
836
830
|
return {
|
|
837
831
|
generations,
|
|
838
832
|
llmOutput: rest
|
|
@@ -875,26 +869,22 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
875
869
|
maxRetries: 0
|
|
876
870
|
});
|
|
877
871
|
}
|
|
878
|
-
const { betas
|
|
872
|
+
const { betas, ...rest } = request;
|
|
879
873
|
const makeCompletionRequest = async () => {
|
|
880
874
|
try {
|
|
881
|
-
if (request?.betas?.length) {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}, options);
|
|
888
|
-
return stream;
|
|
889
|
-
}
|
|
875
|
+
if (request?.betas?.length) return await this.streamingClient.beta.messages.create({
|
|
876
|
+
...rest,
|
|
877
|
+
betas,
|
|
878
|
+
...this.invocationKwargs,
|
|
879
|
+
stream: true
|
|
880
|
+
}, options);
|
|
890
881
|
return await this.streamingClient.messages.create({
|
|
891
882
|
...rest,
|
|
892
883
|
...this.invocationKwargs,
|
|
893
884
|
stream: true
|
|
894
885
|
}, options);
|
|
895
886
|
} catch (e) {
|
|
896
|
-
|
|
897
|
-
throw error;
|
|
887
|
+
throw require_errors.wrapAnthropicClientError(e);
|
|
898
888
|
}
|
|
899
889
|
};
|
|
900
890
|
return this.caller.call(makeCompletionRequest);
|
|
@@ -902,33 +892,29 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
902
892
|
/** @ignore */
|
|
903
893
|
async completionWithRetry(request, options) {
|
|
904
894
|
if (!this.batchClient) {
|
|
905
|
-
const options
|
|
895
|
+
const options = this.apiUrl ? { baseURL: this.apiUrl } : void 0;
|
|
906
896
|
this.batchClient = this.createClient({
|
|
907
897
|
dangerouslyAllowBrowser: true,
|
|
908
898
|
...this.clientOptions,
|
|
909
|
-
...options
|
|
899
|
+
...options,
|
|
910
900
|
apiKey: this.apiKey,
|
|
911
901
|
maxRetries: 0
|
|
912
902
|
});
|
|
913
903
|
}
|
|
914
|
-
const { betas
|
|
904
|
+
const { betas, ...rest } = request;
|
|
915
905
|
const makeCompletionRequest = async () => {
|
|
916
906
|
try {
|
|
917
|
-
if (request?.betas?.length) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}, options);
|
|
923
|
-
return response;
|
|
924
|
-
}
|
|
907
|
+
if (request?.betas?.length) return await this.batchClient.beta.messages.create({
|
|
908
|
+
...rest,
|
|
909
|
+
...this.invocationKwargs,
|
|
910
|
+
betas
|
|
911
|
+
}, options);
|
|
925
912
|
return await this.batchClient.messages.create({
|
|
926
913
|
...rest,
|
|
927
914
|
...this.invocationKwargs
|
|
928
915
|
}, options);
|
|
929
916
|
} catch (e) {
|
|
930
|
-
|
|
931
|
-
throw error;
|
|
917
|
+
throw require_errors.wrapAnthropicClientError(e);
|
|
932
918
|
}
|
|
933
919
|
};
|
|
934
920
|
return this.caller.callWithOptions({ signal: options.signal ?? void 0 }, makeCompletionRequest);
|
|
@@ -969,8 +955,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
969
955
|
method = "jsonSchema";
|
|
970
956
|
}
|
|
971
957
|
if (method === "jsonSchema") {
|
|
972
|
-
outputParser = (0,
|
|
973
|
-
const jsonSchema = (0,
|
|
958
|
+
outputParser = (0, _langchain_core_utils_types.isInteropZodSchema)(schema) ? _langchain_core_output_parsers.StructuredOutputParser.fromZodSchema(schema) : new _langchain_core_output_parsers.JsonOutputParser();
|
|
959
|
+
const jsonSchema = (0, _anthropic_ai_sdk_lib_transform_json_schema.transformJSONSchema)((0, _langchain_core_utils_json_schema.toJsonSchema)(schema));
|
|
974
960
|
llm = this.withConfig({
|
|
975
961
|
outputVersion: "v0",
|
|
976
962
|
outputConfig: { format: {
|
|
@@ -985,8 +971,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
985
971
|
} else if (method === "functionCalling") {
|
|
986
972
|
let functionName = name ?? "extract";
|
|
987
973
|
let tools;
|
|
988
|
-
if ((0,
|
|
989
|
-
const jsonSchema = (0,
|
|
974
|
+
if ((0, _langchain_core_utils_types.isInteropZodSchema)(schema)) {
|
|
975
|
+
const jsonSchema = (0, _langchain_core_utils_json_schema.toJsonSchema)(schema);
|
|
990
976
|
tools = [{
|
|
991
977
|
name: functionName,
|
|
992
978
|
description: jsonSchema.description ?? "A function available to call.",
|
|
@@ -1021,7 +1007,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
1021
1007
|
tools,
|
|
1022
1008
|
ls_structured_output_format: {
|
|
1023
1009
|
kwargs: { method: "functionCalling" },
|
|
1024
|
-
schema: (0,
|
|
1010
|
+
schema: (0, _langchain_core_utils_json_schema.toJsonSchema)(schema)
|
|
1025
1011
|
}
|
|
1026
1012
|
});
|
|
1027
1013
|
const raiseIfNoToolCalls = (message) => {
|
|
@@ -1038,15 +1024,15 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
1038
1024
|
},
|
|
1039
1025
|
ls_structured_output_format: {
|
|
1040
1026
|
kwargs: { method: "functionCalling" },
|
|
1041
|
-
schema: (0,
|
|
1027
|
+
schema: (0, _langchain_core_utils_json_schema.toJsonSchema)(schema)
|
|
1042
1028
|
}
|
|
1043
1029
|
});
|
|
1044
1030
|
} else throw new TypeError(`Unrecognized structured output method '${method}'. Expected 'functionCalling' or 'jsonSchema'`);
|
|
1045
1031
|
if (!includeRaw) return llm.pipe(outputParser).withConfig({ runName: "ChatAnthropicStructuredOutput" });
|
|
1046
|
-
const parserAssign =
|
|
1047
|
-
const parserNone =
|
|
1032
|
+
const parserAssign = _langchain_core_runnables.RunnablePassthrough.assign({ parsed: (input, config) => outputParser.invoke(input.raw, config) });
|
|
1033
|
+
const parserNone = _langchain_core_runnables.RunnablePassthrough.assign({ parsed: () => null });
|
|
1048
1034
|
const parsedWithFallback = parserAssign.withFallbacks({ fallbacks: [parserNone] });
|
|
1049
|
-
return
|
|
1035
|
+
return _langchain_core_runnables.RunnableSequence.from([{ raw: llm }, parsedWithFallback]).withConfig({ runName: "StructuredOutputRunnable" });
|
|
1050
1036
|
}
|
|
1051
1037
|
};
|
|
1052
1038
|
var ChatAnthropic = class extends ChatAnthropicMessages {};
|