Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it clear that you.com is free in case people run out of OpenAI credits #238

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class AskAction extends AnAction {

public AskAction() {
super("Ask CodeGPT", "Chat with CodeGPT", AllIcons.Actions.Find);
super("New CodeGPT Chat", "Chat with CodeGPT", AllIcons.Actions.Find);
EditorActionsUtil.registerOrReplaceAction(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.JBColor;
import com.intellij.ui.TitledSeparator;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBPasswordField;
import com.intellij.ui.components.JBRadioButton;
import com.intellij.ui.components.JBTextField;
import com.intellij.ui.components.*;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UI;
import com.intellij.util.ui.UIUtil;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.credentials.AzureCredentialsManager;
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
Expand All @@ -20,10 +20,12 @@
import ee.carlrobert.codegpt.completions.you.YouUserManager;
import ee.carlrobert.codegpt.completions.you.auth.AuthenticationNotifier;
import ee.carlrobert.codegpt.settings.state.YouSettingsState;
import ee.carlrobert.codegpt.telemetry.ui.utils.JBLabelUtils;
import ee.carlrobert.codegpt.util.SwingUtils;
import ee.carlrobert.llm.client.openai.completion.chat.OpenAIChatCompletionModel;
import ee.carlrobert.llm.completion.CompletionModel;
import java.awt.FlowLayout;

import java.awt.*;
import java.util.List;
import java.util.Map;
import javax.swing.Box;
Expand Down Expand Up @@ -155,6 +157,10 @@ public ServiceSelectionForm(Disposable parentDisposable, SettingsState settings)
public JPanel getForm() {
var panel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
panel.add(useOpenAIServiceRadioButton);
if (OpenAISettingsState.getInstance().isOpenAIQuotaExceeded()) {
panel.add(Box.createHorizontalStrut(4));
panel.add(new JBLabel("<html><sup style=\"color: #cc3300;\">quota exceeded</sup></html>"));
}
// flow layout's horizontal gap adds annoying horizontal padding on each sides
panel.add(Box.createHorizontalStrut(16));
panel.add(useAzureServiceRadioButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void apply() {
var modelChanged = openAISettings.getModel().equals(serviceSelectionForm.getOpenAIModel()) ||
azureSettings.getModel().equals(serviceSelectionForm.getAzureModel());

var prevKey = OpenAICredentialsManager.getInstance().getApiKey();
if (prevKey != null && !prevKey.equals(serviceSelectionForm.getOpenAIApiKey())) {
OpenAISettingsState.getInstance().setOpenAIQuotaExceeded(false);
}

OpenAICredentialsManager.getInstance().setApiKey(serviceSelectionForm.getOpenAIApiKey());
AzureCredentialsManager.getInstance().setApiKey(serviceSelectionForm.getAzureOpenAIApiKey());
AzureCredentialsManager.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class OpenAISettingsState implements PersistentStateComponent<OpenAISetti
private String baseHost = "https://api.openai.com";
private String path = BASE_PATH;
private String model = OpenAIChatCompletionModel.GPT_3_5.getCode();
private boolean openAIQuotaExceeded;

public static OpenAISettingsState getInstance() {
return ApplicationManager.getApplication().getService(OpenAISettingsState.class);
Expand Down Expand Up @@ -92,4 +93,12 @@ public String getPath() {
public void setPath(String path) {
this.path = path;
}

public boolean isOpenAIQuotaExceeded() {
return openAIQuotaExceeded;
}

public void setOpenAIQuotaExceeded(boolean openAIQuotaExceeded) {
this.openAIQuotaExceeded = openAIQuotaExceeded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private boolean isRequestAllowed() {
if (SettingsState.getInstance().isUseAzureService()) {
return AzureCredentialsManager.getInstance().isCredentialSet();
}
if (SettingsState.getInstance().isUseYouService()) {
return true;
}
return OpenAICredentialsManager.getInstance().isApiKeySet();
}

Expand Down Expand Up @@ -203,6 +206,9 @@ private void call(
requestHandler.addErrorListener((error, ex) -> {
try {
if ("insufficient_quota".equals(error.getCode())) {
if (SettingsState.getInstance().isUseOpenAIService()) {
OpenAISettingsState.getInstance().setOpenAIQuotaExceeded(true);
}
responseContainer.displayQuotaExceeded();
} else {
responseContainer.displayError(error.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void displayQuotaExceeded() {
+ "You exceeded your current quota, please check your plan and billing details, "
+ "or <a href=\"#CHANGE_PROVIDER\">change</a> to a different LLM provider.</p>"
+ "</html>");

currentlyProcessedTextPane.addHyperlinkListener(e -> {
if (e.getEventType() == ACTIVATED) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, SettingsConfigurable.class);
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/messages/codegpt.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
action.editor.group.EditorActionGroup=CodeGPT
notification.group.name=CodeGPT notification group
settings.displayName=CodeGPT: Settings
settingsConfigurable.section.userAuthentication.title=Authentication
settingsConfigurable.section.userAuthentication.title=Authentication (Optional)
settingsConfigurable.section.userAuthentication.signIn.label=Sign In
settingsConfigurable.section.userInformation.title=User Information
settingsConfigurable.section.integration.apiKeyField.label=API key:
Expand All @@ -10,7 +10,7 @@ settingsConfigurable.section.integration.displayNameFieldLabel=Display name:
settingsConfigurable.section.service.title=Service Preference
settingsConfigurable.section.service.useOpenAIServiceRadioButtonLabel=Use OpenAI API
settingsConfigurable.section.service.useAzureServiceRadioButtonLabel=Use Azure OpenAI API
settingsConfigurable.section.service.useYouServiceRadioButtonLabel=Use You API
settingsConfigurable.section.service.useYouServiceRadioButtonLabel=Use You.com API (Free)
settingsConfigurable.section.service.useActiveDirectoryAuthenticationCheckBoxLabel=Use Azure active directory authentication
settingsConfigurable.section.service.openai.organizationField.label=Organization:
settingsConfigurable.section.service.openai.organizationField.comment=Useful when you are part of multiple organizations <sup><strong>optional</strong></sup>
Expand Down Expand Up @@ -69,4 +69,4 @@ toolwindow.chat.editor.action.edit.description=Edit generated code
toolwindow.chat.editor.action.newFile.title=New File
toolwindow.chat.editor.action.newFile.description=Create new file from generated code
toolwindow.chat.editor.action.replaceSelection.title=Replace Selection
toolwindow.chat.editor.action.replaceSelection.description=Replace main editor selected code
toolwindow.chat.editor.action.replaceSelection.description=Replace main editor selected code