Skip to content

Commit cb320bd

Browse files
authored
Make Codestral more configurable (#32)
Similar to Ollama allow configuration of `prompt` and `suffix` for the Codestral backend.
1 parent bd2fda1 commit cb320bd

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,31 @@ cmp_ai:setup({
121121
You will also need to make sure you have the Codestral api key in you
122122
environment, `CODESTRAL_API_KEY`.
123123

124+
You can also use the `suffix` and `prompt` parameters, see [Codestral](https://github.com/codestral/codestral) for more details.
125+
126+
```lua
127+
local cmp_ai = require('cmp_ai.config')
128+
129+
cmp_ai:setup({
130+
max_lines = 1000,
131+
provider = 'Codestral',
132+
provider_options = {
133+
model = 'codestral-latest',
134+
prompt = function(lines_before, lines_after)
135+
return lines_before
136+
end,
137+
suffix = function(lines_after)
138+
return lines_after
139+
end
140+
},
141+
notify = true,
142+
notify_callback = function(msg)
143+
vim.notify(msg)
144+
end,
145+
run_on_every_keystroke = true,
146+
})
147+
```
148+
124149
To use Google Bard:
125150

126151
```lua
@@ -170,7 +195,7 @@ cmp_ai:setup({
170195
})
171196
```
172197

173-
With Ollama you can also use the `suffix` parameter, typically when you want to use cmp-ai for codecompletion and you want to use the default plugin/prompt.
198+
With Ollama you can also use the `suffix` parameter, typically when you want to use cmp-ai for code completion and you want to use the default plugin/prompt.
174199

175200
If the model you're using has the following template:
176201
```
@@ -191,7 +216,7 @@ cmp_ai:setup({
191216
provider_options = {
192217
model = 'codegemma:2b-code',
193218
prompt = function(lines_before, lines_after)
194-
return lines_before
219+
return lines_before
195220
end,
196221
suffix = function(lines_after)
197222
return lines_after

lua/cmp_ai/backends/codestral.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ local requests = require('cmp_ai.requests')
33
Codestral = requests:new(nil)
44
BASE_URL = 'https://codestral.mistral.ai/v1/fim/completions'
55

6-
function Codestral:new(o, params)
6+
function Codestral:new(o)
77
o = o or {}
88
setmetatable(o, self)
99
self.__index = self
10-
self.params = vim.tbl_deep_extend('keep', params or {}, {
10+
self.params = vim.tbl_deep_extend('keep', o or {}, {
1111
model = 'codestral-latest',
1212
temperature = 0.1,
1313
n = 1,
@@ -35,8 +35,10 @@ function Codestral:complete(lines_before, lines_after, cb)
3535
return
3636
end
3737
local data = {
38-
prompt = lines_before,
38+
prompt = self.params.prompt and self.params.prompt(lines_before, lines_after) or lines_before,
39+
suffix = self.params.suffix and self.params.suffix(lines_after) or '',
3940
}
41+
4042
data = vim.tbl_deep_extend('keep', data, self.params)
4143
self:Get(BASE_URL, self.headers, data, function(answer)
4244
local new_data = {}

0 commit comments

Comments
 (0)