Skip to content

Commit 8bdef1a

Browse files
committed
Remove OpenAI tools
This project has been archived since Jun-6 2024, and is an overly-specific LLM integration as we now have tools like langchain4j.
1 parent 1229a13 commit 8bdef1a

File tree

3 files changed

+2
-197
lines changed

3 files changed

+2
-197
lines changed

pom.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>script-editor</artifactId>
13-
<version>1.1.2-SNAPSHOT</version>
13+
<version>1.2.0-SNAPSHOT</version>
1414

1515
<name>SciJava Script Editor</name>
1616
<description>Script Editor and Interpreter for SciJava script languages.</description>
@@ -209,17 +209,6 @@
209209
<groupId>com.formdev</groupId>
210210
<artifactId>flatlaf</artifactId>
211211
</dependency>
212-
213-
<dependency>
214-
<groupId>com.theokanning.openai-gpt3-java</groupId>
215-
<artifactId>client</artifactId>
216-
<version>0.14.0</version>
217-
</dependency>
218-
<dependency>
219-
<groupId>com.theokanning.openai-gpt3-java</groupId>
220-
<artifactId>service</artifactId>
221-
<version>0.14.0</version>
222-
</dependency>
223212
</dependencies>
224213

225214
<repositories>

src/main/java/org/scijava/ui/swing/script/OpenAIOptions.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/main/java/org/scijava/ui/swing/script/TextEditor.java

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@
118118
import javax.swing.text.Position;
119119
import javax.swing.tree.TreePath;
120120

121-
import com.theokanning.openai.completion.chat.ChatCompletionRequest;
122-
import com.theokanning.openai.completion.chat.ChatMessage;
123-
import com.theokanning.openai.completion.chat.ChatMessageRole;
124-
import com.theokanning.openai.service.OpenAiService;
125121
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
126122
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
127123
import org.fife.ui.rsyntaxtextarea.Theme;
@@ -219,8 +215,7 @@ public class TextEditor extends JFrame implements ActionListener,
219215
gotoLine, makeJar, makeJarWithSource, removeUnusedImports, sortImports,
220216
removeTrailingWhitespace, findNext, findPrevious, openHelp, addImport,
221217
nextError, previousError, openHelpWithoutFrames, nextTab,
222-
previousTab, runSelection, extractSourceJar, askChatGPTtoGenerateCode,
223-
openSourceForClass,
218+
previousTab, runSelection, extractSourceJar, openSourceForClass,
224219
//openSourceForMenuItem, // this never had an actionListener!??
225220
openMacroFunctions, decreaseFontSize, increaseFontSize, chooseFontSize,
226221
chooseTabSize, gitGrep, replaceTabsWithSpaces,
@@ -518,10 +513,6 @@ public TextEditor(final Context context) {
518513
//openSourceForMenuItem = addToMenu(toolsMenu, "Open Java File for Menu Item...", 0, 0);
519514
//openSourceForMenuItem.setMnemonic(KeyEvent.VK_M);
520515

521-
GuiUtils.addMenubarSeparator(toolsMenu, "chatGPT");
522-
askChatGPTtoGenerateCode = addToMenu(toolsMenu, "Ask chatGPT...", 0, 0);
523-
524-
525516
addScritpEditorMacroCommands(toolsMenu);
526517
mbar.add(toolsMenu);
527518

@@ -1626,7 +1617,6 @@ else if (source == chooseTabSize) {
16261617
}
16271618
else if (source == openClassOrPackageHelp) openClassOrPackageHelp(null);
16281619
else if (source == extractSourceJar) extractSourceJar();
1629-
else if (source == askChatGPTtoGenerateCode) askChatGPTtoGenerateCode();
16301620
else if (source == openSourceForClass) {
16311621
final String className = getSelectedClassNameOrAsk("Class (fully qualified name):", "Which Class?");
16321622
if (className != null) {
@@ -3243,98 +3233,6 @@ public void extractSourceJar() {
32433233
if (file != null) extractSourceJar(file);
32443234
}
32453235

3246-
public void askChatGPTtoGenerateCode() {
3247-
SwingUtilities.invokeLater(() -> {
3248-
3249-
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
3250-
3251-
// setup default prompt
3252-
String prompt =
3253-
promptPrefix()
3254-
.replace("{programming_language}", getCurrentLanguage().getLanguageName() )
3255-
.replace("{custom_prompt}", getTextArea().getSelectedText());
3256-
3257-
String answer = askChatGPT(prompt);
3258-
3259-
if (answer.contains("```")) {
3260-
// clean answer by removing blabla outside the code block
3261-
answer = answer.replace("```java", "```");
3262-
answer = answer.replace("```javascript", "```");
3263-
answer = answer.replace("```python", "```");
3264-
answer = answer.replace("```jython", "```");
3265-
answer = answer.replace("```macro", "```");
3266-
answer = answer.replace("```groovy", "```");
3267-
3268-
String[] temp = answer.split("```");
3269-
answer = temp[1];
3270-
}
3271-
3272-
//getTextArea().insert(answer, getTextArea().getCaretPosition());
3273-
getTextArea().replaceSelection(answer + "\n");
3274-
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
3275-
});
3276-
}
3277-
3278-
private String askChatGPT(String text) {
3279-
// Modified from: https://github.com/TheoKanning/openai-java/blob/main/example/src/main/java/example/OpenAiApiFunctionsExample.java
3280-
String token = apiKey();
3281-
3282-
OpenAiService service = new OpenAiService(token);
3283-
3284-
List<ChatMessage> messages = new ArrayList<>();
3285-
ChatMessage userMessage = new ChatMessage(ChatMessageRole.USER.value(), text);
3286-
messages.add(userMessage);
3287-
3288-
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
3289-
.builder()
3290-
.model(modelName())
3291-
.messages(messages).build();
3292-
3293-
ChatMessage responseMessage = service.createChatCompletion(chatCompletionRequest).getChoices().get(0).getMessage();
3294-
messages.add(responseMessage);
3295-
3296-
String result = responseMessage.getContent();
3297-
System.out.println(result);
3298-
return result;
3299-
}
3300-
3301-
private String apiKey() {
3302-
if (optionsService != null) {
3303-
final OpenAIOptions openAIOptions =
3304-
optionsService.getOptions(OpenAIOptions.class);
3305-
if (openAIOptions != null) {
3306-
final String key = openAIOptions.getOpenAIKey();
3307-
if (key != null && !key.isEmpty()) return key;
3308-
}
3309-
}
3310-
return System.getenv("OPENAI_API_KEY");
3311-
}
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-
33383236
public void extractSourceJar(final File file) {
33393237
try {
33403238
final FileFunctions functions = new FileFunctions(this);

0 commit comments

Comments
 (0)