Switch to openai-client, add conversation history empty label, remove unofficial reverse proxy (closes #43)

This commit is contained in:
Carl-Robert Linnupuu 2023-03-21 00:21:07 +00:00
parent 33a5e520f2
commit 57e1095dd1
85 changed files with 619 additions and 1828 deletions

View file

@ -0,0 +1,57 @@
package ee.carlrobert.codegpt.action;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsActions;
import ee.carlrobert.codegpt.conversations.ConversationsState;
import ee.carlrobert.codegpt.toolwindow.ContentManagerService;
import ee.carlrobert.codegpt.toolwindow.ToolWindowService;
import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class BaseAction extends AnAction {
public BaseAction(
@Nullable @NlsActions.ActionText String text,
@Nullable @NlsActions.ActionDescription String description,
@Nullable Icon icon) {
super(text, description, icon);
}
public BaseAction(@Nullable @NlsActions.ActionText String text) {
super(text);
}
protected abstract void actionPerformed(Project project, Editor editor, String selectedText);
public void actionPerformed(@NotNull AnActionEvent event) {
var project = event.getProject();
var editor = event.getData(PlatformDataKeys.EDITOR);
if (editor != null && project != null) {
actionPerformed(project, editor, editor.getSelectionModel().getSelectedText());
}
}
public void update(AnActionEvent event) {
Project project = event.getProject();
Editor editor = event.getData(PlatformDataKeys.EDITOR);
boolean menuAllowed = false;
if (editor != null && project != null) {
menuAllowed = editor.getSelectionModel().getSelectedText() != null;
}
event.getPresentation().setEnabled(menuAllowed);
}
protected void sendMessage(@NotNull Project project, String prompt) {
ConversationsState.getInstance().startConversation();
project.getService(ContentManagerService.class).displayChatTab(project);
var chatToolWindow = project.getService(ToolWindowService.class).getChatToolWindow();
chatToolWindow.clearWindow();
chatToolWindow.displayUserMessage(prompt);
chatToolWindow.sendMessage(prompt, project);
}
}