@@ -3250,11 +3250,9 @@ public void askChatGPTtoGenerateCode() {
32503250
32513251 // setup default prompt
32523252 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 ());
32583256
32593257 String answer = askChatGPT (prompt );
32603258
@@ -3289,7 +3287,7 @@ private String askChatGPT(String text) {
32893287
32903288 ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
32913289 .builder ()
3292- .model ("gpt-3.5-turbo-0613" )
3290+ .model (modelName () )
32933291 .messages (messages ).build ();
32943292
32953293 ChatMessage responseMessage = service .createChatCompletion (chatCompletionRequest ).getChoices ().get (0 ).getMessage ();
@@ -3312,6 +3310,31 @@ private String apiKey() {
33123310 return System .getenv ("OPENAI_API_KEY" );
33133311 }
33143312
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+
33153338 public void extractSourceJar (final File file ) {
33163339 try {
33173340 final FileFunctions functions = new FileFunctions (this );
0 commit comments