@@ -2,10 +2,36 @@ package cc.unitmesh.devti.connector.custom
2
2
3
3
import cc.unitmesh.devti.connector.CodeCopilot
4
4
import cc.unitmesh.devti.settings.DevtiSettingsState
5
+ import kotlinx.serialization.decodeFromString
6
+ import kotlinx.serialization.json.Json
7
+
5
8
6
9
class CustomConnector : CodeCopilot {
7
- val url = DevtiSettingsState .getInstance()?.customEngineServer ? : " "
8
- val key = DevtiSettingsState .getInstance()?.customEngineToken ? : " "
10
+ val devtiSettingsState = DevtiSettingsState .getInstance()
11
+
12
+ val url = devtiSettingsState?.customEngineServer ? : " "
13
+ val key = devtiSettingsState?.customEngineToken ? : " "
14
+ var promptConfig: PromptConfig ? = null
15
+
16
+ init {
17
+ val prompts = devtiSettingsState?.customEnginePrompts
18
+ try {
19
+ if (prompts != null ) {
20
+ promptConfig = Json .decodeFromString(prompts)
21
+ }
22
+ } catch (e: Exception ) {
23
+ println (" Error parsing prompts: $e " )
24
+ }
25
+
26
+ if (promptConfig == null ) {
27
+ promptConfig = PromptConfig (
28
+ PromptItem (" Auto complete" , " {code}" ),
29
+ PromptItem (" Auto comment" , " {code}" ),
30
+ PromptItem (" Code review" , " {code}" ),
31
+ PromptItem (" Find bug" , " {code}" )
32
+ )
33
+ }
34
+ }
9
35
10
36
private fun prompt (instruction : String , input : String ): String {
11
37
// val retrofit = Retrofit.Builder()
@@ -17,19 +43,23 @@ class CustomConnector : CodeCopilot {
17
43
}
18
44
19
45
override fun codeCompleteFor (text : String , className : String ): String {
20
- return " "
46
+ val complete = promptConfig!! .autoComplete
47
+ return prompt(complete.instruction, complete.input.replace(" {code}" , text))
21
48
}
22
49
23
50
override fun autoComment (text : String ): String {
24
- return " "
51
+ val comment = promptConfig!! .autoComment
52
+ return prompt(comment.instruction, comment.input.replace(" {code}" , text))
25
53
}
26
54
27
55
override fun codeReviewFor (text : String ): String {
28
- return " "
56
+ val review = promptConfig!! .codeReview
57
+ return prompt(review.instruction, review.input.replace(" {code}" , text))
29
58
}
30
59
31
60
override fun findBug (text : String ): String {
32
- return " "
61
+ val bug = promptConfig!! .findBug
62
+ return prompt(bug.instruction, bug.input.replace(" {code}" , text))
33
63
}
34
64
35
65
}
0 commit comments