mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-11 21:31:04 +00:00
Remove Azure model selection and max completion token limit
This commit is contained in:
parent
5446e675fc
commit
14acc5b09f
12 changed files with 40 additions and 71 deletions
|
|
@ -51,9 +51,13 @@ public class CompletionRequestHandler {
|
|||
try {
|
||||
return CompletionRequestService.getInstance()
|
||||
.getChatCompletionAsync(conversation, message, retry, useContextualSearch, eventListener);
|
||||
} catch (Throwable t) {
|
||||
toolWindowCompletionEventListener.handleError(new ErrorDetails("Something went wrong"), t);
|
||||
throw t;
|
||||
} catch (Throwable ex) {
|
||||
var errorMessage = "Something went wrong";
|
||||
if (ex instanceof TotalUsageExceededException) {
|
||||
errorMessage = "The length of the context exceeds the maximum limit that the model can handle. Try reducing the input message or maximum completion token size.";
|
||||
}
|
||||
toolWindowCompletionEventListener.handleError(new ErrorDetails(errorMessage), ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class CompletionRequestProvider {
|
|||
}
|
||||
|
||||
public OpenAIChatCompletionRequest buildOpenAIChatCompletionRequest(
|
||||
String model,
|
||||
@Nullable String model,
|
||||
Message message,
|
||||
boolean isRetry,
|
||||
boolean useContextualSearch,
|
||||
|
|
@ -126,7 +126,7 @@ public class CompletionRequestProvider {
|
|||
}
|
||||
|
||||
private List<OpenAIChatCompletionMessage> buildMessages(
|
||||
String model,
|
||||
@Nullable String model,
|
||||
Message message,
|
||||
boolean isRetry,
|
||||
boolean useContextualSearch) {
|
||||
|
|
@ -150,7 +150,7 @@ public class CompletionRequestProvider {
|
|||
messages.add(new OpenAIChatCompletionMessage("user", message.getPrompt()));
|
||||
}
|
||||
|
||||
if (SettingsState.getInstance().getSelectedService() == ServiceType.YOU) {
|
||||
if (model == null || SettingsState.getInstance().getSelectedService() == ServiceType.YOU) {
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public final class CompletionRequestService {
|
|||
var azureSettings = AzureSettingsState.getInstance();
|
||||
return CompletionClientProvider.getAzureClient().getChatCompletion(
|
||||
requestProvider.buildOpenAIChatCompletionRequest(
|
||||
azureSettings.getModel(),
|
||||
null,
|
||||
message,
|
||||
retry,
|
||||
useContextualSearch,
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public final class ConversationService {
|
|||
case OPENAI:
|
||||
return OpenAISettingsState.getInstance().getModel();
|
||||
case AZURE:
|
||||
return AzureSettingsState.getInstance().getModel();
|
||||
return AzureSettingsState.getInstance().getDeploymentId();
|
||||
case YOU:
|
||||
return "YouCode";
|
||||
case LLAMA_CPP:
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ public class SettingsConfigurable implements Configurable {
|
|||
var azureSettings = AzureSettingsState.getInstance();
|
||||
var llamaSettings = LlamaSettingsState.getInstance();
|
||||
var serviceChanged = isServiceChanged(settings);
|
||||
var modelChanged = openAISettings.getModel().equals(serviceSelectionForm.getOpenAIModel()) ||
|
||||
azureSettings.getModel().equals(serviceSelectionForm.getAzureModel());
|
||||
var modelChanged = openAISettings.getModel().equals(serviceSelectionForm.getOpenAIModel());
|
||||
|
||||
var prevKey = OpenAICredentialsManager.getInstance().getApiKey();
|
||||
if (prevKey != null && !prevKey.equals(serviceSelectionForm.getOpenAIApiKey())) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class ConfigurationComponent {
|
|||
}
|
||||
});
|
||||
|
||||
maxTokensField = new IntegerField("max_tokens", 100, 2000);
|
||||
maxTokensField = new IntegerField();
|
||||
maxTokensField.setColumns(12);
|
||||
maxTokensField.setValue(configuration.getMaxTokens());
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import com.intellij.util.ui.FormBuilder;
|
|||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UI;
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle;
|
||||
import ee.carlrobert.codegpt.completions.you.YouUserManager;
|
||||
import ee.carlrobert.codegpt.completions.you.auth.AuthenticationNotifier;
|
||||
import ee.carlrobert.codegpt.credentials.AzureCredentialsManager;
|
||||
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
||||
|
|
@ -54,7 +53,6 @@ public class ServiceSelectionForm {
|
|||
private final JBTextField azureDeploymentIdField;
|
||||
private final JBTextField azureApiVersionField;
|
||||
private final JPanel azureServiceSectionPanel;
|
||||
private final ComboBox<OpenAIChatCompletionModel> azureCompletionModelComboBox;
|
||||
|
||||
private final JPanel youServiceSectionPanel;
|
||||
private final JBCheckBox displayWebSearchResultsCheckBox;
|
||||
|
|
@ -106,17 +104,10 @@ public class ServiceSelectionForm {
|
|||
azureResourceNameField = new JBTextField(azureSettings.getResourceName(), 35);
|
||||
azureDeploymentIdField = new JBTextField(azureSettings.getDeploymentId(), 35);
|
||||
azureApiVersionField = new JBTextField(azureSettings.getApiVersion(), 35);
|
||||
azureCompletionModelComboBox = new ComboBox<>(
|
||||
new EnumComboBoxModel<>(OpenAIChatCompletionModel.class));
|
||||
azureCompletionModelComboBox.setSelectedItem(selectedOpenAIModel);
|
||||
azureCompletionModelComboBox.getEditor()
|
||||
.getEditorComponent()
|
||||
.setMaximumSize(azureBaseHostField.getPreferredSize());
|
||||
|
||||
displayWebSearchResultsCheckBox = new JBCheckBox(
|
||||
CodeGPTBundle.get("settingsConfigurable.service.you.displayResults.label"),
|
||||
YouSettingsState.getInstance().isDisplayWebSearchResults());
|
||||
displayWebSearchResultsCheckBox.setEnabled(YouUserManager.getInstance().isAuthenticated());
|
||||
|
||||
openAIServiceSectionPanel = createOpenAIServiceSectionPanel();
|
||||
azureServiceSectionPanel = createAzureServiceSectionPanel();
|
||||
|
|
@ -135,6 +126,10 @@ public class ServiceSelectionForm {
|
|||
|
||||
private JPanel createOpenAIServiceSectionPanel() {
|
||||
var requestConfigurationPanel = UI.PanelFactory.grid()
|
||||
.add(UI.PanelFactory.panel(openAICompletionModelComboBox)
|
||||
.withLabel(CodeGPTBundle.get(
|
||||
"settingsConfigurable.shared.model.label"))
|
||||
.resizeX(false))
|
||||
.add(UI.PanelFactory.panel(openAIOrganizationField)
|
||||
.withLabel(CodeGPTBundle.get(
|
||||
"settingsConfigurable.service.openai.organization.label"))
|
||||
|
|
@ -149,10 +144,6 @@ public class ServiceSelectionForm {
|
|||
.withLabel(CodeGPTBundle.get(
|
||||
"settingsConfigurable.shared.path.label"))
|
||||
.resizeX(false))
|
||||
.add(UI.PanelFactory.panel(openAICompletionModelComboBox)
|
||||
.withLabel(CodeGPTBundle.get(
|
||||
"settingsConfigurable.shared.model.label"))
|
||||
.resizeX(false))
|
||||
.createPanel();
|
||||
|
||||
var apiKeyFieldPanel = UI.PanelFactory.panel(openAIApiKeyField)
|
||||
|
|
@ -213,9 +204,6 @@ public class ServiceSelectionForm {
|
|||
.add(UI.PanelFactory.panel(azurePathField)
|
||||
.withLabel(CodeGPTBundle.get("settingsConfigurable.shared.path.label"))
|
||||
.resizeX(false))
|
||||
.add(UI.PanelFactory.panel(azureCompletionModelComboBox)
|
||||
.withLabel(CodeGPTBundle.get("settingsConfigurable.shared.model.label"))
|
||||
.resizeX(false))
|
||||
.createPanel());
|
||||
|
||||
return FormBuilder.createFormBuilder()
|
||||
|
|
@ -365,16 +353,6 @@ public class ServiceSelectionForm {
|
|||
return azureBaseHostField.getText();
|
||||
}
|
||||
|
||||
public void setAzureModel(String model) {
|
||||
azureCompletionModelComboBox.setSelectedItem(OpenAIChatCompletionModel.findByCode(model));
|
||||
}
|
||||
|
||||
public String getAzureModel() {
|
||||
return ((OpenAIChatCompletionModel) (azureCompletionModelComboBox.getModel()
|
||||
.getSelectedItem()))
|
||||
.getCode();
|
||||
}
|
||||
|
||||
public void setDisplayWebSearchResults(boolean displayWebSearchResults) {
|
||||
displayWebSearchResultsCheckBox.setSelected(displayWebSearchResults);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.intellij.openapi.components.Storage;
|
|||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import ee.carlrobert.codegpt.credentials.AzureCredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceSelectionForm;
|
||||
import ee.carlrobert.llm.client.openai.completion.chat.OpenAIChatCompletionModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@State(name = "CodeGPT_AzureSettings_210", storages = @Storage("CodeGPT_AzureSettings_210.xml"))
|
||||
|
|
@ -20,7 +19,6 @@ public class AzureSettingsState implements PersistentStateComponent<AzureSetting
|
|||
private String apiVersion = "";
|
||||
private String baseHost = "https://%s.openai.azure.com";
|
||||
private String path = BASE_PATH;
|
||||
private String model = OpenAIChatCompletionModel.GPT_3_5.getCode();
|
||||
private boolean useAzureApiKeyAuthentication = true;
|
||||
private boolean useAzureActiveDirectoryAuthentication;
|
||||
|
||||
|
|
@ -39,16 +37,20 @@ public class AzureSettingsState implements PersistentStateComponent<AzureSetting
|
|||
}
|
||||
|
||||
public boolean isModified(ServiceSelectionForm serviceSelectionForm) {
|
||||
return serviceSelectionForm.isAzureActiveDirectoryAuthenticationSelected() != isUseAzureActiveDirectoryAuthentication() ||
|
||||
serviceSelectionForm.isAzureApiKeyAuthenticationSelected() != isUseAzureApiKeyAuthentication() ||
|
||||
!serviceSelectionForm.getAzureActiveDirectoryToken().equals(AzureCredentialsManager.getInstance().getAzureActiveDirectoryToken()) ||
|
||||
!serviceSelectionForm.getAzureOpenAIApiKey().equals(AzureCredentialsManager.getInstance().getAzureOpenAIApiKey()) ||
|
||||
var credentialsManager = AzureCredentialsManager.getInstance();
|
||||
return serviceSelectionForm.isAzureActiveDirectoryAuthenticationSelected() !=
|
||||
isUseAzureActiveDirectoryAuthentication() ||
|
||||
serviceSelectionForm.isAzureApiKeyAuthenticationSelected() !=
|
||||
isUseAzureApiKeyAuthentication() ||
|
||||
!serviceSelectionForm.getAzureActiveDirectoryToken()
|
||||
.equals(credentialsManager.getAzureActiveDirectoryToken()) ||
|
||||
!serviceSelectionForm.getAzureOpenAIApiKey()
|
||||
.equals(credentialsManager.getAzureOpenAIApiKey()) ||
|
||||
!serviceSelectionForm.getAzureResourceName().equals(resourceName) ||
|
||||
!serviceSelectionForm.getAzureDeploymentId().equals(deploymentId) ||
|
||||
!serviceSelectionForm.getAzureApiVersion().equals(apiVersion) ||
|
||||
!serviceSelectionForm.getAzureBaseHost().equals(baseHost) ||
|
||||
!serviceSelectionForm.getAzurePath().equals(path) ||
|
||||
!serviceSelectionForm.getAzureModel().equals(model);
|
||||
!serviceSelectionForm.getAzurePath().equals(path);
|
||||
}
|
||||
|
||||
public void apply(ServiceSelectionForm serviceSelectionForm) {
|
||||
|
|
@ -60,20 +62,21 @@ public class AzureSettingsState implements PersistentStateComponent<AzureSetting
|
|||
apiVersion = serviceSelectionForm.getAzureApiVersion();
|
||||
baseHost = serviceSelectionForm.getAzureBaseHost();
|
||||
path = serviceSelectionForm.getAzurePath();
|
||||
model = serviceSelectionForm.getAzureModel();
|
||||
}
|
||||
|
||||
public void reset(ServiceSelectionForm serviceSelectionForm) {
|
||||
serviceSelectionForm.setAzureApiKey(AzureCredentialsManager.getInstance().getAzureOpenAIApiKey());
|
||||
serviceSelectionForm.setAzureActiveDirectoryToken(AzureCredentialsManager.getInstance().getAzureActiveDirectoryToken());
|
||||
serviceSelectionForm.setAzureApiKey(
|
||||
AzureCredentialsManager.getInstance().getAzureOpenAIApiKey());
|
||||
serviceSelectionForm.setAzureActiveDirectoryToken(
|
||||
AzureCredentialsManager.getInstance().getAzureActiveDirectoryToken());
|
||||
serviceSelectionForm.setAzureApiKeyAuthenticationSelected(useAzureApiKeyAuthentication);
|
||||
serviceSelectionForm.setAzureActiveDirectoryAuthenticationSelected(useAzureActiveDirectoryAuthentication);
|
||||
serviceSelectionForm.setAzureActiveDirectoryAuthenticationSelected(
|
||||
useAzureActiveDirectoryAuthentication);
|
||||
serviceSelectionForm.setAzureResourceName(resourceName);
|
||||
serviceSelectionForm.setAzureDeploymentId(deploymentId);
|
||||
serviceSelectionForm.setAzureApiVersion(apiVersion);
|
||||
serviceSelectionForm.setAzureBaseHost(baseHost);
|
||||
serviceSelectionForm.setAzurePath(path);
|
||||
serviceSelectionForm.setAzureModel(serviceSelectionForm.getAzureModel());
|
||||
}
|
||||
|
||||
public boolean isUsingCustomPath() {
|
||||
|
|
@ -120,14 +123,6 @@ public class AzureSettingsState implements PersistentStateComponent<AzureSetting
|
|||
this.path = path;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public boolean isUseAzureApiKeyAuthentication() {
|
||||
return useAzureApiKeyAuthentication;
|
||||
}
|
||||
|
|
@ -140,7 +135,8 @@ public class AzureSettingsState implements PersistentStateComponent<AzureSetting
|
|||
return useAzureActiveDirectoryAuthentication;
|
||||
}
|
||||
|
||||
public void setUseAzureActiveDirectoryAuthentication(boolean useAzureActiveDirectoryAuthentication) {
|
||||
public void setUseAzureActiveDirectoryAuthentication(
|
||||
boolean useAzureActiveDirectoryAuthentication) {
|
||||
this.useAzureActiveDirectoryAuthentication = useAzureActiveDirectoryAuthentication;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public class SettingsState implements PersistentStateComponent<SettingsState> {
|
|||
}
|
||||
if ("azure.chat.completion".equals(clientCode)) {
|
||||
setSelectedService(ServiceType.AZURE);
|
||||
AzureSettingsState.getInstance().setModel(conversation.getModel());
|
||||
}
|
||||
if ("llama.chat.completion".equals(clientCode)) {
|
||||
setSelectedService(ServiceType.LLAMA_CPP);
|
||||
|
|
@ -68,7 +67,7 @@ public class SettingsState implements PersistentStateComponent<SettingsState> {
|
|||
case OPENAI:
|
||||
return OpenAISettingsState.getInstance().getModel();
|
||||
case AZURE:
|
||||
return AzureSettingsState.getInstance().getModel();
|
||||
return AzureSettingsState.getInstance().getDeploymentId();
|
||||
case YOU:
|
||||
return "YouCode";
|
||||
case LLAMA_CPP:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue