diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/models/LLMClientFactory.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/models/LLMClientFactory.kt index 2234ba83..564f002e 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/models/LLMClientFactory.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/models/LLMClientFactory.kt @@ -140,7 +140,7 @@ object LLMClientFactory { service().customServiceStateForFeatureType(featureType) val serviceId = state.id ?: error("No custom service configured") val apiKey = getCredential(CredentialKey.CustomServiceApiKeyById(serviceId)) - ?: error("No API key found for custom service: $serviceId") + ?: "" when (featureType) { FeatureType.CODE_COMPLETION -> CustomOpenAILLMClient.fromCodeCompletionSettingsState( diff --git a/src/test/kotlin/ee/carlrobert/codegpt/agent/AgentProviderIntegrationTest.kt b/src/test/kotlin/ee/carlrobert/codegpt/agent/AgentProviderIntegrationTest.kt index 3e30d433..83b95a33 100644 --- a/src/test/kotlin/ee/carlrobert/codegpt/agent/AgentProviderIntegrationTest.kt +++ b/src/test/kotlin/ee/carlrobert/codegpt/agent/AgentProviderIntegrationTest.kt @@ -363,6 +363,22 @@ class AgentProviderIntegrationTest : IntegrationTest() { assertThat(result.events.text.toString()).isEqualTo("Hello from Custom OpenAI") } + fun testCustomOpenAIAgentAllowsMissingApiKey() { + val customService = configureCustomOpenAIService(apiKey = null) + expectCustomOpenAI(BasicHttpExchange { request -> + assertThat(request.uri.path).isEqualTo("/v1/chat/completions") + assertThat(request.method).isEqualTo("POST") + assertThat(extractPromptText(request)).contains("Say hello without Custom OpenAI auth") + ResponseEntity(customOpenAiResponse("Hello without Custom OpenAI auth")) + }) + + val result = runAgent(ServiceType.CUSTOM_OPENAI, "Say hello without Custom OpenAI auth") + + assertThat(customService.id).isNotBlank() + assertThat(result.output).isEqualTo("Hello without Custom OpenAI auth") + assertThat(result.events.text.toString()).isEqualTo("Hello without Custom OpenAI auth") + } + fun testCustomOpenAIAgentStreamsWhenStoredSelectionUsesModelId() { val customService = configureCustomOpenAIService(stream = true) service().setModel( @@ -1144,7 +1160,8 @@ class AgentProviderIntegrationTest : IntegrationTest() { path: String = "/v1/chat/completions", model: String = "custom-agent-model", stream: Boolean = false, - useResponsesApiBody: Boolean = false + useResponsesApiBody: Boolean = false, + apiKey: String? = "TEST_API_KEY" ): CustomServiceSettingsState { val settings = service() val serviceState = CustomServiceSettingsState().apply { @@ -1163,7 +1180,7 @@ class AgentProviderIntegrationTest : IntegrationTest() { settings.state.services.add(serviceState) setCredential( CustomServiceApiKeyById(requireNotNull(serviceState.id)), - "TEST_API_KEY" + apiKey ) service().setModel( FeatureType.AGENT,