Skip to content

Commit

Permalink
fix tools
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed May 30, 2024
1 parent 9dc95f0 commit 21fdc59
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions libs/langchain-mistralai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function convertMessagesToMistralMessages(
const getTools = (message: BaseMessage): MistralAIToolCalls[] | undefined => {
if (isAIMessage(message) && !!message.tool_calls?.length) {
return message.tool_calls
.map((toolCall) => ({ ...toolCall, id: "null" }))
.map((toolCall) => ({ ...toolCall, id: toolCall.id }))
.map(convertLangChainToolCallToOpenAI) as MistralAIToolCalls[];
}
if (!message.additional_kwargs.tool_calls?.length) {
Expand All @@ -196,7 +196,7 @@ function convertMessagesToMistralMessages(
const toolCalls: Omit<OpenAIToolCall, "index">[] =
message.additional_kwargs.tool_calls;
return toolCalls?.map((toolCall) => ({
id: "null",
id: toolCall.id,
type: "function",
function: toolCall.function,
}));
Expand All @@ -205,22 +205,12 @@ function convertMessagesToMistralMessages(
return messages.map((message) => {
const toolCalls = getTools(message);
const content = toolCalls === undefined ? getContent(message.content) : "";
const role = getRole(message._getType());

if (role === "tool" && toolCalls && toolCalls.length > 0) {
return {
role: "tool",
content,
name: toolCalls[0].function.name,
tool_call_id: toolCalls[0].id,
};
}

return {
role: role as "system" | "user" | "assistant",
role: getRole(message._getType()),
content,
tool_calls: toolCalls,
};
});
}) as MistralAIMessage[];
}

function mistralAIResponseToChatMessage(
Expand Down

0 comments on commit 21fdc59

Please sign in to comment.