Skip to content

Commit 12ac068

Browse files
committed
fix(ui): handle URL scheme error in LLM provider #326
- Add error message for invalid URL scheme in LLM configuration. - Update UI to display error notification when URL scheme is invalid. - Adjust preferred size calculation in AutoDevInputSection to use runReadAction.
1 parent 23f41bc commit 12ac068

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
317317
}
318318

319319
override fun getPreferredSize(): Dimension {
320-
val result = super.getPreferredSize()
320+
val result = com.intellij.openapi.application.runReadAction { super.getPreferredSize() }
321321
result.height = max(min(result.height, maxHeight), minimumSize.height)
322322
return result
323323
}

core/src/main/kotlin/cc/unitmesh/devti/llms/custom/CustomLLMProvider.kt

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

3+
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.AutoDevNotifications
35
import cc.unitmesh.devti.gui.chat.message.ChatRole
46
import cc.unitmesh.devti.llm2.model.LlmConfig
57
import cc.unitmesh.devti.llm2.model.ModelType
@@ -91,7 +93,15 @@ class CustomLLMProvider(val project: Project, var llmConfig: LlmConfig = LlmConf
9193
logger.info("Requesting form: $requestContent $body")
9294

9395
client = client.newBuilder().readTimeout(timeout).build()
94-
val call = client.newCall(builder.url(url).post(body).build())
96+
val call = try {
97+
client.newCall(builder.url(url).post(body).build())
98+
} catch (e: IllegalArgumentException) {
99+
if (e.message?.contains("Expected URL scheme") == true) {
100+
AutoDevNotifications.error(project, AutoDevBundle.message("llm.error.url.scheme"))
101+
}
102+
103+
throw e
104+
}
95105

96106
if (!keepHistory || project.coderSetting.state.noChatHistory) {
97107
clearMessage()

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,5 @@ autodev.custom.llms.placeholder=Custom different LLM
225225
settings.autodev.coder.customLlms=Config LLMs: Plan/ACT/Completion/Embedding/FastApply
226226
sketch.compile.devins=Collect context (aka. transpile AutoDev DevIns)
227227
autodev.run.action=Run this file
228+
#llm.error.url.scheme=请配置好您的模型,参考文档:https://ide.unitmesh.cc/quick-start
229+
llm.error.url.scheme=Please, Please, Please configure your model, refer to the document: https://ide.unitmesh.cc/quick-start

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,4 @@ settings.autodev.coder.customLlms=自定义不同模型: Plan/ACT/Completion/Emb
225225
#sketch.compile.devins="Collect context (Transpile AutoDev DevIns)"
226226
sketch.compile.devins=收集上下文中(即转译 AutoDev DevIns 指令)
227227
autodev.run.action=Run this file
228+
llm.error.url.scheme=请请请先配置好您的模型,参考文档:https://ide.unitmesh.cc/quick-start

0 commit comments

Comments
 (0)