@langchain/anthropic 0.1.14 → 0.1.15
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 +17 -13
- package/dist/chat_models.js +17 -13
- package/dist/tests/chat_models-tools.int.test.js +1 -1
- package/package.json +1 -1
package/dist/chat_models.cjs
CHANGED
|
@@ -188,24 +188,28 @@ function _formatMessagesForAnthropic(messages) {
|
|
|
188
188
|
throw new Error(`Message type "${message._getType()}" is not supported.`);
|
|
189
189
|
}
|
|
190
190
|
if ((0, messages_1.isAIMessage)(message) && !!message.tool_calls?.length) {
|
|
191
|
-
if (message.content === "") {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
191
|
+
if (typeof message.content === "string") {
|
|
192
|
+
if (message.content === "") {
|
|
193
|
+
return {
|
|
194
|
+
role,
|
|
195
|
+
content: message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
return {
|
|
200
|
+
role,
|
|
201
|
+
content: [
|
|
202
|
+
{ type: "text", text: message.content },
|
|
203
|
+
...message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
204
|
+
],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
203
207
|
}
|
|
204
208
|
else {
|
|
205
209
|
const { content } = message;
|
|
206
210
|
const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) => content.find((contentPart) => contentPart.type === "tool_use" && contentPart.id === toolCall.id));
|
|
207
211
|
if (hasMismatchedToolCalls) {
|
|
208
|
-
console.warn(`The "tool_calls" field on a message is only respected if content is
|
|
212
|
+
console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
|
|
209
213
|
}
|
|
210
214
|
return {
|
|
211
215
|
role,
|
package/dist/chat_models.js
CHANGED
|
@@ -184,24 +184,28 @@ function _formatMessagesForAnthropic(messages) {
|
|
|
184
184
|
throw new Error(`Message type "${message._getType()}" is not supported.`);
|
|
185
185
|
}
|
|
186
186
|
if (isAIMessage(message) && !!message.tool_calls?.length) {
|
|
187
|
-
if (message.content === "") {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
187
|
+
if (typeof message.content === "string") {
|
|
188
|
+
if (message.content === "") {
|
|
189
|
+
return {
|
|
190
|
+
role,
|
|
191
|
+
content: message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return {
|
|
196
|
+
role,
|
|
197
|
+
content: [
|
|
198
|
+
{ type: "text", text: message.content },
|
|
199
|
+
...message.tool_calls.map(_convertLangChainToolCallToAnthropic),
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
199
203
|
}
|
|
200
204
|
else {
|
|
201
205
|
const { content } = message;
|
|
202
206
|
const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) => content.find((contentPart) => contentPart.type === "tool_use" && contentPart.id === toolCall.id));
|
|
203
207
|
if (hasMismatchedToolCalls) {
|
|
204
|
-
console.warn(`The "tool_calls" field on a message is only respected if content is
|
|
208
|
+
console.warn(`The "tool_calls" field on a message is only respected if content is a string.`);
|
|
205
209
|
}
|
|
206
210
|
return {
|
|
207
211
|
role,
|
|
@@ -62,7 +62,7 @@ test("Few shotting with tool calls", async () => {
|
|
|
62
62
|
const res = await chat.invoke([
|
|
63
63
|
new HumanMessage("What is the weather in SF?"),
|
|
64
64
|
new AIMessage({
|
|
65
|
-
content: "",
|
|
65
|
+
content: "Let me look up the current weather.",
|
|
66
66
|
tool_calls: [
|
|
67
67
|
{
|
|
68
68
|
id: "toolu_feiwjf9u98r389u498",
|