Skip to content

Commit

Permalink
feat(provider): enable DevIn agent responses #101
Browse files Browse the repository at this point in the history
This commit enables the execution of DevIn agent responses within the custom agent chat processor by adding a new interface for DevIn response providers and implementing a custom agent response provider for DevIn language. The DevIn custom agent response provider executes the DevIn code and notifies the project of the result.
  • Loading branch information
phodal committed Mar 17, 2024
1 parent e599196 commit 1efc73c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
40 changes: 33 additions & 7 deletions example/custom_agent/server.py
Expand Up @@ -93,13 +93,39 @@ def mock_devins(messages: Messages):
Here are the patches for your
```devin
/write:src/main/java/com/example/Controller.java#L1-L12
\\`\\`\\`java
public class Controller {
public void method() {
System.out.println("Hello, World!");
}
}
/patch
\\`\\`\\`patch
Index: src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java b/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java
--- a/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java (revision b5985862c79fe42043697bc5d5f38b470020be3d)
+++ b/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java (date 1709616724534)
@@ -4,7 +4,19 @@
@RestController
public class BlogCategoryController {
- // devti://story/github/1
+ public void addCategory(String categoryName) {
+ // ... add category logic here
+ }
+
+ public void deleteCategory(long categoryId) {
+ // ... delete category logic here
+ }
- // Close a bank account
+ public void updateCategory(long categoryId, String newCategoryName) {
+ // ... update category logic here
+ }
+
+ public void listCategories() {
+ // ... list all categories logic here
+ }
}
\\`\\`\\`
```"""

Expand Down
@@ -0,0 +1,30 @@
package cc.unitmesh.devti.language.provider

import cc.unitmesh.devti.AutoDevNotifications
import cc.unitmesh.devti.language.DevInLanguage
import cc.unitmesh.devti.language.compiler.DevInsCompiler
import cc.unitmesh.devti.language.psi.DevInFile
import cc.unitmesh.devti.provider.custom.AgentResponseProvider
import cc.unitmesh.devti.provider.custom.CustomAgentContext
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFileFactory
import java.util.*


class DevInsCustomAgentResponse : AgentResponseProvider {
override val name: String = "DevIn"

override fun execute(project: Project, context: CustomAgentContext): String {
val filename = "DevIns-${UUID.randomUUID()}.devin"

val devInFile = PsiFileFactory.getInstance(project)
.createFileFromText(filename, DevInLanguage, context.response) as DevInFile

val devInsCompiler = DevInsCompiler(project, devInFile)
val result = devInsCompiler.compile()

AutoDevNotifications.notify(project, result.output)

return result.output
}
}
Expand Up @@ -44,4 +44,8 @@
class="cc.unitmesh.devti.language.actions.DevInsRunFileAction"
use-shortcut-of="RunClass"/>
</actions>

<extensions defaultExtensionNs="cc.unitmesh">
<customAgentResponse implementation="cc.unitmesh.devti.language.provider.DevInsCustomAgentResponse" />
</extensions>
</idea-plugin>
Expand Up @@ -8,7 +8,10 @@ import cc.unitmesh.devti.gui.chat.ChatCodingPanel
import cc.unitmesh.devti.gui.chat.ChatRole
import cc.unitmesh.devti.llms.LLMProvider
import cc.unitmesh.devti.provider.ContextPrompter
import cc.unitmesh.devti.provider.custom.AgentResponseProvider
import cc.unitmesh.devti.provider.custom.CustomAgentContext
import cc.unitmesh.devti.util.LLMCoroutineScope
import cc.unitmesh.devti.util.parser.Code
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
Expand Down Expand Up @@ -38,6 +41,8 @@ class CustomAgentChatProcessor(val project: Project) {
}

selectedAgent.state = CustomAgentState.FINISHED

var devInCode: String? = ""
when (selectedAgent.responseAction) {
CustomAgentResponseAction.Direct -> {
val message = ui.addMessage("loading", false, "")
Expand All @@ -50,6 +55,12 @@ class CustomAgentChatProcessor(val project: Project) {
val content = sb.toString().removeSurrounding("\"")
llmProvider.appendLocalMessage(content, ChatRole.Assistant)
message.reRenderAssistantOutput()

val code = Code.parse(content)
if (code.language.displayName == "DevIn") {
devInCode = code.text
}

ui.hiddenProgressBar()
ui.updateUI()
}
Expand All @@ -64,6 +75,11 @@ class CustomAgentChatProcessor(val project: Project) {
llmProvider.appendLocalMessage(msg, ChatRole.Assistant)
ui.hiddenProgressBar()
ui.updateUI()

val code = Code.parse(msg)
if (code.language.displayName == "DevIn") {
devInCode = code.text
}
}

CustomAgentResponseAction.TextChunk -> {
Expand Down Expand Up @@ -101,5 +117,11 @@ class CustomAgentChatProcessor(val project: Project) {
ui.hiddenProgressBar()
}
}

if (!devInCode.isNullOrEmpty()) {
AgentResponseProvider.instance("DevIn").forEach {
it.execute(project, CustomAgentContext(selectedAgent, devInCode))
}
}
}
}
Expand Up @@ -10,7 +10,7 @@ data class CustomAgentContext(
val response: String
)

internal interface AgentResponseProvider {
interface AgentResponseProvider {
val name: String

@RequiresBackgroundThread
Expand Down

0 comments on commit 1efc73c

Please sign in to comment.