@langchain/anthropic 1.3.16 → 1.3.18-dev-1771365493298
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 +9 -0
- package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +11 -7
- package/dist/chat_models.cjs +68 -78
- 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 +40 -50
- 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 +1 -2
- package/dist/profiles.cjs.map +1 -1
- package/dist/profiles.js +1 -2
- 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 +25 -26
- 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 +21 -21
- 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 +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @langchain/anthropic
|
|
2
2
|
|
|
3
|
+
## 1.3.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9991](https://github.com/langchain-ai/langchainjs/pull/9991) [`dca939d`](https://github.com/langchain-ai/langchainjs/commit/dca939dee687b2a0a0a56dfbb1677ab2cd1ceb62) Thanks [@nickwinder](https://github.com/nickwinder)! - fix(anthropic): update MODEL_DEFAULT_MAX_OUTPUT_TOKENS with correct values for all Claude models
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d5e3db0`](https://github.com/langchain-ai/langchainjs/commit/d5e3db0d01ab321ec70a875805b2f74aefdadf9d)]:
|
|
10
|
+
- @langchain/core@1.1.21
|
|
11
|
+
|
|
3
12
|
## 1.3.16
|
|
4
13
|
|
|
5
14
|
### 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,40 +1,43 @@
|
|
|
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 = {
|
|
23
23
|
"claude-opus-4-6": 16384,
|
|
24
|
-
"claude-opus-4-5":
|
|
25
|
-
"claude-
|
|
26
|
-
"claude-
|
|
27
|
-
"claude-
|
|
28
|
-
"claude-sonnet-
|
|
29
|
-
"claude-
|
|
30
|
-
"claude-3-
|
|
31
|
-
"claude-3-
|
|
24
|
+
"claude-opus-4-5": 16384,
|
|
25
|
+
"claude-sonnet-4-5": 16384,
|
|
26
|
+
"claude-haiku-4-5": 16384,
|
|
27
|
+
"claude-opus-4-1": 16384,
|
|
28
|
+
"claude-sonnet-4": 16384,
|
|
29
|
+
"claude-opus-4": 16384,
|
|
30
|
+
"claude-3-7-sonnet": 8192,
|
|
31
|
+
"claude-3-5-sonnet": 8192,
|
|
32
|
+
"claude-3-5-haiku": 8192,
|
|
33
|
+
"claude-3-opus": 4096,
|
|
34
|
+
"claude-3-sonnet": 4096,
|
|
35
|
+
"claude-3-haiku": 4096
|
|
32
36
|
};
|
|
33
37
|
const FALLBACK_MAX_OUTPUT_TOKENS = 2048;
|
|
34
38
|
function defaultMaxOutputTokensForModel(model) {
|
|
35
39
|
if (!model) return FALLBACK_MAX_OUTPUT_TOKENS;
|
|
36
|
-
|
|
37
|
-
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;
|
|
38
41
|
}
|
|
39
42
|
function _toolsInParams(params) {
|
|
40
43
|
return !!(params.tools && params.tools.length > 0);
|
|
@@ -50,14 +53,13 @@ function _thinkingInParams(params) {
|
|
|
50
53
|
return !!(params.thinking && (params.thinking.type === "enabled" || params.thinking.type === "adaptive"));
|
|
51
54
|
}
|
|
52
55
|
function _compactionInParams(params) {
|
|
53
|
-
|
|
54
|
-
return !!cm?.edits?.some((e) => e.type === "compact_20260112");
|
|
56
|
+
return !!params.context_management?.edits?.some((e) => e.type === "compact_20260112");
|
|
55
57
|
}
|
|
56
58
|
function isAnthropicTool(tool) {
|
|
57
59
|
return "input_schema" in tool;
|
|
58
60
|
}
|
|
59
61
|
function isBuiltinTool(tool) {
|
|
60
|
-
|
|
62
|
+
return typeof tool === "object" && tool !== null && "type" in tool && ("name" in tool || "mcp_server_name" in tool) && typeof tool.type === "string" && [
|
|
61
63
|
"text_editor_",
|
|
62
64
|
"computer_",
|
|
63
65
|
"bash_",
|
|
@@ -69,8 +71,7 @@ function isBuiltinTool(tool) {
|
|
|
69
71
|
"memory_",
|
|
70
72
|
"tool_search_",
|
|
71
73
|
"mcp_toolset"
|
|
72
|
-
];
|
|
73
|
-
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));
|
|
74
75
|
}
|
|
75
76
|
function _combineBetas(a, b, ...rest) {
|
|
76
77
|
return Array.from(new Set([
|
|
@@ -83,7 +84,6 @@ function extractToken(chunk) {
|
|
|
83
84
|
if (typeof chunk.content === "string") return chunk.content;
|
|
84
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);
|
|
85
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;
|
|
86
|
-
return void 0;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Anthropic chat model integration.
|
|
@@ -601,7 +601,7 @@ function extractToken(chunk) {
|
|
|
601
601
|
*
|
|
602
602
|
* <br />
|
|
603
603
|
*/
|
|
604
|
-
var ChatAnthropicMessages = class extends
|
|
604
|
+
var ChatAnthropicMessages = class extends _langchain_core_language_models_chat_models.BaseChatModel {
|
|
605
605
|
static lc_name() {
|
|
606
606
|
return "ChatAnthropic";
|
|
607
607
|
}
|
|
@@ -644,7 +644,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
644
644
|
createClient;
|
|
645
645
|
constructor(fields) {
|
|
646
646
|
super(fields ?? {});
|
|
647
|
-
this.anthropicApiKey = fields?.apiKey ?? fields?.anthropicApiKey ?? (0,
|
|
647
|
+
this.anthropicApiKey = fields?.apiKey ?? fields?.anthropicApiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("ANTHROPIC_API_KEY");
|
|
648
648
|
if (!this.anthropicApiKey && !fields?.createClient) throw new Error("Anthropic API key not found");
|
|
649
649
|
this.clientOptions = fields?.clientOptions ?? {};
|
|
650
650
|
/** Keep anthropicApiKey for backwards compatibility */
|
|
@@ -666,7 +666,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
666
666
|
this.outputConfig = fields?.outputConfig ?? this.outputConfig;
|
|
667
667
|
this.inferenceGeo = fields?.inferenceGeo ?? this.inferenceGeo;
|
|
668
668
|
this.betas = fields?.betas ?? this.betas;
|
|
669
|
-
this.createClient = fields?.createClient ?? ((options) => new
|
|
669
|
+
this.createClient = fields?.createClient ?? ((options) => new _anthropic_ai_sdk.Anthropic(options));
|
|
670
670
|
}
|
|
671
671
|
getLsParams(options) {
|
|
672
672
|
const params = this.invocationParams(options);
|
|
@@ -686,20 +686,20 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
686
686
|
* @returns {AnthropicTool[] | undefined} The formatted tools, or undefined if none are passed.
|
|
687
687
|
*/
|
|
688
688
|
formatStructuredToolToAnthropic(tools) {
|
|
689
|
-
if (!tools) return
|
|
689
|
+
if (!tools) return;
|
|
690
690
|
return tools.map((tool) => {
|
|
691
|
-
if ((0,
|
|
691
|
+
if ((0, _langchain_core_utils_function_calling.isLangChainTool)(tool) && tool.extras?.providerToolDefinition) return tool.extras.providerToolDefinition;
|
|
692
692
|
if (isBuiltinTool(tool)) return tool;
|
|
693
693
|
if (isAnthropicTool(tool)) return tool;
|
|
694
|
-
if ((0,
|
|
694
|
+
if ((0, _langchain_core_language_models_base.isOpenAITool)(tool)) return {
|
|
695
695
|
name: tool.function.name,
|
|
696
696
|
description: tool.function.description,
|
|
697
697
|
input_schema: tool.function.parameters
|
|
698
698
|
};
|
|
699
|
-
if ((0,
|
|
699
|
+
if ((0, _langchain_core_utils_function_calling.isLangChainTool)(tool)) return {
|
|
700
700
|
name: tool.name,
|
|
701
701
|
description: tool.description,
|
|
702
|
-
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,
|
|
703
703
|
...tool.extras ? require_tools.AnthropicToolExtrasSchema.parse(tool.extras) : {}
|
|
704
704
|
};
|
|
705
705
|
throw new Error(`Unknown tool type passed to ChatAnthropic: ${JSON.stringify(tool, null, 2)}`);
|
|
@@ -731,8 +731,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
731
731
|
if (options?.outputFormat && !base.format) base.format = options.outputFormat;
|
|
732
732
|
return Object.keys(base).length > 0 ? base : void 0;
|
|
733
733
|
})();
|
|
734
|
-
const
|
|
735
|
-
const compactionBetas = hasCompaction ? ["compact-2026-01-12"] : [];
|
|
734
|
+
const compactionBetas = this.contextManagement?.edits?.some((e) => e.type === "compact_20260112") ? ["compact-2026-01-12"] : [];
|
|
736
735
|
const output = {
|
|
737
736
|
model: this.model,
|
|
738
737
|
stop_sequences: options?.stop ?? this.stopSequences,
|
|
@@ -802,8 +801,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
802
801
|
if (!result) continue;
|
|
803
802
|
const { chunk } = result;
|
|
804
803
|
const token = extractToken(chunk);
|
|
805
|
-
const generationChunk = new
|
|
806
|
-
message: new
|
|
804
|
+
const generationChunk = new _langchain_core_outputs.ChatGenerationChunk({
|
|
805
|
+
message: new _langchain_core_messages.AIMessageChunk({
|
|
807
806
|
content: chunk.content,
|
|
808
807
|
additional_kwargs: chunk.additional_kwargs,
|
|
809
808
|
tool_call_chunks: chunk.tool_call_chunks,
|
|
@@ -821,14 +820,13 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
821
820
|
async _generateNonStreaming(messages, params, requestOptions, cacheControl) {
|
|
822
821
|
let formattedMessages = require_message_inputs._convertMessagesToAnthropicPayload(messages);
|
|
823
822
|
if (cacheControl) formattedMessages = require_message_inputs.applyCacheControlToPayload(formattedMessages, cacheControl);
|
|
824
|
-
const
|
|
823
|
+
const { content, ...additionalKwargs } = await this.completionWithRetry({
|
|
825
824
|
...params,
|
|
826
825
|
stream: false,
|
|
827
826
|
...formattedMessages
|
|
828
827
|
}, requestOptions);
|
|
829
|
-
const { content,...additionalKwargs } = response;
|
|
830
828
|
const generations = require_message_outputs.anthropicResponseToChatMessages(content, additionalKwargs);
|
|
831
|
-
const { role: _role, type: _type
|
|
829
|
+
const { role: _role, type: _type, ...rest } = additionalKwargs;
|
|
832
830
|
return {
|
|
833
831
|
generations,
|
|
834
832
|
llmOutput: rest
|
|
@@ -871,26 +869,22 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
871
869
|
maxRetries: 0
|
|
872
870
|
});
|
|
873
871
|
}
|
|
874
|
-
const { betas
|
|
872
|
+
const { betas, ...rest } = request;
|
|
875
873
|
const makeCompletionRequest = async () => {
|
|
876
874
|
try {
|
|
877
|
-
if (request?.betas?.length) {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}, options);
|
|
884
|
-
return stream;
|
|
885
|
-
}
|
|
875
|
+
if (request?.betas?.length) return await this.streamingClient.beta.messages.create({
|
|
876
|
+
...rest,
|
|
877
|
+
betas,
|
|
878
|
+
...this.invocationKwargs,
|
|
879
|
+
stream: true
|
|
880
|
+
}, options);
|
|
886
881
|
return await this.streamingClient.messages.create({
|
|
887
882
|
...rest,
|
|
888
883
|
...this.invocationKwargs,
|
|
889
884
|
stream: true
|
|
890
885
|
}, options);
|
|
891
886
|
} catch (e) {
|
|
892
|
-
|
|
893
|
-
throw error;
|
|
887
|
+
throw require_errors.wrapAnthropicClientError(e);
|
|
894
888
|
}
|
|
895
889
|
};
|
|
896
890
|
return this.caller.call(makeCompletionRequest);
|
|
@@ -898,33 +892,29 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
898
892
|
/** @ignore */
|
|
899
893
|
async completionWithRetry(request, options) {
|
|
900
894
|
if (!this.batchClient) {
|
|
901
|
-
const options
|
|
895
|
+
const options = this.apiUrl ? { baseURL: this.apiUrl } : void 0;
|
|
902
896
|
this.batchClient = this.createClient({
|
|
903
897
|
dangerouslyAllowBrowser: true,
|
|
904
898
|
...this.clientOptions,
|
|
905
|
-
...options
|
|
899
|
+
...options,
|
|
906
900
|
apiKey: this.apiKey,
|
|
907
901
|
maxRetries: 0
|
|
908
902
|
});
|
|
909
903
|
}
|
|
910
|
-
const { betas
|
|
904
|
+
const { betas, ...rest } = request;
|
|
911
905
|
const makeCompletionRequest = async () => {
|
|
912
906
|
try {
|
|
913
|
-
if (request?.betas?.length) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}, options);
|
|
919
|
-
return response;
|
|
920
|
-
}
|
|
907
|
+
if (request?.betas?.length) return await this.batchClient.beta.messages.create({
|
|
908
|
+
...rest,
|
|
909
|
+
...this.invocationKwargs,
|
|
910
|
+
betas
|
|
911
|
+
}, options);
|
|
921
912
|
return await this.batchClient.messages.create({
|
|
922
913
|
...rest,
|
|
923
914
|
...this.invocationKwargs
|
|
924
915
|
}, options);
|
|
925
916
|
} catch (e) {
|
|
926
|
-
|
|
927
|
-
throw error;
|
|
917
|
+
throw require_errors.wrapAnthropicClientError(e);
|
|
928
918
|
}
|
|
929
919
|
};
|
|
930
920
|
return this.caller.callWithOptions({ signal: options.signal ?? void 0 }, makeCompletionRequest);
|
|
@@ -965,8 +955,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
965
955
|
method = "jsonSchema";
|
|
966
956
|
}
|
|
967
957
|
if (method === "jsonSchema") {
|
|
968
|
-
outputParser = (0,
|
|
969
|
-
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));
|
|
970
960
|
llm = this.withConfig({
|
|
971
961
|
outputVersion: "v0",
|
|
972
962
|
outputConfig: { format: {
|
|
@@ -981,8 +971,8 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
981
971
|
} else if (method === "functionCalling") {
|
|
982
972
|
let functionName = name ?? "extract";
|
|
983
973
|
let tools;
|
|
984
|
-
if ((0,
|
|
985
|
-
const jsonSchema = (0,
|
|
974
|
+
if ((0, _langchain_core_utils_types.isInteropZodSchema)(schema)) {
|
|
975
|
+
const jsonSchema = (0, _langchain_core_utils_json_schema.toJsonSchema)(schema);
|
|
986
976
|
tools = [{
|
|
987
977
|
name: functionName,
|
|
988
978
|
description: jsonSchema.description ?? "A function available to call.",
|
|
@@ -1017,7 +1007,7 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
1017
1007
|
tools,
|
|
1018
1008
|
ls_structured_output_format: {
|
|
1019
1009
|
kwargs: { method: "functionCalling" },
|
|
1020
|
-
schema: (0,
|
|
1010
|
+
schema: (0, _langchain_core_utils_json_schema.toJsonSchema)(schema)
|
|
1021
1011
|
}
|
|
1022
1012
|
});
|
|
1023
1013
|
const raiseIfNoToolCalls = (message) => {
|
|
@@ -1034,15 +1024,15 @@ var ChatAnthropicMessages = class extends __langchain_core_language_models_chat_
|
|
|
1034
1024
|
},
|
|
1035
1025
|
ls_structured_output_format: {
|
|
1036
1026
|
kwargs: { method: "functionCalling" },
|
|
1037
|
-
schema: (0,
|
|
1027
|
+
schema: (0, _langchain_core_utils_json_schema.toJsonSchema)(schema)
|
|
1038
1028
|
}
|
|
1039
1029
|
});
|
|
1040
1030
|
} else throw new TypeError(`Unrecognized structured output method '${method}'. Expected 'functionCalling' or 'jsonSchema'`);
|
|
1041
1031
|
if (!includeRaw) return llm.pipe(outputParser).withConfig({ runName: "ChatAnthropicStructuredOutput" });
|
|
1042
|
-
const parserAssign =
|
|
1043
|
-
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 });
|
|
1044
1034
|
const parsedWithFallback = parserAssign.withFallbacks({ fallbacks: [parserNone] });
|
|
1045
|
-
return
|
|
1035
|
+
return _langchain_core_runnables.RunnableSequence.from([{ raw: llm }, parsedWithFallback]).withConfig({ runName: "StructuredOutputRunnable" });
|
|
1046
1036
|
}
|
|
1047
1037
|
};
|
|
1048
1038
|
var ChatAnthropic = class extends ChatAnthropicMessages {};
|