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

feat: add optional host to Anthropic settings #749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = ee.carlrobert
pluginName = CodeGPT
pluginRepositoryUrl = https://github.com/carlrobertoh/CodeGPT
# SemVer format -> https://semver.org
pluginVersion = 2.12.0
pluginVersion = 2.12.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 241.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public static OpenAIClient getOpenAIClient() {
}

public static ClaudeClient getClaudeClient() {
final ClaudeClient.Builder builder = new ClaudeClient.Builder(getCredential(CredentialKey.ANTHROPIC_API_KEY), AnthropicSettings.getCurrentState().getApiVersion());
if (AnthropicSettings.getCurrentState().getHost() != null && !AnthropicSettings.getCurrentState().getHost().isEmpty()) {
builder.setHost(AnthropicSettings.getCurrentState().getHost());
}
return new ClaudeClient(
getCredential(CredentialKey.ANTHROPIC_API_KEY),
AnthropicSettings.getCurrentState().getApiVersion(),
builder,
getDefaultClientBuilder());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AnthropicSettingsForm {
private final JBPasswordField apiKeyField;
private final JBTextField apiVersionField;
private final JBTextField modelField;
private final JBTextField hostField;

public AnthropicSettingsForm(AnthropicSettingsState settings) {
apiKeyField = new JBPasswordField();
Expand All @@ -29,6 +30,7 @@ public AnthropicSettingsForm(AnthropicSettingsState settings) {
});
apiVersionField = new JBTextField(settings.getApiVersion(), 35);
modelField = new JBTextField(settings.getModel(), 35);
hostField = new JBTextField(settings.getHost(), 35);
}

public JPanel getForm() {
Expand All @@ -51,6 +53,11 @@ public JPanel getForm() {
.withComment(CodeGPTBundle.get(
"settingsConfigurable.service.anthropic.model.comment"))
.resizeX(false))
.add(UI.PanelFactory.panel(hostField)
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.custom.anthropic.url.label"))
.withComment(CodeGPTBundle.get(
"settingsConfigurable.service.anthropic.url.comment"))
.resizeX(false))
.createPanel())
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
Expand All @@ -60,6 +67,7 @@ public AnthropicSettingsState getCurrentState() {
var state = new AnthropicSettingsState();
state.setModel(modelField.getText());
state.setApiVersion(apiVersionField.getText());
state.setHost(hostField.getText());
return state;
}

Expand All @@ -68,6 +76,7 @@ public void resetForm() {
apiKeyField.setText(CredentialsStore.getCredential(ANTHROPIC_API_KEY));
apiVersionField.setText(state.getApiVersion());
modelField.setText(state.getModel());
hostField.setText(state.getHost());
}

public @Nullable String getApiKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class AnthropicSettingsState {

private String apiVersion = "2023-06-01";
private String model = "claude-3-opus-20240229";
private String host = "";

public String getApiVersion() {
return apiVersion;
Expand All @@ -23,6 +24,14 @@ public void setModel(String model) {
this.model = model;
}

public String getHost() {
return host;
}

public void setHost(final String host) {
this.host = host;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -32,11 +41,11 @@ public boolean equals(Object o) {
return false;
}
AnthropicSettingsState that = (AnthropicSettingsState) o;
return Objects.equals(apiVersion, that.apiVersion) && Objects.equals(model, that.model);
return Objects.equals(apiVersion, that.apiVersion) && Objects.equals(model, that.model) && Objects.equals(host, that.host);
}

@Override
public int hashCode() {
return Objects.hash(apiVersion, model);
return Objects.hash(apiVersion, model, host);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/codegpt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ settingsConfigurable.service.openai.organization.label=Organization:
settingsConfigurable.section.openai.organization.comment=Useful when you are part of multiple organizations <sup><strong>optional</strong></sup>
settingsConfigurable.service.google.apiKey.comment=You can find the API key in your <a href="https://aistudio.google.com/app/apikey">User settings</a>.
settingsConfigurable.service.google.model.comment=Note: Gemini Vision models <a href="https://ai.google.dev/gemini-api/docs/get-started/web?multi-turn-conversations-chat&hl=en#multi-turn-conversations-chat">do not yet support chats</a>.
settingsConfigurable.service.custom.anthropic.url.label=URL:
settingsConfigurable.service.anthropic.apiKey.comment=You can find the API key in your <a href="https://console.anthropic.com/settings/keys">User settings</a>.
settingsConfigurable.service.anthropic.apiVersion.comment=We always recommend using the <a href="https://docs.anthropic.com/claude/reference/versions">latest API version</a> whenever possible.
settingsConfigurable.service.anthropic.model.comment=For details on model comparison metrics, see <a href="https://docs.anthropic.com/claude/docs/models-overview#model-comparison">model comparison</a>.
settingsConfigurable.service.anthropic.url.comment=Optional, defaults to https://api.anthropic.com.
settingsConfigurable.service.azure.resourceName.label=Resource name:
settingsConfigurable.service.azure.resourceName.comment=The name of your Azure OpenAI resource.
settingsConfigurable.service.azure.deploymentId.label=Deployment ID:
Expand Down
Loading