@@ -42,6 +42,9 @@ CodeCompletionSettings::CodeCompletionSettings()
42
42
43
43
setDisplayName (Tr::tr (" Code Completion" ));
44
44
45
+ configVersion.setSettingsKey (Constants::CC_CONFIG_VERSION);
46
+ configVersion.setDefaultValue (Constants::CC_CONFIG_VERSION_LATEST);
47
+
45
48
// Auto Completion Settings
46
49
autoCompletion.setSettingsKey (Constants::CC_AUTO_COMPLETION);
47
50
autoCompletion.setLabelText (Tr::tr (" Enable Auto Complete" ));
@@ -150,21 +153,29 @@ CodeCompletionSettings::CodeCompletionSettings()
150
153
useSystemPrompt.setLabelText (Tr::tr (" Use System Prompt" ));
151
154
152
155
systemPrompt.setSettingsKey (Constants::CC_SYSTEM_PROMPT);
153
- systemPrompt.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
154
- systemPrompt.setDefaultValue (
155
- " You are an expert C++, Qt, and QML code completion assistant. Your task is to provide "
156
+
157
+ systemPromptJinja.setSettingsKey (Constants::CC_SYSTEM_PROMPT_JINJA);
158
+ systemPromptJinja.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
159
+ systemPromptJinja.setDefaultValue (
160
+ " You are an expert {{ language }} code completion assistant. Your task is to provide "
156
161
" precise and contextually appropriate code completions.\n\n " );
162
+ systemPromptJinja.setToolTip (
163
+ Tr::tr (" The setting uses Jinja format. The following keys are available:\n "
164
+ " - language (string): Programming language for the current file\n "
165
+ " - mime_type (string): MIME type of the current file\n " ));
157
166
158
167
useUserMessageTemplateForCC.setSettingsKey (Constants::CC_USE_USER_TEMPLATE);
159
168
useUserMessageTemplateForCC.setDefaultValue (true );
160
169
useUserMessageTemplateForCC.setLabelText (
161
170
Tr::tr (" Use special system prompt and user message for non FIM models" ));
162
171
163
172
systemPromptForNonFimModels.setSettingsKey (Constants::CC_SYSTEM_PROMPT_FOR_NON_FIM);
164
- systemPromptForNonFimModels.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
165
- systemPromptForNonFimModels.setLabelText (Tr::tr (" System prompt for non FIM models:" ));
166
- systemPromptForNonFimModels.setDefaultValue (
167
- " You are an expert C++, Qt, and QML code completion assistant. Your task is to provide "
173
+
174
+ systemPromptForNonFimModelsJinja.setSettingsKey (Constants::CC_SYSTEM_PROMPT_FOR_NON_FIM_JINJA);
175
+ systemPromptForNonFimModelsJinja.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
176
+ systemPromptForNonFimModelsJinja.setLabelText (Tr::tr (" System prompt for non FIM models:" ));
177
+ systemPromptForNonFimModelsJinja.setDefaultValue (
178
+ " You are an expert {{ language }} code completion assistant. Your task is to provide "
168
179
" precise and contextually appropriate code completions.\n\n "
169
180
" Core Requirements:\n "
170
181
" 1. Continue code exactly from the cursor position, ensuring it properly connects with any "
@@ -178,19 +189,32 @@ CodeCompletionSettings::CodeCompletionSettings()
178
189
" - Ensure seamless integration with code both before and after the cursor\n\n "
179
190
" Context Format:\n "
180
191
" <code_context>\n "
181
- " {{ code before cursor}} <cursor>{{ code after cursor}} \n "
192
+ " [[ code before cursor]] <cursor>[[ code after cursor]] \n "
182
193
" </code_context>\n\n "
183
194
" Response Format:\n "
184
195
" - No explanations or comments\n "
185
196
" - Only include new characters needed to create valid code\n "
186
197
" - Should be codeblock with language\n " );
198
+ systemPromptForNonFimModelsJinja.setToolTip (
199
+ Tr::tr (" The setting uses Jinja format. The following keys are available:\n "
200
+ " - language (string): Programming language for the current file\n "
201
+ " - mime_type (string): MIME type of the current file" ));
187
202
188
203
userMessageTemplateForCC.setSettingsKey (Constants::CC_USER_TEMPLATE);
189
- userMessageTemplateForCC.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
190
- userMessageTemplateForCC.setLabelText (Tr::tr (" User message for non FIM models:" ));
191
- userMessageTemplateForCC.setDefaultValue (
204
+
205
+ userMessageTemplateForCCjinja.setSettingsKey (Constants::CC_USER_TEMPLATE_JINJA);
206
+ userMessageTemplateForCCjinja.setDisplayStyle (Utils::StringAspect::TextEditDisplay);
207
+ userMessageTemplateForCCjinja.setLabelText (Tr::tr (" User message for non FIM models:" ));
208
+ userMessageTemplateForCCjinja.setToolTip (
209
+ Tr::tr (" The setting uses Jinja format. The following keys are available:\n "
210
+ " - language (string): Programming language for the current file\n "
211
+ " - mime_type (string): MIME type of the current file\n "
212
+ " - prefix (string): The code of the current file before the cursor\n "
213
+ " - suffix (string): The code of the current file after the cursor" ));
214
+
215
+ userMessageTemplateForCCjinja.setDefaultValue (
192
216
" Here is the code context with insertion points:\n "
193
- " <code_context>\n ${ prefix} <cursor>${ suffix}\n </code_context>\n\n " );
217
+ " <code_context>\n {{ prefix }} <cursor>{{ suffix } }\n </code_context>\n\n " );
194
218
195
219
useProjectChangesCache.setSettingsKey (Constants::CC_USE_PROJECT_CHANGES_CACHE);
196
220
useProjectChangesCache.setDefaultValue (true );
@@ -222,8 +246,14 @@ CodeCompletionSettings::CodeCompletionSettings()
222
246
223
247
resetToDefaults.m_buttonText = Tr::tr (" Reset Page to Defaults" );
224
248
249
+ bool hasSavedConfigVersion = hasSavedSetting (&configVersion);
250
+
225
251
readSettings ();
226
252
253
+ if (!hasSavedConfigVersion || configVersion () < Constants::CC_CONFIG_VERSION_1_JINJA_TEMPLATES) {
254
+ upgradeOldTemplatesToJinja ();
255
+ }
256
+
227
257
readFileParts.setValue (!readFullFile.value ());
228
258
229
259
setupConnections ();
@@ -252,13 +282,13 @@ CodeCompletionSettings::CodeCompletionSettings()
252
282
auto contextItem = Column{
253
283
Row{contextGrid, Stretch{1 }},
254
284
Row{useSystemPrompt, Stretch{1 }},
255
- Group{title (Tr::tr (" Prompts for FIM models" )), Column{systemPrompt }},
285
+ Group{title (Tr::tr (" Prompts for FIM models" )), Column{systemPromptJinja }},
256
286
Group{
257
287
title (Tr::tr (" Prompts for Non FIM models" )),
258
288
Column{
259
289
Row{useUserMessageTemplateForCC, Stretch{1 }},
260
- systemPromptForNonFimModels ,
261
- userMessageTemplateForCC ,
290
+ systemPromptForNonFimModelsJinja ,
291
+ userMessageTemplateForCCjinja ,
262
292
}},
263
293
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1 }}};
264
294
@@ -347,23 +377,38 @@ void CodeCompletionSettings::resetSettingsToDefaults()
347
377
resetAspect (readStringsBeforeCursor);
348
378
resetAspect (readStringsAfterCursor);
349
379
resetAspect (useSystemPrompt);
350
- resetAspect (systemPrompt );
380
+ resetAspect (systemPromptJinja );
351
381
resetAspect (useProjectChangesCache);
352
382
resetAspect (maxChangesCacheSize);
353
383
resetAspect (ollamaLivetime);
354
384
resetAspect (contextWindow);
355
385
resetAspect (useUserMessageTemplateForCC);
356
- resetAspect (userMessageTemplateForCC );
357
- resetAspect (systemPromptForNonFimModels );
386
+ resetAspect (userMessageTemplateForCCjinja );
387
+ resetAspect (systemPromptForNonFimModelsJinja );
358
388
}
359
389
}
360
390
361
- QString CodeCompletionSettings::processMessageToFIM ( const QString &prefix, const QString &suffix) const
391
+ void CodeCompletionSettings::upgradeOldTemplatesToJinja ()
362
392
{
363
- QString result = userMessageTemplateForCC ();
364
- result.replace (" ${prefix}" , prefix);
365
- result.replace (" ${suffix}" , suffix);
366
- return result;
393
+ {
394
+ QString newTemplate = userMessageTemplateForCC ();
395
+ newTemplate.replace (" ${prefix}" , " {{ prefix }}" );
396
+ newTemplate.replace (" ${suffix}" , " {{ suffix }}" );
397
+ userMessageTemplateForCCjinja.setValue (newTemplate);
398
+ }
399
+ {
400
+ QString newTemplate = systemPromptForNonFimModels ();
401
+ newTemplate.replace (
402
+ " {{code before cursor}}<cursor>{{code after cursor}}" ,
403
+ " [[code before cursor]]<cursor>[[code after cursor]]" );
404
+ newTemplate.replace (" C++, Qt, and QML" , " {{ language }}" );
405
+ systemPromptForNonFimModelsJinja.setValue (newTemplate);
406
+ }
407
+ {
408
+ QString newTemplate = systemPrompt ();
409
+ newTemplate.replace (" C++, Qt, and QML" , " {{ language }}" );
410
+ systemPromptJinja.setValue (newTemplate);
411
+ }
367
412
}
368
413
369
414
class CodeCompletionSettingsPage : public Core ::IOptionsPage
0 commit comments