Skip to content

Commit 46b499e

Browse files
committed
fix(chat-coding-service): handle custom RAG requests #51
Previously, the chat coding service was not correctly identifying and handling custom RAG (Reusable Arbitrary Grammar) requests. This commit modifies the service to properly recognize custom RAG prompts and invoke the appropriate processing logic. The import of `kotlinx.serialization.json.Json` has been retained, and a new method `isCustomRag(input: String)` has been added to the `CoUnitPreProcessor` class to handle these requests. Additionally, the `AutoDevInputSection` and `ChatCodingPanel` have been updated to include a `ComboBox` for selecting custom RAGs and to expose a method `usedCustomRag()` to indicate whether a custom RAG has been selected.
1 parent 54761b8 commit 46b499e

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/CoUnitPreProcessor.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import com.intellij.openapi.components.Service
1212
import com.intellij.openapi.diagnostic.logger
1313
import com.intellij.openapi.project.Project
1414
import kotlinx.coroutines.launch
15-
// keep this import
16-
import kotlinx.serialization.json.Json
1715

1816
const val CO_UNIT = "/counit"
1917

@@ -22,10 +20,10 @@ class CoUnitPreProcessor(val project: Project) {
2220
private val llmFactory = LlmFactory()
2321

2422
private val coUnitPromptGenerator = CoUnitPromptGenerator(project)
25-
private val json = Json { ignoreUnknownKeys = true }
2623
private val llmProvider = llmFactory.create(project)
2724

28-
fun isCoUnit(input: String): Boolean {
25+
fun isCustomRag(input: String): Boolean {
26+
// handle current category
2927
return project.customRagSettings.enableCustomRag && input.startsWith(CO_UNIT)
3028
}
3129

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
4747
private val documentListener: DocumentListener
4848
private val buttonPresentation: Presentation
4949
private val button: ActionButton
50+
private val customRag: ComboBox<String>
51+
5052
val editorListeners: EventDispatcher<AutoDevInputListener> =
5153
EventDispatcher.create(AutoDevInputListener::class.java)
5254
private var tokenizer: Tokenizer? = null
@@ -107,11 +109,11 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
107109
JBColor(3684930, 3750720)
108110
)
109111
layoutPanel.setOpaque(false)
110-
val customRags = ComboBox(arrayOf("Normal")).also {
112+
customRag = ComboBox(arrayOf("Normal")).also {
111113
// todo: load from json config
112114
}
113115

114-
layoutPanel.addToLeft(customRags)
116+
layoutPanel.addToLeft(customRag)
115117
layoutPanel.addToCenter(horizontalGlue)
116118
layoutPanel.addToRight(button)
117119
addToBottom(layoutPanel)
@@ -187,6 +189,10 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
187189
return ValidationInfo(errorMessage, this as JComponent).asWarning()
188190
}
189191

192+
fun usedCustomRag(): Boolean {
193+
return customRag.selectedItem != "Normal"
194+
}
195+
190196
private val maxHeight: Int
191197
get() {
192198
val decorator: InternalDecorator = UIUtil.getParentOfType(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,8 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
244244
myList.removeAll()
245245
updateUI()
246246
}
247+
248+
fun usedCustomRag(): Boolean {
249+
return inputSection.usedCustomRag()
250+
}
247251
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ class ChatCodingService(var actionType: ChatActionType, val project: Project) {
3333
val requestPrompt = prompter.requestPrompt()
3434
val displayPrompt = prompter.displayPrompt()
3535

36-
counitProcessor.isCoUnit(requestPrompt).let {
37-
if (it) {
38-
counitProcessor.handleChat(prompter, ui, context)
39-
return
40-
}
36+
if (counitProcessor.isCustomRag(requestPrompt) && ui.usedCustomRag()) {
37+
counitProcessor.handleChat(prompter, ui, context)
38+
return
4139
}
4240

4341
ui.addMessage(requestPrompt, true, displayPrompt)

0 commit comments

Comments
 (0)