Skip to content

Commit

Permalink
feat(devin-lang): update notification group id and add LLM support #101
Browse files Browse the repository at this point in the history
The notification group id in the GUI has been updated from "AI notification group" to "AutoDev.notify" for consistency. Additionally, support for LLM (Large Language Models) has been added, including imports, a new LLMProvider class, and integration with the existing compiler and execution logic. This commit also includes changes to the run configuration producer and configuration type to better support the new LLM features.
  • Loading branch information
phodal committed Mar 15, 2024
1 parent cc8b04e commit a2e96b6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
Expand Up @@ -15,10 +15,8 @@ class AutoDevConfigurationType : SimpleConfigurationType(
AutoDevBundle.message("line.marker.run.0", DevInLanguage.INSTANCE.id),
NotNullLazyValue.lazy { DevInIcons.DEFAULT }
) {
override fun createTemplateConfiguration(project: Project): RunConfiguration {
val devConfiguration = AutoDevConfiguration(project, this, "AutoDevConfiguration")
return devConfiguration
}
override fun createTemplateConfiguration(project: Project): RunConfiguration =
AutoDevConfiguration(project, this, "AutoDevConfiguration")

companion object {
fun getInstance(): AutoDevConfigurationType {
Expand Down
Expand Up @@ -21,6 +21,7 @@ class AutoDevRunConfigurationProducer : LazyRunConfigurationProducer<AutoDevConf

configuration.name = virtualFile.presentableName
configuration.setScriptPath(virtualFile.path)

return true
}

Expand All @@ -31,9 +32,8 @@ class AutoDevRunConfigurationProducer : LazyRunConfigurationProducer<AutoDevConf
val psiLocation = context.psiLocation ?: return false
val psiFile = psiLocation.containingFile as? DevInFile ?: return false
val virtualFile = psiFile.virtualFile ?: return false
val scriptPath = configuration.getScriptPath()

return virtualFile.path == scriptPath
return virtualFile.path == configuration.getScriptPath()
}

}
Expand Up @@ -2,6 +2,9 @@ package cc.unitmesh.devti.language.run

import cc.unitmesh.devti.language.compiler.DevInCompiler
import cc.unitmesh.devti.language.psi.DevInFile
import cc.unitmesh.devti.llms.LLMProvider
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.devti.util.LLMCoroutineScope
import com.intellij.build.process.BuildProcessHandler
import com.intellij.execution.DefaultExecutionResult
import com.intellij.execution.ExecutionException
Expand All @@ -15,16 +18,20 @@ import com.intellij.execution.process.ProcessTerminatedListener
import com.intellij.execution.runners.ProgramRunner
import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiManager
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.OutputStream

open class DevInRunConfigurationProfileState(
private val myProject: Project,
private val configuration: AutoDevConfiguration,
) : RunProfileState {
private val llm: LLMProvider = LlmFactory.instance.create(myProject)

override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult {
val processHandler: ProcessHandler = createProcessHandler(configuration.name)
ProcessTerminatedListener.attach(processHandler)
Expand All @@ -47,10 +54,23 @@ open class DevInRunConfigurationProfileState(
val compiler = DevInCompiler(myProject, file)
val output = compiler.compile()

console.print(output, ConsoleViewContentType.NORMAL_OUTPUT)
console.print(output, ConsoleViewContentType.USER_INPUT)
console.print("--------------------\n", ConsoleViewContentType.NORMAL_OUTPUT)

ApplicationManager.getApplication().invokeLater {
LLMCoroutineScope.scope(myProject).launch {
runBlocking {
llm.stream(output, "").collect {
console.print(it, ConsoleViewContentType.NORMAL_OUTPUT)
}
}

console.print("Done!", ConsoleViewContentType.SYSTEM_OUTPUT)
// done!
processHandler.detachProcess()
}
}

// done!
processHandler.detachProcess()

val result = DefaultExecutionResult(console, processHandler)

Expand Down
2 changes: 1 addition & 1 deletion src/222/main/resources/META-INF/autodev-core.xml
Expand Up @@ -57,7 +57,7 @@
<!-- icon="cc.unitmesh.devti.AutoDevIcons.AI_PAIR"-->
<!-- factoryClass="cc.unitmesh.devti.gui.AutoDevPairToolWindowFactory"/>-->

<notificationGroup id="AI notification group" displayType="STICKY_BALLOON" bundle="messages.AutoDevBundle"
<notificationGroup id="AutoDev.notify" displayType="STICKY_BALLOON" bundle="messages.AutoDevBundle"
key="name"/>

<intentionAction>
Expand Down
2 changes: 1 addition & 1 deletion src/233/main/resources/META-INF/autodev-core.xml
Expand Up @@ -58,7 +58,7 @@
<!-- icon="cc.unitmesh.devti.AutoDevIcons.AI_PAIR"-->
<!-- factoryClass="cc.unitmesh.devti.gui.AutoDevPairToolWindowFactory"/>-->

<notificationGroup id="AI notification group" displayType="STICKY_BALLOON" bundle="messages.AutoDevBundle"
<notificationGroup id="AutoDev.notify" displayType="STICKY_BALLOON" bundle="messages.AutoDevBundle"
key="name"/>

<intentionAction>
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/llms/LlmFactory.kt
Expand Up @@ -23,4 +23,8 @@ class LlmFactory {
AIEngines.XingHuo -> project.getService(XingHuoProvider::class.java)
}
}

companion object {
val instance: LlmFactory = LlmFactory()
}
}

0 comments on commit a2e96b6

Please sign in to comment.