Skip to content

Commit 33f9472

Browse files
Remove legacy anthropic tool use code from mistral-format (RooCodeInc#2103)
* remove claude tool use backwards compatability * remove anthropic tool use from mistal-format * further simplify mistral-format * fix linting error in unrelated file
1 parent 49f0c92 commit 33f9472

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

src/api/transform/mistral-format.ts

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Anthropic } from "@anthropic-ai/sdk"
2-
import { Mistral } from "@mistralai/mistralai"
32
import { AssistantMessage } from "@mistralai/mistralai/models/components/assistantmessage"
43
import { SystemMessage } from "@mistralai/mistralai/models/components/systemmessage"
54
import { ToolMessage } from "@mistralai/mistralai/models/components/toolmessage"
@@ -21,25 +20,15 @@ export function convertToMistralMessages(anthropicMessages: Anthropic.Messages.M
2120
})
2221
} else {
2322
if (anthropicMessage.role === "user") {
24-
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce<{
25-
nonToolMessages: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[]
26-
toolMessages: Anthropic.ToolResultBlockParam[]
27-
}>(
28-
(acc, part) => {
29-
if (part.type === "tool_result") {
30-
acc.toolMessages.push(part)
31-
} else if (part.type === "text" || part.type === "image") {
32-
acc.nonToolMessages.push(part)
33-
} // user cannot send tool_use messages
34-
return acc
35-
},
36-
{ nonToolMessages: [], toolMessages: [] },
23+
// Filter to only include text and image blocks
24+
const textAndImageBlocks = anthropicMessage.content.filter(
25+
(part) => part.type === "text" || part.type === "image",
3726
)
3827

39-
if (nonToolMessages.length > 0) {
28+
if (textAndImageBlocks.length > 0) {
4029
mistralMessages.push({
4130
role: "user",
42-
content: nonToolMessages.map((part) => {
31+
content: textAndImageBlocks.map((part) => {
4332
if (part.type === "image") {
4433
return {
4534
type: "image_url",
@@ -53,37 +42,17 @@ export function convertToMistralMessages(anthropicMessages: Anthropic.Messages.M
5342
})
5443
}
5544
} else if (anthropicMessage.role === "assistant") {
56-
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce<{
57-
nonToolMessages: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[]
58-
toolMessages: Anthropic.ToolUseBlockParam[]
59-
}>(
60-
(acc, part) => {
61-
if (part.type === "tool_use") {
62-
acc.toolMessages.push(part)
63-
} else if (part.type === "text" || part.type === "image") {
64-
acc.nonToolMessages.push(part)
65-
} // assistant cannot send tool_result messages
66-
return acc
67-
},
68-
{ nonToolMessages: [], toolMessages: [] },
69-
)
45+
// Only process text blocks - assistant cannot send images or other content types in Mistral's API format
46+
const textBlocks = anthropicMessage.content.filter((part) => part.type === "text")
7047

71-
let content: string | undefined
72-
if (nonToolMessages.length > 0) {
73-
content = nonToolMessages
74-
.map((part) => {
75-
if (part.type === "image") {
76-
return "" // impossible as the assistant cannot send images
77-
}
78-
return part.text
79-
})
80-
.join("\n")
81-
}
48+
if (textBlocks.length > 0) {
49+
const content = textBlocks.map((part) => part.text).join("\n")
8250

83-
mistralMessages.push({
84-
role: "assistant",
85-
content,
86-
})
51+
mistralMessages.push({
52+
role: "assistant",
53+
content,
54+
})
55+
}
8756
}
8857
}
8958
}

0 commit comments

Comments
 (0)