Skip to content

Commit 063c304

Browse files
committed
fix(llm): handle empty custom LLMs gracefully
Check if custom LLMs string is empty before attempting to decode, returning an empty list if true. This prevents unnecessary exceptions when no custom LLMs are configured.
1 parent dd0adfc commit 063c304

File tree

1 file changed

+6
-1
lines changed
  • core/src/main/kotlin/cc/unitmesh/devti/llm2/model

1 file changed

+6
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/llm2/model/LlmConfig.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.llm2.model
22

33
import cc.unitmesh.devti.settings.AutoDevSettingsState
4+
import com.intellij.openapi.diagnostic.logger
45
import kotlinx.serialization.Serializable
56
import kotlinx.serialization.json.Json
67
import kotlin.text.ifEmpty
@@ -23,8 +24,12 @@ data class LlmConfig(
2324
) {
2425
companion object {
2526
fun load(): List<LlmConfig> {
27+
val llms = AutoDevSettingsState.getInstance().customLlms.trim()
28+
if (llms.isEmpty()) {
29+
return emptyList()
30+
}
31+
2632
val configs: List<LlmConfig> = try {
27-
val llms = AutoDevSettingsState.getInstance().customLlms
2833
Json.decodeFromString(llms)
2934
} catch (e: Exception) {
3035
throw Exception("Failed to load custom llms: $e")

0 commit comments

Comments
 (0)