Skip to content

Commit

Permalink
chore: lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Nov 22, 2024
1 parent a03523c commit a3c60d2
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions libs/langchain-community/src/utils/bedrock/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ function _formatContent(content: MessageContent) {
type: "image" as const, // Explicitly setting the type as "image"
source,
};
} else if (contentPart.type === "text" || contentPart.type === "text_delta") {
} else if (
contentPart.type === "text" ||
contentPart.type === "text_delta"
) {
if (contentPart.text === "") {
return [];
}
Expand Down Expand Up @@ -209,29 +212,17 @@ export function formatMessagesForAnthropic(messages: BaseMessage[]): {
};
}
} else {
const { content } = message;
const hasMismatchedToolCalls = !message.tool_calls.every((toolCall) =>
content.find(
(contentPart) =>
contentPart.type === "tool_use" && contentPart.id === toolCall.id
)
);
if (hasMismatchedToolCalls) {
console.warn(
`The "tool_calls" field on a message is only respected if content is a string.`
);
}


const formattedContent = _formatContent(message.content);
if (Array.isArray(formattedContent)) {
const formattedToolsContent = message.tool_calls.map(_convertLangChainToolCallToAnthropic);
const formattedToolsContent = message.tool_calls.map(
_convertLangChainToolCallToAnthropic
);
return {
role,
content: [
...formattedContent,
...formattedToolsContent
]
}
content: [...formattedContent, ...formattedToolsContent],
};
}

return {
Expand Down

0 comments on commit a3c60d2

Please sign in to comment.