Skip to content

Commit 0375d22

Browse files
committed
feat(counit): rename and refactor to support custom agent functionality #51
The CoUnit functionality has been refactored to support custom agent interactions. This includes the renaming of classes and methods, as well as the modification of import statements to reflect the new custom agent-centric approach. The `CustomAgentPromptGenerator` now handles the generation of prompts, and the `CustomAgentPreProcessor` handles the processing of chat input. The related model class has been renamed to `CustomAgentConfig`, and the configuration settings for custom agents have been updated accordingly. Additionally, the UI components have been modified to reflect the changes in the backend functionality.
1 parent cf7bb77 commit 0375d22

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CoUnitPreProcessor.kt renamed to src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentPreProcessor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import kotlinx.coroutines.launch
1515
const val CO_UNIT = "/counit"
1616

1717
@Service(Service.Level.PROJECT)
18-
class CoUnitPreProcessor(val project: Project) {
18+
class CustomAgentPreProcessor(val project: Project) {
1919
private val llmFactory = LlmFactory()
2020

21-
private val coUnitPromptGenerator = CoUnitPromptGenerator(project)
21+
private val customAgentPromptGenerator = CustomAgentPromptGenerator(project)
2222
private val llmProvider = llmFactory.create(project)
2323

2424
fun handleChat(prompter: ContextPrompter, ui: ChatCodingPanel, context: ChatContext?) {
@@ -27,7 +27,7 @@ class CoUnitPreProcessor(val project: Project) {
2727

2828
val request = originRequest.removePrefix(CO_UNIT).trim()
2929

30-
val response = coUnitPromptGenerator.findIntention(request)
30+
val response = customAgentPromptGenerator.findIntention(request)
3131
if (response == null) {
3232
logger.error("can not find intention for request: $request")
3333
return
@@ -49,7 +49,7 @@ class CoUnitPreProcessor(val project: Project) {
4949
llmProvider.appendLocalMessage(searchTip, ChatRole.User)
5050
ui.addMessage(searchTip, true, searchTip)
5151

52-
val related = coUnitPromptGenerator.semanticQuery("") ?: ""
52+
val related = customAgentPromptGenerator.semanticQuery("") ?: ""
5353
if (related.isEmpty()) {
5454
val noResultTip = "no related API found"
5555
llmProvider.appendLocalMessage(noResultTip, ChatRole.Assistant)
@@ -80,7 +80,7 @@ class CoUnitPreProcessor(val project: Project) {
8080
}
8181

8282
companion object {
83-
private val logger = logger<CoUnitPreProcessor>()
83+
private val logger = logger<CustomAgentPreProcessor>()
8484
}
8585
}
8686

src/main/kotlin/cc/unitmesh/devti/counit/CoUnitPromptGenerator.kt renamed to src/main/kotlin/cc/unitmesh/devti/counit/CustomAgentPromptGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.intellij.openapi.components.Service
44
import com.intellij.openapi.project.Project
55

66
@Service(Service.Level.PROJECT)
7-
class CoUnitPromptGenerator(val project: Project) {
7+
class CustomAgentPromptGenerator(val project: Project) {
88
fun findIntention(input: String): String? {
99
return null
1010
}

src/main/kotlin/cc/unitmesh/devti/counit/model/CustomRagApp.kt renamed to src/main/kotlin/cc/unitmesh/devti/counit/model/CustomAgentConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data class CustomFlowTransition(
4040
)
4141

4242
@Serializable
43-
data class CustomRagApp(
43+
data class CustomAgentConfig(
4444
val name: String,
4545
val description: String = "",
4646
val url: String = "",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cc.unitmesh.devti.gui.chat
33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.AutoDevIcons
55
import cc.unitmesh.devti.counit.configurable.customRagSettings
6-
import cc.unitmesh.devti.counit.model.CustomRagApp
6+
import cc.unitmesh.devti.counit.model.CustomAgentConfig
77
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
88
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
99
import cc.unitmesh.devti.settings.AutoDevSettingsState
@@ -55,8 +55,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
5555
private val buttonPresentation: Presentation
5656
private val button: ActionButton
5757

58-
private val defaultRag: CustomRagApp = CustomRagApp("Normal", "Normal")
59-
private var customRag: ComboBox<CustomRagApp> = ComboBox(MutableCollectionComboBoxModel(listOf()))
58+
private val defaultRag: CustomAgentConfig = CustomAgentConfig("Normal", "Normal")
59+
private var customRag: ComboBox<CustomAgentConfig> = ComboBox(MutableCollectionComboBoxModel(listOf()))
6060

6161
private val logger = logger<AutoDevInputSection>()
6262

@@ -120,7 +120,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
120120

121121
if (project.customRagSettings.enableCustomRag) {
122122
customRag = ComboBox(MutableCollectionComboBoxModel(loadRagApps()))
123-
customRag.setRenderer(SimpleListCellRenderer.create { label: JBLabel, value: CustomRagApp?, _: Int ->
123+
customRag.setRenderer(SimpleListCellRenderer.create { label: JBLabel, value: CustomAgentConfig?, _: Int ->
124124
if (value != null) {
125125
label.text = value.name
126126
}
@@ -150,10 +150,10 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
150150
}
151151

152152

153-
private fun loadRagApps(): List<CustomRagApp> {
153+
private fun loadRagApps(): List<CustomAgentConfig> {
154154
val ragsJsonConfig = project.customRagSettings.ragsJsonConfig
155155
val rags = try {
156-
Json.decodeFromString<List<CustomRagApp>>(ragsJsonConfig)
156+
Json.decodeFromString<List<CustomAgentConfig>>(ragsJsonConfig)
157157
} catch (e: Exception) {
158158
logger.warn("Failed to parse custom rag apps", e)
159159
listOf()

src/main/kotlin/cc/unitmesh/devti/gui/chat/ChatCodingService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cc.unitmesh.devti.gui.chat
33
import cc.unitmesh.cf.core.llms.LlmMsg
44
import cc.unitmesh.devti.AutoDevBundle
55
import cc.unitmesh.devti.util.LLMCoroutineScope
6-
import cc.unitmesh.devti.counit.CoUnitPreProcessor
6+
import cc.unitmesh.devti.counit.CustomAgentPreProcessor
77
import cc.unitmesh.devti.counit.configurable.customRagSettings
88
import cc.unitmesh.devti.llms.LlmFactory
99
import cc.unitmesh.devti.util.parser.PostCodeProcessor
@@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
1616

1717
class ChatCodingService(var actionType: ChatActionType, val project: Project) {
1818
private val llmFactory = LlmFactory()
19-
private val counitProcessor = project.service<CoUnitPreProcessor>()
19+
private val counitProcessor = project.service<CustomAgentPreProcessor>()
2020

2121
val action = actionType.instruction(project = project)
2222

src/main/kotlin/cc/unitmesh/devti/gui/chat/message/AutoDevRateMessageAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,5 @@ abstract class AutoDevRateMessageAction : DumbAwareToggleAction() {
5959
override fun getReactionIcon(): Icon = AutoDevIcons.Dislike
6060

6161
override fun getReactionIconSelected(): Icon = AutoDevIcons.Disliked
62-
6362
}
6463
}

src/main/resources/messages/AutoDevBundle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ settings.external.counit.location.label=CoUnit Location (TODO, with JSON RPC) :
7070
settings.external.counit.server.address.label=CoUnit Server address:
7171
devti.loading=Loading
7272

73-
counit.name=Custom RAG
74-
counit.enable.label=Enable Custom RAG (Experimental)
73+
counit.name=Custom Agent
74+
counit.enable.label=Enable Custom Agent (Experimental)
7575
counit.location.label=Custom RAG Location (with JSON RPC, TODO):
76-
counit.server.address.label=Custom RAG Server
77-
counit.custom.rag.label=Custom RAG (Experimental)
78-
counit.rags.json.placeholder=Custom RAG JSON Config
76+
counit.server.address.label=Custom Agent Server
77+
counit.custom.rag.label=Custom Agent (Experimental)
78+
counit.rags.json.placeholder=Custom Agent JSON Config
7979

8080
group.DevOpsGenius.NewActions.text=SRE Genius (AutoDev)
8181
action.new.genius.dockerfile=Generate Dockerfile

0 commit comments

Comments
 (0)