Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@langchain/anthropic

Package Overview
Dependencies
Maintainers
0
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@langchain/anthropic - npm Package Compare versions

Comparing version 0.3.10 to 0.3.11

9

dist/chat_models.d.ts

@@ -523,4 +523,4 @@ import { Anthropic, type ClientOptions } from "@anthropic-ai/sdk";

tools?: Anthropic.Messages.Tool[] | undefined;
tool_choice?: Anthropic.Messages.MessageCreateParams.ToolChoiceAuto | Anthropic.Messages.MessageCreateParams.ToolChoiceAny | Anthropic.Messages.MessageCreateParams.ToolChoiceTool | undefined;
metadata?: Anthropic.Messages.MessageCreateParams.Metadata | undefined;
tool_choice?: Anthropic.Messages.ToolChoice | undefined;
metadata?: Anthropic.Messages.Metadata | undefined;
temperature?: number | undefined;

@@ -541,4 +541,4 @@ stream?: boolean | undefined;

tools?: Anthropic.Messages.Tool[] | undefined;
tool_choice?: Anthropic.Messages.MessageCreateParams.ToolChoiceAuto | Anthropic.Messages.MessageCreateParams.ToolChoiceAny | Anthropic.Messages.MessageCreateParams.ToolChoiceTool | undefined;
metadata?: Anthropic.Messages.MessageCreateParams.Metadata | undefined;
tool_choice?: Anthropic.Messages.ToolChoice | undefined;
metadata?: Anthropic.Messages.Metadata | undefined;
temperature?: number | undefined;

@@ -559,3 +559,2 @@ stream?: boolean | undefined;

stop_reason: "tool_use" | "stop_sequence" | "end_turn" | "max_tokens" | null;
/** Anthropic API key */
stop_sequence: string | null;

@@ -562,0 +561,0 @@ usage: Anthropic.Messages.Usage;

@@ -21,1 +21,5 @@ import Anthropic from "@anthropic-ai/sdk";

export type ChatAnthropicToolType = AnthropicTool | BindToolsInput;
export type AnthropicTextBlockParam = Anthropic.Messages.TextBlockParam;
export type AnthropicImageBlockParam = Anthropic.Messages.ImageBlockParam;
export type AnthropicToolUseBlockParam = Anthropic.Messages.ToolUseBlockParam;
export type AnthropicToolResultBlockParam = Anthropic.Messages.ToolResultBlockParam;

@@ -217,5 +217,52 @@ /**

return {
messages: formattedMessages,
messages: mergeMessages(formattedMessages),
system,
};
}
function mergeMessages(messages) {
if (!messages || messages.length <= 1) {
return messages;
}
const result = [];
let currentMessage = messages[0];
const normalizeContent = (content) => {
if (typeof content === "string") {
return [
{
type: "text",
text: content,
},
];
}
return content;
};
const isToolResultMessage = (msg) => {
if (msg.role !== "user")
return false;
if (typeof msg.content === "string") {
return false;
}
return (Array.isArray(msg.content) &&
msg.content.every((item) => item.type === "tool_result"));
};
for (let i = 1; i < messages.length; i += 1) {
const nextMessage = messages[i];
if (isToolResultMessage(currentMessage) &&
isToolResultMessage(nextMessage)) {
// Merge the messages by combining their content arrays
currentMessage = {
...currentMessage,
content: [
...normalizeContent(currentMessage.content),
...normalizeContent(nextMessage.content),
],
};
}
else {
result.push(currentMessage);
currentMessage = nextMessage;
}
}
result.push(currentMessage);
return result;
}

@@ -14,2 +14,3 @@ import { AIMessage, AIMessageChunk, } from "@langchain/core/messages";

}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { input_tokens, output_tokens, ...rest } = usage ?? {};

@@ -20,2 +21,6 @@ const usageMetadata = {

total_tokens: input_tokens + output_tokens,
input_token_details: {
cache_creation: rest.cache_creation_input_tokens,
cache_read: rest.cache_read_input_tokens,
},
};

@@ -41,2 +46,8 @@ return {

total_tokens: data.usage.output_tokens,
input_token_details: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cache_creation: data.usage.cache_creation_input_tokens,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cache_read: data.usage.cache_read_input_tokens,
},
};

@@ -147,2 +158,6 @@ return {

total_tokens: (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0),
input_token_details: {
cache_creation: usage.cache_creation_input_tokens,
cache_read: usage.cache_read_input_tokens,
},
}

@@ -149,0 +164,0 @@ : undefined;

{
"name": "@langchain/anthropic",
"version": "0.3.10",
"version": "0.3.11",
"description": "Anthropic integrations for LangChain.js",

@@ -38,3 +38,3 @@ "type": "module",

"dependencies": {
"@anthropic-ai/sdk": "^0.27.3",
"@anthropic-ai/sdk": "^0.32.1",
"fast-xml-parser": "^4.4.1",

@@ -41,0 +41,0 @@ "zod": "^3.22.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc