Skip to content

Commit 82584b1

Browse files
committed
fix style
1 parent 400b855 commit 82584b1

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

lua/codecompanion/adapters/http/mistral.lua

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local adapter_utils = require("codecompanion.utils.adapters")
22
local log = require("codecompanion.utils.log")
33
local openai = require("codecompanion.adapters.http.openai")
4-
local log = require("codecompanion.utils.log")
54

65
---@class CodeCompanion.HTTPAdapter.Mistral: CodeCompanion.HTTPAdapter
76
return {
@@ -63,21 +62,19 @@ return {
6362
end,
6463
form_messages = function(self, messages)
6564
local is_previous_tool = false
66-
local messages = vim
67-
.iter(messages)
68-
:filter(function(msg)
69-
local is_tool = msg.role == "tool"
70-
local is_user = msg.role == "user"
71-
local keep = true
72-
-- Mistral does not like user after tool messages, those should always be assistant
73-
-- Worst case we drop 1 user message, but the assistant will respond to the tool
74-
if is_previous_tool and is_user then
75-
log:debug("Dropping user after tool message: %s", msg.content)
76-
keep = false
77-
end
78-
is_previous_tool = is_tool
79-
return keep
80-
end)
65+
local messages = vim.iter(messages):filter(function(msg)
66+
local is_tool = msg.role == "tool"
67+
local is_user = msg.role == "user"
68+
local keep = true
69+
-- Mistral does not like user after tool messages, those should always be assistant
70+
-- Worst case we drop 1 user message, but the assistant will respond to the tool
71+
if is_previous_tool and is_user then
72+
log:debug("Dropping user after tool message: %s", msg.content)
73+
keep = false
74+
end
75+
is_previous_tool = is_tool
76+
return keep
77+
end)
8178
return openai.handlers.form_messages(self, messages)
8279
end,
8380
chat_output = function(self, data, tools)

tests/adapters/http/test_mistral.lua

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ T["Mistral adapter"]["form_messages"]["it can form messages with tools"] = funct
5050
},
5151
},
5252
},
53-
{ role = "tool", content = "ok", },
54-
{ role = "assistant", content = "that works" }
53+
{ role = "tool", content = "ok" },
54+
{ role = "assistant", content = "that works" },
5555
}
5656

5757
local expected = {
@@ -85,8 +85,8 @@ T["Mistral adapter"]["form_messages"]["it can form messages with tools"] = funct
8585
},
8686
},
8787
},
88-
{ role = "tool", content = "ok", },
89-
{ role = "assistant", content = "that works" }
88+
{ role = "tool", content = "ok" },
89+
{ role = "assistant", content = "that works" },
9090
},
9191
}
9292

@@ -111,8 +111,8 @@ T["Mistral adapter"]["form_messages"]["it skips messages when user follows tools
111111
},
112112
},
113113
},
114-
{ role = "tool", content = "ok", },
115-
{ role = "user", content = "my message" }
114+
{ role = "tool", content = "ok" },
115+
{ role = "user", content = "my message" },
116116
}
117117

118118
local expected = {
@@ -141,7 +141,6 @@ T["Mistral adapter"]["form_messages"]["it skips messages when user follows tools
141141
h.eq(expected, adapter.handlers.form_messages(adapter, input))
142142
end
143143

144-
145144
T["Mistral adapter"]["form_messages"]["it can form tools to be sent to the API"] = function()
146145
adapter = require("codecompanion.adapters").extend("mistral", {
147146
schema = {

0 commit comments

Comments
 (0)