@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.
@@ -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
- return {
193
- role,
194
- content: message.tool_calls.map(_convertLangChainToolCallToAnthropic),
195
- };
196
- }
197
- else if (typeof message.content === "string") {
198
- console.warn(`The "tool_calls" field on a message is only respected if content is an empty string.`);
199
- return {
200
- role,
201
- content: _formatContent(message.content),
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 an empty string.`);
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,
@@ -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
- return {
189
- role,
190
- content: message.tool_calls.map(_convertLangChainToolCallToAnthropic),
191
- };
192
- }
193
- else if (typeof message.content === "string") {
194
- console.warn(`The "tool_calls" field on a message is only respected if content is an empty string.`);
195
- return {
196
- role,
197
- content: _formatContent(message.content),
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 an empty string.`);
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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/anthropic",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Anthropic integrations for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {