@langchain/anthropic 0.3.0 → 0.3.2-rc.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/dist/chat_models.cjs +4 -2
- package/dist/chat_models.js +5 -3
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/message_inputs.cjs +4 -3
- package/dist/utils/message_inputs.d.ts +2 -1
- package/dist/utils/message_inputs.js +2 -1
- package/package.json +2 -2
package/dist/chat_models.cjs
CHANGED
|
@@ -661,7 +661,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
661
661
|
}
|
|
662
662
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
663
663
|
const params = this.invocationParams(options);
|
|
664
|
-
const formattedMessages = (0, message_inputs_js_1.
|
|
664
|
+
const formattedMessages = (0, message_inputs_js_1._convertMessagesToAnthropic)(messages);
|
|
665
665
|
const coerceContentToString = !_toolsInParams({
|
|
666
666
|
...params,
|
|
667
667
|
...formattedMessages,
|
|
@@ -712,7 +712,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
712
712
|
const response = await this.completionWithRetry({
|
|
713
713
|
...params,
|
|
714
714
|
stream: false,
|
|
715
|
-
...(0, message_inputs_js_1.
|
|
715
|
+
...(0, message_inputs_js_1._convertMessagesToAnthropic)(messages),
|
|
716
716
|
}, requestOptions);
|
|
717
717
|
const { content, ...additionalKwargs } = response;
|
|
718
718
|
const generations = (0, message_outputs_js_1.anthropicResponseToChatMessages)(content, additionalKwargs);
|
|
@@ -766,6 +766,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
766
766
|
if (!this.streamingClient) {
|
|
767
767
|
const options_ = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
|
|
768
768
|
this.streamingClient = this.createClient({
|
|
769
|
+
dangerouslyAllowBrowser: true,
|
|
769
770
|
...this.clientOptions,
|
|
770
771
|
...options_,
|
|
771
772
|
apiKey: this.apiKey,
|
|
@@ -785,6 +786,7 @@ class ChatAnthropicMessages extends chat_models_1.BaseChatModel {
|
|
|
785
786
|
if (!this.batchClient) {
|
|
786
787
|
const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
|
|
787
788
|
this.batchClient = this.createClient({
|
|
789
|
+
dangerouslyAllowBrowser: true,
|
|
788
790
|
...this.clientOptions,
|
|
789
791
|
...options,
|
|
790
792
|
apiKey: this.apiKey,
|
package/dist/chat_models.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isZodSchema } from "@langchain/core/utils/types";
|
|
|
10
10
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
11
11
|
import { AnthropicToolsOutputParser } from "./output_parsers.js";
|
|
12
12
|
import { extractToolCallChunk, handleToolChoice } from "./utils/tools.js";
|
|
13
|
-
import {
|
|
13
|
+
import { _convertMessagesToAnthropic } from "./utils/message_inputs.js";
|
|
14
14
|
import { _makeMessageChunkFromAnthropicEvent, anthropicResponseToChatMessages, } from "./utils/message_outputs.js";
|
|
15
15
|
function _toolsInParams(params) {
|
|
16
16
|
return !!(params.tools && params.tools.length > 0);
|
|
@@ -658,7 +658,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
658
658
|
}
|
|
659
659
|
async *_streamResponseChunks(messages, options, runManager) {
|
|
660
660
|
const params = this.invocationParams(options);
|
|
661
|
-
const formattedMessages =
|
|
661
|
+
const formattedMessages = _convertMessagesToAnthropic(messages);
|
|
662
662
|
const coerceContentToString = !_toolsInParams({
|
|
663
663
|
...params,
|
|
664
664
|
...formattedMessages,
|
|
@@ -709,7 +709,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
709
709
|
const response = await this.completionWithRetry({
|
|
710
710
|
...params,
|
|
711
711
|
stream: false,
|
|
712
|
-
...
|
|
712
|
+
..._convertMessagesToAnthropic(messages),
|
|
713
713
|
}, requestOptions);
|
|
714
714
|
const { content, ...additionalKwargs } = response;
|
|
715
715
|
const generations = anthropicResponseToChatMessages(content, additionalKwargs);
|
|
@@ -763,6 +763,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
763
763
|
if (!this.streamingClient) {
|
|
764
764
|
const options_ = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
|
|
765
765
|
this.streamingClient = this.createClient({
|
|
766
|
+
dangerouslyAllowBrowser: true,
|
|
766
767
|
...this.clientOptions,
|
|
767
768
|
...options_,
|
|
768
769
|
apiKey: this.apiKey,
|
|
@@ -782,6 +783,7 @@ export class ChatAnthropicMessages extends BaseChatModel {
|
|
|
782
783
|
if (!this.batchClient) {
|
|
783
784
|
const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
|
|
784
785
|
this.batchClient = this.createClient({
|
|
786
|
+
dangerouslyAllowBrowser: true,
|
|
785
787
|
...this.clientOptions,
|
|
786
788
|
...options,
|
|
787
789
|
apiKey: this.apiKey,
|
package/dist/index.cjs
CHANGED
|
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports._convertMessagesToAnthropic = void 0;
|
|
17
18
|
__exportStar(require("./chat_models.cjs"), exports);
|
|
19
|
+
var message_inputs_js_1 = require("./utils/message_inputs.cjs");
|
|
20
|
+
Object.defineProperty(exports, "_convertMessagesToAnthropic", { enumerable: true, get: function () { return message_inputs_js_1._convertMessagesToAnthropic; } });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports._convertMessagesToAnthropic = exports._convertLangChainToolCallToAnthropic = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* This util file contains functions for converting LangChain messages to Anthropic messages.
|
|
6
6
|
*/
|
|
@@ -163,10 +163,11 @@ function _formatContent(content) {
|
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Formats messages as a prompt for the model.
|
|
166
|
+
* Used in LangSmith, export is important here.
|
|
166
167
|
* @param messages The base messages to format as a prompt.
|
|
167
168
|
* @returns The formatted prompt.
|
|
168
169
|
*/
|
|
169
|
-
function
|
|
170
|
+
function _convertMessagesToAnthropic(messages) {
|
|
170
171
|
const mergedMessages = _mergeMessages(messages);
|
|
171
172
|
let system;
|
|
172
173
|
if (mergedMessages.length > 0 && mergedMessages[0]._getType() === "system") {
|
|
@@ -234,4 +235,4 @@ function _formatMessagesForAnthropic(messages) {
|
|
|
234
235
|
system,
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
|
-
exports.
|
|
238
|
+
exports._convertMessagesToAnthropic = _convertMessagesToAnthropic;
|
|
@@ -7,7 +7,8 @@ import { AnthropicMessageCreateParams, AnthropicToolResponse } from "../types.js
|
|
|
7
7
|
export declare function _convertLangChainToolCallToAnthropic(toolCall: ToolCall): AnthropicToolResponse;
|
|
8
8
|
/**
|
|
9
9
|
* Formats messages as a prompt for the model.
|
|
10
|
+
* Used in LangSmith, export is important here.
|
|
10
11
|
* @param messages The base messages to format as a prompt.
|
|
11
12
|
* @returns The formatted prompt.
|
|
12
13
|
*/
|
|
13
|
-
export declare function
|
|
14
|
+
export declare function _convertMessagesToAnthropic(messages: BaseMessage[]): AnthropicMessageCreateParams;
|
|
@@ -159,10 +159,11 @@ function _formatContent(content) {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Formats messages as a prompt for the model.
|
|
162
|
+
* Used in LangSmith, export is important here.
|
|
162
163
|
* @param messages The base messages to format as a prompt.
|
|
163
164
|
* @returns The formatted prompt.
|
|
164
165
|
*/
|
|
165
|
-
export function
|
|
166
|
+
export function _convertMessagesToAnthropic(messages) {
|
|
166
167
|
const mergedMessages = _mergeMessages(messages);
|
|
167
168
|
let system;
|
|
168
169
|
if (mergedMessages.length > 0 && mergedMessages[0]._getType() === "system") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/anthropic",
|
|
3
|
-
"version": "0.3.0",
|
|
3
|
+
"version": "0.3.2-rc.0",
|
|
4
4
|
"description": "Anthropic integrations for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"author": "LangChain",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@anthropic-ai/sdk": "^0.
|
|
38
|
+
"@anthropic-ai/sdk": "^0.27.3",
|
|
39
39
|
"fast-xml-parser": "^4.4.1",
|
|
40
40
|
"zod": "^3.22.4",
|
|
41
41
|
"zod-to-json-schema": "^3.22.4"
|