Skip to content

Commit 5f9bf7f

Browse files
committed
feat(devins-lang): add support for LLM responses in DevInsConversations #100
This commit introduces the ability to retrieve and process responses from a language model (LLM) within the DevInsConversations class. It adds a new method `getLlmResponse` to retrieve the LLM response for a given script path, and updates the `runTask` method to parse the LLM response and execute the corresponding DevInCode if it matches the DevInLanguage. This feature enhances the conversational capabilities of the DevIns language by integrating with advanced language models.
1 parent a80f342 commit 5f9bf7f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/psi/DevInFile.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class DevInFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, DevI
2121
override fun getStub(): DevInFileStub? = super.getStub() as DevInFileStub?
2222

2323
companion object {
24+
/**
25+
* Create a temp DevInFile from a string.
26+
*/
2427
fun fromString(project: Project, text: String): DevInFile {
2528
val filename = "DevIns-${UUID.randomUUID()}.devin"
2629
val devInFile = PsiFileFactory.getInstance(project)

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/flow/DevInsConversations.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,8 @@ class DevInsConversationService(val project: Project) {
107107
}, null, true)
108108
}
109109
}
110+
111+
fun getLlmResponse(scriptPath: String): String {
112+
return cachedConversations[scriptPath]?.llmResponse ?: ""
113+
}
110114
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/flow/DevInsProcessProcessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package cc.unitmesh.devti.language.run.flow
22

33
import cc.unitmesh.devti.gui.chat.ChatActionType
44
import cc.unitmesh.devti.gui.sendToChatWindow
5+
import cc.unitmesh.devti.language.DevInLanguage
56
import cc.unitmesh.devti.language.compiler.DevInsCompiler
67
import cc.unitmesh.devti.language.psi.DevInFile
78
import cc.unitmesh.devti.language.psi.DevInVisitor
89
import cc.unitmesh.devti.provider.ContextPrompter
10+
import cc.unitmesh.devti.util.parser.Code
911
import com.intellij.execution.process.ProcessEvent
1012
import com.intellij.openapi.application.runReadAction
1113
import com.intellij.openapi.components.Service
@@ -52,6 +54,14 @@ class DevInsProcessProcessor(val project: Project) {
5254
val devInFile: DevInFile? = runReadAction { DevInFile.lookup(project, scriptPath) }
5355
project.service<DevInsConversationService>().updateIdeOutput(scriptPath, output)
5456

57+
val llmResponse = project.service<DevInsConversationService>().getLlmResponse(scriptPath)
58+
val code = Code.parse(llmResponse)
59+
if (code.language == DevInLanguage.INSTANCE) {
60+
val devInCode = code.text
61+
val file = DevInFile.fromString(project, devInCode)
62+
runTask(file)
63+
}
64+
5565
when {
5666
event.exitCode == 0 -> {
5767
val comment = lookupFlagComment(devInFile!!).firstOrNull() ?: return
@@ -70,7 +80,7 @@ class DevInsProcessProcessor(val project: Project) {
7080
}
7181
}
7282

73-
private fun runTask(newScript: DevInFile) {
83+
fun runTask(newScript: DevInFile) {
7484
val compiledResult = DevInsCompiler(project, newScript).compile()
7585
val prompt = compiledResult.output
7686

0 commit comments

Comments
 (0)