Skip to content

Commit ffe2bb3

Browse files
committed
feat(core): add JsonText and JsonPath param types #271
- Extend `ParamType` enum with `JsonText` and `JsonPath`. - Add factory functions `JsonEditable` and `JsonPathEditable` for creating LLMParam instances. - Update `LocalJsonTextProvider` to support optional `fileName` and `oneLineMode`. - Modify `LLMSettingComponent` to use new param types for response and request formats.
1 parent ba8c1b7 commit ffe2bb3

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

core/src/main/kotlin/cc/unitmesh/devti/provider/local/LocalJsonTextProvider.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class JsonLanguageField(
2525
private val myProject: Project?,
2626
val value: String,
2727
private val placeholder: String,
28-
private val fileName: String
28+
private val fileName: String? = null,
29+
private val oneLineMode: Boolean = false
2930
) :
3031
LanguageTextField(
3132
Language.findLanguageByID("JSON"), myProject, value,
@@ -35,7 +36,9 @@ class JsonLanguageField(
3536
}
3637

3738
override fun customizePsiFile(file: PsiFile?) {
38-
file?.name = fileName
39+
if (fileName != null) {
40+
file?.name = fileName
41+
}
3942
}
4043
}
4144
) {
@@ -50,15 +53,17 @@ class JsonLanguageField(
5053
val scheme = EditorColorsUtil.getColorSchemeForBackground(this.colorsScheme.defaultBackground)
5154
this.colorsScheme = this.createBoundColorSchemeDelegate(scheme)
5255

53-
val metrics: FontMetrics = getFontMetrics(font)
54-
val columnWidth = metrics.charWidth('m')
55-
5656
this.settings.isUseSoftWraps = true
5757
this.settings.isAdditionalPageAtBottom = false
5858
this.settings.isCaretRowShown = false
5959

60-
isOneLineMode = false
61-
preferredSize = Dimension(25 * columnWidth, 25 * metrics.height)
60+
isOneLineMode = oneLineMode
61+
62+
if (!oneLineMode) {
63+
val metrics: FontMetrics = getFontMetrics(font)
64+
val columnWidth = metrics.charWidth('m')
65+
preferredSize = Dimension(25 * columnWidth, 25 * metrics.height)
66+
}
6267
}
6368
}
6469
}

core/src/main/kotlin/cc/unitmesh/devti/settings/LLMParamComponent.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class LLMParam(
117117
var items: List<String> = emptyList(),
118118
) {
119119
enum class ParamType {
120-
Text, Password, ComboBox, Separator
120+
Text, Password, ComboBox, Separator, JsonText, JsonPath
121121
}
122122

123123
private var onChange: (LLMParam.(String) -> Unit)? = null
@@ -158,6 +158,9 @@ class LLMParam(
158158

159159
// factory functions to create LLMParam
160160
fun Editable(value: String = "") = LLMParam(value = value)
161+
fun JsonEditable(value: String = "") = LLMParam(value = value, type = ParamType.JsonText)
162+
fun JsonPathEditable(value: String = "") = LLMParam(value = value, type = ParamType.JsonPath)
163+
161164
fun Password(password: String = "") = LLMParam(value = password, type = ParamType.Password)
162165

163166
fun ComboBox(value: String, items: List<String>) =

core/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ import cc.unitmesh.devti.gui.component.JsonLanguageField
66
import cc.unitmesh.devti.settings.locale.HUMAN_LANGUAGES
77
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback
88
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.jBLabel
9+
import com.intellij.lang.Language
10+
import com.intellij.openapi.editor.Document
11+
import com.intellij.openapi.project.Project
912
import com.intellij.openapi.project.ProjectManager
13+
import com.intellij.psi.PsiFile
1014
import com.intellij.ui.EditorTextField
1115
import com.intellij.ui.JBColor
16+
import com.intellij.ui.LanguageTextField
17+
import com.intellij.ui.LanguageTextField.SimpleDocumentCreator
1218
import com.intellij.ui.dsl.builder.panel
1319
import com.intellij.util.ui.FormBuilder
1420
import javax.swing.JPanel
@@ -27,8 +33,8 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
2733
private val customEngineServerParam by LLMParam.creating { Editable(settings.customEngineServer) }
2834
private val customEngineTokenParam by LLMParam.creating { Password(settings.customEngineToken) }
2935

30-
private val customEngineResponseFormatParam by LLMParam.creating { Editable(settings.customEngineResponseFormat) }
31-
private val customEngineRequestBodyFormatParam by LLMParam.creating { Editable(settings.customEngineRequestFormat) }
36+
private val customEngineResponseFormatParam by LLMParam.creating { JsonPathEditable(settings.customEngineResponseFormat) }
37+
private val customEngineRequestBodyFormatParam by LLMParam.creating { JsonEditable(settings.customEngineRequestFormat) }
3238

3339
val project = ProjectManager.getInstance().openProjects.firstOrNull()
3440
private val customLlmParam: EditorTextField by lazy {
@@ -75,6 +81,23 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
7581
}, 1, false)
7682
}
7783

84+
LLMParam.ParamType.JsonText -> {
85+
formBuilder.addLabeledComponent(jBLabel(this.label), cc.unitmesh.devti.provider.local.JsonLanguageField(
86+
project, this.value, AutoDevBundle.messageWithLanguageFromLLMSetting(this.label), null, true
87+
), 1, false)
88+
}
89+
90+
LLMParam.ParamType.JsonPath -> {
91+
formBuilder.addLabeledComponent(jBLabel(this.label), LanguageTextField(
92+
Language.findLanguageByID("JSONPath"), project, value,
93+
object : SimpleDocumentCreator() {
94+
override fun createDocument(value: String?, language: Language?, project: Project?): Document {
95+
return LanguageTextField.createDocument(value, language, project, this)
96+
}
97+
}
98+
), 1, false)
99+
}
100+
78101
LLMParam.ParamType.ComboBox -> {
79102
formBuilder.addLabeledComponent(jBLabel(this.label), ReactiveComboBox(this), 1, false)
80103
}

0 commit comments

Comments
 (0)