@@ -6,6 +6,7 @@ import ee.carlrobert.codegpt.conversations.message.Message
66import ee.carlrobert.codegpt.settings.models.ModelSettings
77import ee.carlrobert.codegpt.settings.service.FeatureType
88import ee.carlrobert.codegpt.settings.service.ServiceType
9+ import ee.carlrobert.codegpt.settings.service.custom.CustomServiceChatCompletionSettingsState
910import org.assertj.core.api.Assertions.assertThat
1011import testsupport.IntegrationTest
1112import testsupport.http.RequestEntity
@@ -140,6 +141,66 @@ class CompletionServiceKoogIntegrationTest : IntegrationTest() {
140141 assertThat(result).isEqualTo(" fun value() = 2" )
141142 }
142143
144+ fun testCustomOpenAISettingsTestConnectionUsesChatCompletionCapability () {
145+ val settings = CustomServiceChatCompletionSettingsState ().apply {
146+ url = System .getProperty(" customOpenAI.baseUrl" ) + " /v9/chat/completions"
147+ headers.clear()
148+ body.clear()
149+ body[" model" ] = " custom-chat-model"
150+ body[" stream" ] = false
151+ body[" max_tokens" ] = 16
152+ }
153+ expectCustomOpenAI(BasicHttpExchange { request ->
154+ assertThat(request.uri.path).isEqualTo(" /v9/chat/completions" )
155+ assertThat(request.method).isEqualTo(" POST" )
156+ assertThat(request.body[" model" ]).isEqualTo(" custom-chat-model" )
157+ ResponseEntity (
158+ jsonMapResponse(
159+ e(" id" , " chatcmpl-test" ),
160+ e(" object" , " chat.completion" ),
161+ e(" created" , 1 ),
162+ e(" model" , " custom-chat-model" ),
163+ e(
164+ " choices" ,
165+ jsonArray(
166+ jsonMap(
167+ e(" index" , 0 ),
168+ e(
169+ " message" ,
170+ jsonMap(
171+ e(" role" , " assistant" ),
172+ e(" content" , " Connection ok" )
173+ )
174+ ),
175+ e(" finish_reason" , " stop" )
176+ )
177+ )
178+ ),
179+ e(
180+ " usage" ,
181+ jsonMap(
182+ e(" prompt_tokens" , 1 ),
183+ e(" completion_tokens" , 1 ),
184+ e(" total_tokens" , 2 )
185+ )
186+ )
187+ )
188+ )
189+ })
190+ val listener = RecordingListener ()
191+
192+ CompletionRequestService .testCustomServiceConnectionAsync(
193+ settings = settings,
194+ apiKey = " TEST_API_KEY" ,
195+ modelId = " custom-chat-model" ,
196+ eventListener = listener
197+ )
198+ waitExpecting { listener.completed != null || listener.error != null }
199+
200+ assertThat(listener.error).isNull()
201+ assertThat(listener.completed).isEqualTo(" Connection ok" )
202+ }
203+
143204 private class RecordingListener : CompletionStreamEventListener {
144205 val chunks = mutableListOf<String >()
145206 var completed: String? = null
0 commit comments