@@ -3250,11 +3250,9 @@ public void askChatGPTtoGenerateCode() {
3250
3250
3251
3251
// setup default prompt
3252
3252
String prompt =
3253
- "Write code in " + getCurrentLanguage ().getLanguageName () + ".\n " +
3254
- "Write concise and high quality code for ImageJ/Fiji.\n " +
3255
- "Put minimal comments explaining what the code does.\n " +
3256
- "The code should do the following:\n " +
3257
- getTextArea ().getSelectedText ();
3253
+ promptPrefix ()
3254
+ .replace ("{programming_language}" , getCurrentLanguage ().getLanguageName () )
3255
+ .replace ("{custom_prompt}" , getTextArea ().getSelectedText ());
3258
3256
3259
3257
String answer = askChatGPT (prompt );
3260
3258
@@ -3289,7 +3287,7 @@ private String askChatGPT(String text) {
3289
3287
3290
3288
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
3291
3289
.builder ()
3292
- .model ("gpt-3.5-turbo-0613" )
3290
+ .model (modelName () )
3293
3291
.messages (messages ).build ();
3294
3292
3295
3293
ChatMessage responseMessage = service .createChatCompletion (chatCompletionRequest ).getChoices ().get (0 ).getMessage ();
@@ -3312,6 +3310,31 @@ private String apiKey() {
3312
3310
return System .getenv ("OPENAI_API_KEY" );
3313
3311
}
3314
3312
3313
+ private String modelName () {
3314
+ if (optionsService != null ) {
3315
+ final OpenAIOptions openAIOptions =
3316
+ optionsService .getOptions (OpenAIOptions .class );
3317
+ if (openAIOptions != null ) {
3318
+ final String key = openAIOptions .getModelName ();
3319
+ if (key != null && !key .isEmpty ()) return key ;
3320
+ }
3321
+ }
3322
+ return null ;
3323
+ }
3324
+
3325
+ private String promptPrefix () {
3326
+ if (optionsService != null ) {
3327
+ final OpenAIOptions openAIOptions =
3328
+ optionsService .getOptions (OpenAIOptions .class );
3329
+ if (openAIOptions != null ) {
3330
+ final String promptPrefix = openAIOptions .getPromptPrefix ();
3331
+ if (promptPrefix != null && !promptPrefix .isEmpty ()) return promptPrefix ;
3332
+ }
3333
+ }
3334
+ return "" ;
3335
+ }
3336
+
3337
+
3315
3338
public void extractSourceJar (final File file ) {
3316
3339
try {
3317
3340
final FileFunctions functions = new FileFunctions (this );
0 commit comments