mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 22:31:24 +00:00
refactor: Expand and explicitly handle cases where a ServiceType is checked (#521)
This streamlines changes to ServiceType, where any additions or removals will be flagged at compile time to be handled, instead of silently falling back to a default value.
This commit is contained in:
parent
5f5c9cbfa1
commit
f44fab551b
3 changed files with 35 additions and 33 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package ee.carlrobert.codegpt.completions;
|
||||
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.ANTHROPIC;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.AZURE;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.CUSTOM_OPENAI;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.LLAMA_CPP;
|
||||
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
|
||||
|
|
@ -226,19 +224,15 @@ public final class CompletionRequestService {
|
|||
}
|
||||
|
||||
public static boolean isRequestAllowed(ServiceType serviceType) {
|
||||
if (serviceType == OPENAI
|
||||
&& CredentialsStore.INSTANCE.isCredentialSet(CredentialKey.OPENAI_API_KEY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var azureCredentialKey = AzureSettings.getCurrentState().isUseAzureApiKeyAuthentication()
|
||||
? CredentialKey.AZURE_OPENAI_API_KEY
|
||||
: CredentialKey.AZURE_ACTIVE_DIRECTORY_TOKEN;
|
||||
if (serviceType == AZURE && CredentialsStore.INSTANCE.isCredentialSet(azureCredentialKey)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return List.of(LLAMA_CPP, ANTHROPIC, CUSTOM_OPENAI).contains(serviceType);
|
||||
return switch (serviceType) {
|
||||
case OPENAI -> CredentialsStore.INSTANCE.isCredentialSet(CredentialKey.OPENAI_API_KEY);
|
||||
case AZURE -> CredentialsStore.INSTANCE.isCredentialSet(
|
||||
AzureSettings.getCurrentState().isUseAzureApiKeyAuthentication()
|
||||
? CredentialKey.AZURE_OPENAI_API_KEY
|
||||
: CredentialKey.AZURE_ACTIVE_DIRECTORY_TOKEN);
|
||||
case CUSTOM_OPENAI, ANTHROPIC, LLAMA_CPP -> true;
|
||||
case YOU -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue