Skip to content

Commit

Permalink
feat(counit): rename and refactor to support custom agent functionality
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
phodal committed Mar 5, 2024
1 parent cf7bb77 commit 0375d22
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Expand Up @@ -15,10 +15,10 @@ import kotlinx.coroutines.launch
const val CO_UNIT = "/counit"

@Service(Service.Level.PROJECT)
class CoUnitPreProcessor(val project: Project) {
class CustomAgentPreProcessor(val project: Project) {
private val llmFactory = LlmFactory()

private val coUnitPromptGenerator = CoUnitPromptGenerator(project)
private val customAgentPromptGenerator = CustomAgentPromptGenerator(project)
private val llmProvider = llmFactory.create(project)

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

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

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

val related = coUnitPromptGenerator.semanticQuery("") ?: ""
val related = customAgentPromptGenerator.semanticQuery("") ?: ""
if (related.isEmpty()) {
val noResultTip = "no related API found"
llmProvider.appendLocalMessage(noResultTip, ChatRole.Assistant)
Expand Down Expand Up @@ -80,7 +80,7 @@ class CoUnitPreProcessor(val project: Project) {
}

companion object {
private val logger = logger<CoUnitPreProcessor>()
private val logger = logger<CustomAgentPreProcessor>()
}
}

Expand Up @@ -4,7 +4,7 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project

@Service(Service.Level.PROJECT)
class CoUnitPromptGenerator(val project: Project) {
class CustomAgentPromptGenerator(val project: Project) {
fun findIntention(input: String): String? {
return null
}
Expand Down
Expand Up @@ -40,7 +40,7 @@ data class CustomFlowTransition(
)

@Serializable
data class CustomRagApp(
data class CustomAgentConfig(
val name: String,
val description: String = "",
val url: String = "",
Expand Down
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.devti.gui.chat
import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.AutoDevIcons
import cc.unitmesh.devti.counit.configurable.customRagSettings
import cc.unitmesh.devti.counit.model.CustomRagApp
import cc.unitmesh.devti.counit.model.CustomAgentConfig
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
import cc.unitmesh.devti.settings.AutoDevSettingsState
Expand Down Expand Up @@ -55,8 +55,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
private val buttonPresentation: Presentation
private val button: ActionButton

private val defaultRag: CustomRagApp = CustomRagApp("Normal", "Normal")
private var customRag: ComboBox<CustomRagApp> = ComboBox(MutableCollectionComboBoxModel(listOf()))
private val defaultRag: CustomAgentConfig = CustomAgentConfig("Normal", "Normal")
private var customRag: ComboBox<CustomAgentConfig> = ComboBox(MutableCollectionComboBoxModel(listOf()))

private val logger = logger<AutoDevInputSection>()

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

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


private fun loadRagApps(): List<CustomRagApp> {
private fun loadRagApps(): List<CustomAgentConfig> {
val ragsJsonConfig = project.customRagSettings.ragsJsonConfig
val rags = try {
Json.decodeFromString<List<CustomRagApp>>(ragsJsonConfig)
Json.decodeFromString<List<CustomAgentConfig>>(ragsJsonConfig)
} catch (e: Exception) {
logger.warn("Failed to parse custom rag apps", e)
listOf()
Expand Down
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.devti.gui.chat
import cc.unitmesh.cf.core.llms.LlmMsg
import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.util.LLMCoroutineScope
import cc.unitmesh.devti.counit.CoUnitPreProcessor
import cc.unitmesh.devti.counit.CustomAgentPreProcessor
import cc.unitmesh.devti.counit.configurable.customRagSettings
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.devti.util.parser.PostCodeProcessor
Expand All @@ -16,7 +16,7 @@ import kotlinx.coroutines.launch

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

val action = actionType.instruction(project = project)

Expand Down
Expand Up @@ -59,6 +59,5 @@ abstract class AutoDevRateMessageAction : DumbAwareToggleAction() {
override fun getReactionIcon(): Icon = AutoDevIcons.Dislike

override fun getReactionIconSelected(): Icon = AutoDevIcons.Disliked

}
}
10 changes: 5 additions & 5 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -70,12 +70,12 @@ settings.external.counit.location.label=CoUnit Location (TODO, with JSON RPC) :
settings.external.counit.server.address.label=CoUnit Server address:
devti.loading=Loading

counit.name=Custom RAG
counit.enable.label=Enable Custom RAG (Experimental)
counit.name=Custom Agent
counit.enable.label=Enable Custom Agent (Experimental)
counit.location.label=Custom RAG Location (with JSON RPC, TODO):
counit.server.address.label=Custom RAG Server
counit.custom.rag.label=Custom RAG (Experimental)
counit.rags.json.placeholder=Custom RAG JSON Config
counit.server.address.label=Custom Agent Server
counit.custom.rag.label=Custom Agent (Experimental)
counit.rags.json.placeholder=Custom Agent JSON Config

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

0 comments on commit 0375d22

Please sign in to comment.