@langchain/anthropic 0.3.1 → 0.3.2
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 +2 -2
- package/dist/chat_models.d.ts +0 -9
- package/dist/chat_models.js +3 -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 +1 -1
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._convertMessagesToAnthropicPayload)(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._convertMessagesToAnthropicPayload)(messages),
|
|
716
716
|
}, requestOptions);
|
|
717
717
|
const { content, ...additionalKwargs } = response;
|
|
718
718
|
const generations = (0, message_outputs_js_1.anthropicResponseToChatMessages)(content, additionalKwargs);
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -552,17 +552,8 @@ export declare class ChatAnthropicMessages<CallOptions extends ChatAnthropicCall
|
|
|
552
552
|
generations: import("@langchain/core/outputs").ChatGeneration[];
|
|
553
553
|
llmOutput: {
|
|
554
554
|
id: string;
|
|
555
|
-
/** Does nucleus sampling, in which we compute the
|
|
556
|
-
* cumulative distribution over all the options for each
|
|
557
|
-
* subsequent token in decreasing probability order and
|
|
558
|
-
* cut it off once it reaches a particular probability
|
|
559
|
-
* specified by top_p. Defaults to -1, which disables it.
|
|
560
|
-
* Note that you should either alter temperature or top_p,
|
|
561
|
-
* but not both.
|
|
562
|
-
*/
|
|
563
555
|
model: Anthropic.Messages.Model;
|
|
564
556
|
stop_reason: "tool_use" | "stop_sequence" | "end_turn" | "max_tokens" | null;
|
|
565
|
-
/** Anthropic API URL */
|
|
566
557
|
stop_sequence: string | null;
|
|
567
558
|
usage: Anthropic.Messages.Usage;
|
|
568
559
|
};
|
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 { _convertMessagesToAnthropicPayload } 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 = _convertMessagesToAnthropicPayload(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
|
+
..._convertMessagesToAnthropicPayload(messages),
|
|
713
713
|
}, requestOptions);
|
|
714
714
|
const { content, ...additionalKwargs } = response;
|
|
715
715
|
const generations = anthropicResponseToChatMessages(content, additionalKwargs);
|
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._convertMessagesToAnthropicPayload = 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, "_convertMessagesToAnthropicPayload", { enumerable: true, get: function () { return message_inputs_js_1._convertMessagesToAnthropicPayload; } });
|
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._convertMessagesToAnthropicPayload = 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 _convertMessagesToAnthropicPayload(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._convertMessagesToAnthropicPayload = _convertMessagesToAnthropicPayload;
|
|
@@ -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 _convertMessagesToAnthropicPayload(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 _convertMessagesToAnthropicPayload(messages) {
|
|
166
167
|
const mergedMessages = _mergeMessages(messages);
|
|
167
168
|
let system;
|
|
168
169
|
if (mergedMessages.length > 0 && mergedMessages[0]._getType() === "system") {
|