Skip to content

Commit 7de0431

Browse files
author
Jia Liu
committed
feat: add custom AI engine setting for inlay code complete
1 parent 268f309 commit 7de0431

File tree

8 files changed

+175
-4
lines changed

8 files changed

+175
-4
lines changed

src/222/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<extensions defaultExtensionNs="JavaScript.JsonSchema">
8484
<ProviderFactory implementation="cc.unitmesh.devti.custom.schema.AutoDevJsonSchemaProviderFactory"/>
8585
<ProviderFactory implementation="cc.unitmesh.devti.custom.schema.AutoDevPromptJsonSchemaProviderFactory"/>
86+
<ProviderFactory implementation="cc.unitmesh.devti.custom.schema.InlayCodePromptsJsonSchemaProviderFactory"/>
8687
</extensions>
8788

8889
<extensionPoints>

src/main/kotlin/cc/unitmesh/devti/agent/configurable/CoUnitToolConfigurable.kt

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

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.custom.schema.CUSTOM_AGENT_FILE_NAME
45
import cc.unitmesh.devti.fullWidthCell
56
import cc.unitmesh.devti.gui.component.JsonLanguageField
67
import com.intellij.openapi.Disposable
@@ -23,7 +24,8 @@ class CoUnitToolConfigurable(val project: Project) : BoundConfigurable(AutoDevBu
2324
val languageField = JsonLanguageField(
2425
project,
2526
state::agentJsonConfig.toString(),
26-
AutoDevBundle.message("counit.agent.json.placeholder")
27+
AutoDevBundle.message("counit.agent.json.placeholder"),
28+
CUSTOM_AGENT_FILE_NAME
2729
)
2830
fullWidthCell(languageField)
2931
.bind(
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cc.unitmesh.devti.custom.schema
2+
3+
import com.intellij.openapi.application.runReadAction
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.openapi.vfs.VirtualFile
6+
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider
7+
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory
8+
import com.jetbrains.jsonSchema.extension.SchemaType
9+
10+
const val INLAY_PROMPTS_FILE_NAME = "AutoDevInlayCodeCompletePromptFile.json"
11+
12+
//todo: refactor provider to reduce duplicate code
13+
class InlayCodeCompletePromptsSchemaFileProvider(project: Project) : JsonSchemaFileProvider {
14+
override fun isAvailable(file: VirtualFile): Boolean {
15+
return runReadAction { isMyFile(file) }
16+
}
17+
18+
private fun isMyFile(file: VirtualFile): Boolean {
19+
if (!file.isValid) {
20+
return false
21+
}
22+
23+
return file.name == INLAY_PROMPTS_FILE_NAME
24+
}
25+
26+
override fun getName(): String = "AutoDevInlayCodeCompletePromptFile"
27+
28+
override fun getSchemaFile(): VirtualFile? {
29+
return JsonSchemaProviderFactory.getResourceFile(this::class.java, inlayPromptsSchemaFile)
30+
}
31+
32+
override fun getSchemaType(): SchemaType {
33+
return SchemaType.schema
34+
}
35+
36+
companion object {
37+
private const val inlayPromptsSchemaFile = "auto-dev-inlay-code-complete-prompt-file.json"
38+
}
39+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cc.unitmesh.devti.custom.schema
2+
3+
import com.intellij.openapi.project.Project
4+
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider
5+
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory
6+
7+
class InlayCodePromptsJsonSchemaProviderFactory: JsonSchemaProviderFactory {
8+
override fun getProviders(project: Project): MutableList<JsonSchemaFileProvider> {
9+
return mutableListOf(InlayCodeCompletePromptsSchemaFileProvider(project))
10+
}
11+
}

src/main/kotlin/cc/unitmesh/devti/gui/component/JsonLanguageField.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.intellij.ui.LanguageTextField
1212
import java.awt.Dimension
1313
import java.awt.FontMetrics
1414

15-
class JsonLanguageField(private val myProject: Project, val value: String, private val placeholder: String) :
15+
class JsonLanguageField(private val myProject: Project, val value: String, private val placeholder: String, private val fileName: String) :
1616
LanguageTextField(JsonLanguage.INSTANCE, myProject, value,
1717
object : SimpleDocumentCreator() {
1818
override fun createDocument(value: String?, language: Language?, project: Project?): Document {

src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderConfigurable.kt

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package cc.unitmesh.devti.settings.coder
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.custom.schema.INLAY_PROMPTS_FILE_NAME
45
import cc.unitmesh.devti.fullWidthCell
6+
import cc.unitmesh.devti.gui.component.JsonLanguageField
7+
import cc.unitmesh.devti.settings.ResponseType
58
import com.intellij.openapi.components.service
69
import com.intellij.openapi.options.BoundConfigurable
710
import com.intellij.openapi.project.Project
11+
import com.intellij.openapi.ui.ComboBox
812
import com.intellij.openapi.ui.DialogPanel
9-
import com.intellij.ui.dsl.builder.*
13+
import com.intellij.ui.dsl.builder.panel
14+
import com.intellij.ui.dsl.builder.toMutableProperty
15+
import com.intellij.util.containers.toArray
1016
import javax.swing.JCheckBox
17+
import javax.swing.JPasswordField
1118
import javax.swing.JTextField
1219

1320
class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBundle.message("settings.autodev.coder")) {
@@ -21,11 +28,22 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
2128
private val explainCodeField = JTextField()
2229
private val refactorCodeField = JTextField()
2330
private val fixIssueCodeField = JTextField()
24-
private val generateTestField = JTextField()
31+
2532
private val useCustomAIEngineWhenInlayCodeComplete = JCheckBox()
2633
.apply {
2734
toolTipText = "You can use custom LLM to inlay complete code."
2835
}
36+
private val maxTokenLengthParam = JTextField()
37+
private val delaySecondsParam: JTextField = JTextField()
38+
private val customEngineResponseTypeParam: ComboBox<String> = ComboBox(ResponseType.values().map { it.name }.toArray(emptyArray()));
39+
private val customEngineResponseFormatParam = JTextField()
40+
private val customEngineRequestBodyFormatParam = JTextField()
41+
private val customEngineServerParam = JTextField()
42+
private val customEngineTokenParam = JPasswordField()
43+
private val customEnginePrompt = JsonLanguageField(project, "", "Custom your prompt here", INLAY_PROMPTS_FILE_NAME)
44+
45+
private val generateTestField = JTextField()
46+
2947
val settings = project.service<AutoDevCoderSettingService>()
3048
val state = settings.state.copy()
3149

@@ -107,6 +125,78 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
107125
)
108126
}
109127

128+
row(AutoDevBundle.message("settings.autodev.coder.delaySecondsParam")) {
129+
fullWidthCell(delaySecondsParam)
130+
.bind(
131+
componentGet = { it.text },
132+
componentSet = { component, value -> component.text = value },
133+
prop = state::delaySecondsParam.toMutableProperty()
134+
)
135+
}
136+
137+
row(AutoDevBundle.message("settings.autodev.coder.maxTokenLengthParam")) {
138+
fullWidthCell(maxTokenLengthParam)
139+
.bind(
140+
componentGet = { it.text },
141+
componentSet = { component, value -> component.text = value },
142+
prop = state::maxTokenLengthParam.toMutableProperty()
143+
)
144+
}
145+
146+
row(AutoDevBundle.message("settings.autodev.coder.customEngineResponseTypeParam")) {
147+
fullWidthCell(customEngineResponseTypeParam)
148+
.bind(
149+
componentGet = { it.selectedItem?.toString() ?: ResponseType.SSE.name },
150+
componentSet = { component, value -> component.selectedItem = value },
151+
prop = state::customEngineResponseTypeParam.toMutableProperty()
152+
)
153+
}
154+
155+
row(AutoDevBundle.message("settings.autodev.coder.customEngineResponseFormatParam")) {
156+
fullWidthCell(customEngineResponseFormatParam)
157+
.bind(
158+
componentGet = { it.text },
159+
componentSet = { component, value -> component.text = value },
160+
prop = state::customEngineResponseFormatParam.toMutableProperty()
161+
)
162+
}
163+
164+
row(AutoDevBundle.message("settings.autodev.coder.customEngineRequestBodyFormatParam")) {
165+
fullWidthCell(customEngineRequestBodyFormatParam)
166+
.bind(
167+
componentGet = { it.text },
168+
componentSet = { component, value -> component.text = value },
169+
prop = state::customEngineRequestBodyFormatParam.toMutableProperty()
170+
)
171+
}
172+
173+
row(AutoDevBundle.message("settings.autodev.coder.customEngineServerParam")) {
174+
fullWidthCell(customEngineServerParam)
175+
.bind(
176+
componentGet = { it.text },
177+
componentSet = { component, value -> component.text = value },
178+
prop = state::customEngineServerParam.toMutableProperty()
179+
)
180+
}
181+
row(AutoDevBundle.message("settings.autodev.coder.customEngineTokenParam")) {
182+
fullWidthCell(customEngineTokenParam)
183+
.bind(
184+
componentGet = { it.text },
185+
componentSet = { component, value -> component.text = value },
186+
prop = state::customEngineTokenParam.toMutableProperty()
187+
)
188+
}
189+
row(AutoDevBundle.message("settings.autodev.coder.customEnginePrompt")){}
190+
row() {
191+
// TODO: spike better way for support 213 and 221
192+
fullWidthCell(customEnginePrompt)
193+
.bind(
194+
componentGet = { it.text },
195+
componentSet = { component, value -> component.text = value },
196+
prop = state::customEnginePrompt.toMutableProperty()
197+
)
198+
}
199+
110200
onApply {
111201
settings.modify {
112202
it.recordingInLocal = state.recordingInLocal
@@ -117,6 +207,14 @@ class AutoDevCoderConfigurable(project: Project) : BoundConfigurable(AutoDevBund
117207
it.fixIssueCode = state.fixIssueCode
118208
it.generateTest = state.generateTest
119209
it.useCustomAIEngineWhenInlayCodeComplete = state.useCustomAIEngineWhenInlayCodeComplete
210+
it.delaySecondsParam = state.delaySecondsParam
211+
it.maxTokenLengthParam = state.maxTokenLengthParam
212+
it.customEngineResponseTypeParam = state.customEngineResponseTypeParam
213+
it.customEngineResponseFormatParam = state.customEngineResponseFormatParam
214+
it.customEngineRequestBodyFormatParam = state.customEngineRequestBodyFormatParam
215+
it.customEngineServerParam = state.customEngineServerParam
216+
it.customEngineTokenParam = state.customEngineTokenParam
217+
it.customEnginePrompt = state.customEnginePrompt
120218
it.noChatHistory = state.noChatHistory
121219
}
122220
}

src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderSettingService.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package cc.unitmesh.devti.settings.coder
22

3+
import cc.unitmesh.devti.settings.LLMParam
4+
import cc.unitmesh.devti.settings.MAX_TOKEN_LENGTH
5+
import cc.unitmesh.devti.settings.ResponseType
36
import com.intellij.openapi.components.*
47
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.ui.ComboBox
59

610
val Project.coderSetting: AutoDevCoderSettingService
711
get() = service<AutoDevCoderSettingService>()
@@ -31,6 +35,14 @@ class AutoDevCoderSettingService(
3135
var generateTest: String by property("Generate test for \$lang code") { it.isEmpty() }
3236

3337
var useCustomAIEngineWhenInlayCodeComplete by property(false)
38+
var maxTokenLengthParam: String by property(MAX_TOKEN_LENGTH.toString()) { it.isEmpty() }
39+
var delaySecondsParam: String by property("") { it.isEmpty() }
40+
var customEngineResponseTypeParam by property(ResponseType.SSE.name) { it.isEmpty() }
41+
var customEngineResponseFormatParam by property("") { it.isEmpty() }
42+
var customEngineRequestBodyFormatParam by property("") { it.isEmpty() }
43+
var customEngineServerParam by property("") { it.isEmpty() }
44+
var customEngineTokenParam by property("") { it.isEmpty() }
45+
var customEnginePrompt by property("") { it.isEmpty() }
3446
override fun copy(): AutoDevCoderSettings {
3547
val state = AutoDevCoderSettings()
3648
state.copyFrom(this)

src/main/resources/messages/AutoDevBundle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ settings.autodev.coder.refactorCode=Refactor code
9797
settings.autodev.coder.fixIssueCode=Fix issue
9898
settings.autodev.coder.generateTest=Generate test
9999
settings.autodev.coder.useCustomerAgentWhenInlayCodeComplete= Use Custormer Agent
100+
settings.autodev.coder.delaySecondsParam=Quest Delay Seconds
101+
settings.autodev.coder.maxTokenLengthParam=Max token length
102+
settings.autodev.coder.customEngineResponseTypeParam=Custom Response Type
103+
settings.autodev.coder.customEngineResponseFormatParam=Custom Response Format (Json Path)
104+
settings.autodev.coder.customEngineRequestBodyFormatParam=Custom Request Body Format (Json)
105+
settings.autodev.coder.customEngineServerParam=Custom Engine Server
106+
settings.autodev.coder.customEngineTokenParam=Custom Engine Token
107+
settings.autodev.coder.customEnginePrompt=Custom Engine Prompt (Json)
100108

101109
settings.welcome.message=Welcome to use AutoDev
102110
settings.welcome.feature.context=Precise context-aware code generate and chat

0 commit comments

Comments
 (0)