Skip to content

Commit

Permalink
feat: init default spec
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 13, 2023
1 parent 674dfe6 commit 0c3d87f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
11 changes: 11 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/prompting/PromptConfig.kt
Expand Up @@ -28,12 +28,23 @@ data class PromptConfig(
private val logger = Logger.getInstance(PromptConfig::class.java)

fun default(): PromptConfig {
val spec = mapOf(
"controller" to "",
"service" to "",
"model" to "",
"repository" to "",
"ddl" to "",
"code_review" to "",
"auto_comment" to "",
)

return PromptConfig(
PromptItem("Complete java code, return rest code, no explaining.", "{code}"),
PromptItem("Auto comment code", "{code}"),
PromptItem("Code review code", "{code}"),
PromptItem("Find bug", "{code}"),
PromptItem("Write test code for", "{code}"),
spec
)
}

Expand Down
@@ -1,10 +1,13 @@
package cc.unitmesh.devti.settings

import cc.unitmesh.devti.prompting.PromptConfig
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@State(name = "cc.unitmesh.devti.settings.DevtiSettingsState", storages = [Storage("DevtiSettings.xml")])
class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
Expand All @@ -24,7 +27,7 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {

override fun loadState(state: AutoDevSettingsState) {
if (customEnginePrompts == "") {
customEnginePrompts = DEFAULT_PROMPTS.trimIndent()
customEnginePrompts = Json.encodeToString(PromptConfig.default())
}

XmlSerializerUtil.copyBean(state, this)
Expand All @@ -36,4 +39,4 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
}
}

}
}
20 changes: 0 additions & 20 deletions src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt
@@ -1,25 +1,5 @@
package cc.unitmesh.devti.settings

val OPENAI_MODEL = arrayOf("gpt-3.5-turbo", "gpt-4")
val DEFAULT_PROMPTS = """
{
"auto_complete": {
"instruction": "",
"input": ""
},
"auto_comment": {
"instruction": "",
"input": ""
},
"code_review": {
"instruction": "",
"input": ""
},
"refactor": {
"instruction": "",
"input": ""
}
}
"""
val AI_ENGINES = arrayOf("OpenAI", "Custom", "Azure")
val DEFAULT_AI_ENGINE = AI_ENGINES[0]
Expand Up @@ -8,7 +8,6 @@ import java.io.File
class PromptConfigTest {
@Test
fun should_serial_from_readme_string() {
// read from root README.md file
val readmeFile = File("README.md").readText()
val codeBlocks = parseCodeFromString(readmeFile)
val configExample = codeBlocks.last()
Expand Down

0 comments on commit 0c3d87f

Please sign in to comment.