@langchain/anthropic
Advanced tools
Comparing version 0.3.7 to 0.3.8
@@ -21,9 +21,9 @@ /** | ||
} | ||
function _mergeMessages(messages) { | ||
function _ensureMessageContents(messages) { | ||
// Merge runs of human/tool messages into single human messages with content blocks. | ||
const merged = []; | ||
const updatedMsgs = []; | ||
for (const message of messages) { | ||
if (message._getType() === "tool") { | ||
if (typeof message.content === "string") { | ||
const previousMessage = merged[merged.length - 1]; | ||
const previousMessage = updatedMsgs[updatedMsgs.length - 1]; | ||
if (previousMessage?._getType() === "human" && | ||
@@ -42,3 +42,3 @@ Array.isArray(previousMessage.content) && | ||
// If not, we create a new human message with the tool result. | ||
merged.push(new HumanMessage({ | ||
updatedMsgs.push(new HumanMessage({ | ||
content: [ | ||
@@ -55,3 +55,3 @@ { | ||
else { | ||
merged.push(new HumanMessage({ | ||
updatedMsgs.push(new HumanMessage({ | ||
content: [ | ||
@@ -68,27 +68,6 @@ { | ||
else { | ||
const previousMessage = merged[merged.length - 1]; | ||
if (previousMessage?._getType() === "human" && | ||
message._getType() === "human") { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let combinedContent; | ||
if (typeof previousMessage.content === "string") { | ||
combinedContent = [{ type: "text", text: previousMessage.content }]; | ||
} | ||
else { | ||
combinedContent = previousMessage.content; | ||
} | ||
if (typeof message.content === "string") { | ||
combinedContent.push({ type: "text", text: message.content }); | ||
} | ||
else { | ||
combinedContent = combinedContent.concat(message.content); | ||
} | ||
previousMessage.content = combinedContent; | ||
} | ||
else { | ||
merged.push(message); | ||
} | ||
updatedMsgs.push(message); | ||
} | ||
} | ||
return merged; | ||
return updatedMsgs; | ||
} | ||
@@ -179,3 +158,3 @@ export function _convertLangChainToolCallToAnthropic(toolCall) { | ||
export function _convertMessagesToAnthropicPayload(messages) { | ||
const mergedMessages = _mergeMessages(messages); | ||
const mergedMessages = _ensureMessageContents(messages); | ||
let system; | ||
@@ -182,0 +161,0 @@ if (mergedMessages.length > 0 && mergedMessages[0]._getType() === "system") { |
{ | ||
"name": "@langchain/anthropic", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "Anthropic integrations for LangChain.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
183841
4833