@@ -135,7 +135,17 @@ open class ChatClient(
135135 return post(request)
136136 }
137137
138- private fun post (request : HttpPost ): String = withClient { EntityUtils .toString(it.execute(request).entity) }
138+ private fun post (request : HttpPost ): String = withClient {
139+ log(
140+ level = Level .DEBUG ,
141+ msg = String .format(
142+ " POST %s\n Prefix:\n\t %s\n " ,
143+ request.uri,
144+ EntityUtils .toString(request.entity).replace(" \n " , " \n\t " )
145+ )
146+ )
147+ EntityUtils .toString(it.execute(request).entity)
148+ }
139149
140150 @Throws(IOException ::class )
141151 protected open fun authorize (request : HttpRequest , apiProvider : APIProvider ) {
@@ -202,14 +212,6 @@ open class ChatClient(
202212 }), model)
203213 val json = JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
204214 .writeValueAsString(geminiChatRequest)
205- log(
206- level = Level .DEBUG ,
207- msg = String .format(
208- " Chat Request %s\n Prefix:\n\t %s\n " ,
209- requestID,
210- json.replace(" \n " , " \n\t " )
211- )
212- )
213215 fromGemini(
214216 post(
215217 " ${apiBase[apiProvider]} /v1beta/${model.modelName} :generateContent?key=${key[apiProvider]} " ,
@@ -223,14 +225,6 @@ open class ChatClient(
223225 val anthropicChatRequest = mapToAnthropicChatRequest(chatRequest, model)
224226 val json = JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
225227 .writeValueAsString(anthropicChatRequest)
226- log(
227- level = Level .DEBUG ,
228- msg = String .format(
229- " Chat Request %s\n Prefix:\n\t %s\n " ,
230- requestID,
231- json.replace(" \n " , " \n\t " )
232- )
233- )
234228 val request = HttpPost (" ${apiBase[apiProvider]} /messages" )
235229 request.addHeader(" Content-Type" , " application/json" )
236230 request.addHeader(" Accept" , " application/json" )
@@ -245,42 +239,18 @@ open class ChatClient(
245239 val json =
246240 JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
247241 .writeValueAsString(chatRequest.copy(stop = null ))
248- log(
249- level = Level .DEBUG ,
250- msg = String .format(
251- " Chat Request %s\n Prefix:\n\t %s\n " ,
252- requestID,
253- json.replace(" \n " , " \n\t " )
254- )
255- )
256242 post(" ${apiBase[apiProvider]} /chat/completions" , json, apiProvider)
257243 }
258244
259245 apiProvider == APIProvider .Mistral -> {
260246 val json = JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
261247 .writeValueAsString(toGroq(chatRequest))
262- log(
263- level = Level .DEBUG ,
264- msg = String .format(
265- " Chat Request %s\n Prefix:\n\t %s\n " ,
266- requestID,
267- json.replace(" \n " , " \n\t " )
268- )
269- )
270248 post(" ${apiBase[apiProvider]} /chat/completions" , json, apiProvider)
271249 }
272250
273251 apiProvider == APIProvider .Groq -> {
274252 val json = JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
275253 .writeValueAsString(toGroq(chatRequest))
276- log(
277- level = Level .DEBUG ,
278- msg = String .format(
279- " Chat Request %s\n Prefix:\n\t %s\n " ,
280- requestID,
281- json.replace(" \n " , " \n\t " )
282- )
283- )
284254 post(" ${apiBase[apiProvider]} /chat/completions" , json, apiProvider)
285255 }
286256
@@ -289,14 +259,6 @@ open class ChatClient(
289259 val json =
290260 JsonUtil .objectMapper().writerWithDefaultPrettyPrinter()
291261 .writeValueAsString(toModelsLab(chatRequest))
292- log(
293- level = Level .DEBUG ,
294- msg = String .format(
295- " Chat Request %s\n Prefix:\n\t %s\n " ,
296- requestID,
297- json.replace(" \n " , " \n\t " )
298- )
299- )
300262 fromModelsLab(post(" ${apiBase[apiProvider]} /llm/chat" , json, apiProvider))
301263 }
302264 }
@@ -308,13 +270,6 @@ open class ChatClient(
308270 .credentialsProvider(awsCredentials(awsAuth))
309271 .region(Region .of(awsAuth.region))
310272 .build()
311- log(
312- level = Level .DEBUG ,
313- msg = String .format(
314- " Chat Request %s\n Prefix:\n\t %s\n " ,
315- requestID, JsonUtil .toJson(chatRequest).replace(" \n " , " \n\t " )
316- )
317- )
318273 val invokeModelResponse = bedrockRuntimeClient
319274 .invokeModel(invokeModelRequest)
320275 val responseBody = invokeModelResponse.body().asString(Charsets .UTF_8 )
@@ -324,14 +279,6 @@ open class ChatClient(
324279 else -> {
325280 val json =
326281 JsonUtil .objectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(chatRequest)
327- log(
328- level = Level .DEBUG ,
329- msg = String .format(
330- " Chat Request %s\n Prefix:\n\t %s\n " ,
331- requestID,
332- json.replace(" \n " , " \n\t " )
333- )
334- )
335282 post(" ${apiBase[apiProvider]} /chat/completions" , json, apiProvider)
336283 }
337284 }
0 commit comments