Skip to content

Commit

Permalink
feat(gui): add support for custom rag apps selection #51
Browse files Browse the repository at this point in the history
Enable users to select from a list of custom rag apps to configure the development environment. This feature enhances the flexibility and customization options for developers, allowing them to tailor their workflows to their specific needs. The selection is dynamically loaded from a configurable JSON file, ensuring ease of maintenance and extensibility.
  • Loading branch information
phodal committed Mar 4, 2024
1 parent 3f19fae commit 27d1269
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
@@ -1,5 +1,8 @@
package cc.unitmesh.devti.counit.model

import cc.unitmesh.devti.custom.team.InteractionType
import kotlinx.serialization.Serializable

/**
* Enumeration of possible response actions.
*
Expand All @@ -24,6 +27,7 @@ enum class ResponseAction {
Flow
}

@Serializable
data class CustomFlowTransition(
/**
* will be JsonPath
Expand All @@ -35,11 +39,13 @@ data class CustomFlowTransition(
val target: String,
)

@Serializable
data class CustomRagApp(
val name: String,
val description: String = "",
val url: String = "",
val icon: String = "",
val responseAction: ResponseAction = ResponseAction.Direct,
val customFlowTransition: List<CustomFlowTransition> = emptyList(),
val interactive: InteractionType = InteractionType.ChatPanel,
)
35 changes: 30 additions & 5 deletions src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt
Expand Up @@ -2,13 +2,16 @@ 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.llms.tokenizer.Tokenizer
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
import cc.unitmesh.devti.settings.AutoDevSettingsState
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.Presentation
import com.intellij.openapi.actionSystem.impl.ActionButton
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.ex.EditorEx
Expand All @@ -20,13 +23,19 @@ import com.intellij.openapi.ui.ValidationInfo
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.openapi.wm.impl.InternalDecorator
import com.intellij.temporary.gui.block.AutoDevCoolBorder
import com.intellij.ui.CollectionComboBoxModel
import com.intellij.ui.JBColor
import com.intellij.ui.MutableCollectionComboBoxModel
import com.intellij.ui.SimpleListCellRenderer
import com.intellij.ui.components.JBLabel
import com.intellij.ui.content.ContentManager
import com.intellij.util.EventDispatcher
import com.intellij.util.ui.JBEmptyBorder
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.components.BorderLayoutPanel
import kotlinx.serialization.json.Json
import kotlinx.serialization.decodeFromString
import java.awt.Color
import java.awt.Component
import java.awt.Dimension
Expand All @@ -46,7 +55,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
private val documentListener: DocumentListener
private val buttonPresentation: Presentation
private val button: ActionButton
private val customRag: ComboBox<String>
private val customRag: ComboBox<CustomRagApp>
private val logger = logger<AutoDevInputSection>()

val editorListeners: EventDispatcher<AutoDevInputListener> =
EventDispatcher.create(AutoDevInputListener::class.java)
Expand Down Expand Up @@ -93,7 +103,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
input.border = JBEmptyBorder(4)

addToCenter(input)

val layoutPanel = BorderLayoutPanel()
val horizontalGlue = Box.createHorizontalGlue()
horizontalGlue.addMouseListener(object : MouseAdapter() {
Expand All @@ -107,9 +116,12 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
JBColor(3684930, 3750720)
)
layoutPanel.setOpaque(false)
customRag = ComboBox(arrayOf("Normal")).also {
// todo: load from json config
}
customRag = ComboBox(MutableCollectionComboBoxModel(loadRagApps()))
customRag.setRenderer(SimpleListCellRenderer.create { label: JBLabel, value: CustomRagApp?, _: Int ->
if (value != null) {
label.text = value.name
}
})

layoutPanel.addToLeft(customRag)
layoutPanel.addToCenter(horizontalGlue)
Expand All @@ -131,6 +143,19 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
tokenizer = TokenizerImpl.INSTANCE
}

private fun loadRagApps(): List<CustomRagApp> {
val ragsJsonConfig = project.customRagSettings.ragsJsonConfig
val rags = try {
Json.decodeFromString<List<CustomRagApp>>(ragsJsonConfig)
} catch (e: Exception) {
logger.warn("Failed to parse custom rag apps", e)
listOf()
}

val firstRag = CustomRagApp("Normal", "Normal")
return listOf(firstRag) + rags
}

fun initEditor() {
val editorEx = when (this.input.editor) {
is EditorEx -> this.input.editor
Expand Down

0 comments on commit 27d1269

Please sign in to comment.