File tree Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ This fork does the following:
15
15
- ** UI Query and select** local or remote model
16
16
- ** Strips thinking tokens** from replies if the model forgets to use codeblocks
17
17
- ** New callback types** : ` insert_lines ` and ` prepend_lines `
18
+ - ** Model definition inheritance** : Define models that inherit other model parameters
18
19
- ** Refactored for idiomatic Lua** and neovim plugin style
19
20
- ** Simplified command system** with explicit configuration
20
21
- ** Tests with plenary library**
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ M.persistent_override = nil
150
150
--- @field callback_type ? codegpt.CallbackType Controls what the plugin does with the response
151
151
--- @field extra_params ? table Custom parameters to include with this model query
152
152
--- @field append_string ? string String to append to prompt -- ex : /no_think
153
+ --- @field from ? string (optional ) Name of parent model to inherit params from
153
154
154
155
--- @alias ModelDef { [string] : codegpt.Model | string }
155
156
Original file line number Diff line number Diff line change @@ -31,6 +31,15 @@ function M.get_model_by_name(name)
31
31
end
32
32
end
33
33
34
+ -- (optional) inherit a parent model
35
+ if result ~= nil and result .from ~= nil and # result .from > 0 then
36
+ local parent_name , parent = M .get_model_by_name (result .from )
37
+ if parent ~= nil then
38
+ result = vim .tbl_deep_extend (" force" , parent , result )
39
+ selected = parent_name
40
+ end
41
+ end
42
+
34
43
return selected , result
35
44
end
36
45
--- default model selection order from highest to lowest priority
@@ -74,6 +83,15 @@ function M.get_model()
74
83
end
75
84
end
76
85
86
+ -- (optional) inherit a parent model
87
+ if result ~= nil and result .from ~= nil and # result .from > 0 then
88
+ local parent_name , parent = M .get_model_by_name (result .from )
89
+ if parent ~= nil then
90
+ result = vim .tbl_deep_extend (" force" , parent , result )
91
+ selected = parent_name
92
+ end
93
+ end
94
+
77
95
return selected , result
78
96
end
79
97
Original file line number Diff line number Diff line change @@ -164,4 +164,58 @@ describe("models selection", function()
164
164
local name , model = models .get_model ()
165
165
assert (name == " gpt4-o" )
166
166
end )
167
+
168
+ it (" should inherit a model definition" , function ()
169
+ codegpt .setup ({
170
+ connection = {
171
+ api_provider = " openai" ,
172
+ },
173
+ models = {
174
+ openai = {
175
+ default = " fbar" ,
176
+ foo = {
177
+ temperature = 0.5 ,
178
+ max_tokens = 420 ,
179
+ },
180
+ foobar = {
181
+ alias = " fbar" ,
182
+ from = " foo" ,
183
+ temperature = 1 ,
184
+ append_string = " /no_think" ,
185
+ },
186
+ bar = {
187
+ from = " fbar" ,
188
+ temperature = 0 ,
189
+ },
190
+ },
191
+ },
192
+ })
193
+ local _ , model = models .get_model ()
194
+ assert (vim .deep_equal (model , {
195
+ temperature = 1 ,
196
+ alias = " fbar" ,
197
+ from = " foo" ,
198
+ max_tokens = 420 ,
199
+ append_string = " /no_think" ,
200
+ }))
201
+
202
+ local name , model = models .get_model_by_name (" fbar" )
203
+ assert (vim .deep_equal (model , {
204
+ temperature = 1 ,
205
+ alias = " fbar" ,
206
+ from = " foo" ,
207
+ max_tokens = 420 ,
208
+ append_string = " /no_think" ,
209
+ }))
210
+ assert (name == " foo" )
211
+ local name , model = models .get_model_by_name (" bar" )
212
+ assert (vim .deep_equal (model , {
213
+ temperature = 0 ,
214
+ alias = " fbar" ,
215
+ from = " fbar" ,
216
+ max_tokens = 420 ,
217
+ append_string = " /no_think" ,
218
+ }))
219
+ assert (name == " foo" )
220
+ end )
167
221
end )
You can’t perform that action at this time.
0 commit comments