@@ -56,17 +56,13 @@ class CustomLLMProvider(val project: Project) : LLMProvider {
56
56
private val messages: MutableList <Message > = mutableListOf ()
57
57
private val logger = logger<CustomLLMProvider >()
58
58
59
- override fun clearMessage () {
60
- messages.clear()
61
- }
59
+ override fun clearMessage () = messages.clear()
62
60
63
61
override fun appendLocalMessage (msg : String , role : ChatRole ) {
64
62
messages + = Message (role.roleName(), msg)
65
63
}
66
64
67
- override fun prompt (promptText : String ): String {
68
- return this .prompt(promptText, " " )
69
- }
65
+ override fun prompt (promptText : String ): String = this .prompt(promptText, " " )
70
66
71
67
override fun stream (promptText : String , systemPrompt : String , keepHistory : Boolean ): Flow <String > {
72
68
if (! keepHistory) {
@@ -93,10 +89,10 @@ class CustomLLMProvider(val project: Project) : LLMProvider {
93
89
client = client.newBuilder().readTimeout(timeout).build()
94
90
val call = client.newCall(builder.url(url).post(body).build())
95
91
96
- if (autoDevSettingsState.customEngineResponseType == ResponseType .SSE .name) {
97
- return streamSSE(call)
92
+ return if (autoDevSettingsState.customEngineResponseType == ResponseType .SSE .name) {
93
+ streamSSE(call)
98
94
} else {
99
- return streamJson(call)
95
+ streamJson(call)
100
96
}
101
97
}
102
98
@@ -204,8 +200,7 @@ fun Request.Builder.appendCustomHeaders(customRequestHeader: String): Request.Bu
204
200
}
205
201
}
206
202
}.onFailure {
207
- // should I warn user?
208
- println (" Failed to parse custom request header ${it.message} " )
203
+ logger<CustomLLMProvider >().warn(" Failed to parse custom request header" , it)
209
204
}
210
205
}
211
206
@@ -217,14 +212,12 @@ fun JsonObject.updateCustomBody(customRequest: String): JsonObject {
217
212
this @updateCustomBody.forEach { u, v -> put(u, v) }
218
213
219
214
val customRequestJson = Json .parseToJsonElement(customRequest).jsonObject
220
-
221
215
customRequestJson[" customFields" ]?.let { customFields ->
222
216
customFields.jsonObject.forEach { (key, value) ->
223
217
put(key, value.jsonPrimitive)
224
218
}
225
219
}
226
220
227
-
228
221
// TODO clean code with magic literals
229
222
var roleKey = " role"
230
223
var contentKey = " message"
@@ -234,8 +227,6 @@ fun JsonObject.updateCustomBody(customRequest: String): JsonObject {
234
227
}
235
228
236
229
val messages: JsonArray = this @updateCustomBody[" messages" ]?.jsonArray ? : buildJsonArray { }
237
-
238
-
239
230
this .put(" messages" , buildJsonArray {
240
231
messages.forEach { message ->
241
232
val role: String = message.jsonObject[" role" ]?.jsonPrimitive?.content ? : " user"
0 commit comments