generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
64 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/cc/unitmesh/devti/counit/CoUnitPreProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cc.unitmesh.devti.counit | ||
|
||
import cc.unitmesh.devti.LLMCoroutineScope | ||
import cc.unitmesh.devti.gui.chat.ChatCodingPanel | ||
import cc.unitmesh.devti.gui.chat.ChatContext | ||
import cc.unitmesh.devti.llms.LlmProviderFactory | ||
import cc.unitmesh.devti.provider.ContextPrompter | ||
import cc.unitmesh.devti.settings.configurable.coUnitSettings | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.project.Project | ||
import kotlinx.coroutines.launch | ||
|
||
@Service(Service.Level.PROJECT) | ||
class CoUnitPreProcessor(val project: Project) { | ||
private val llmProviderFactory = LlmProviderFactory() | ||
|
||
fun isCoUnit(input: String): Boolean { | ||
return project.coUnitSettings.enableCoUnit && input.startsWith("/counit") | ||
} | ||
|
||
fun handleChat(prompter: ContextPrompter, ui: ChatCodingPanel, context: ChatContext?) { | ||
val originRequest = prompter.requestPrompt() | ||
ui.addMessage(originRequest, true, originRequest) | ||
|
||
// originRequest is starsWith /counit, should remove it | ||
val request = originRequest.removePrefix("/counit").trim() | ||
|
||
val response = CoUnitPromptGenerator(project).findIntention(request) | ||
?: throw Exception("CoUnit response is null, please check your CoUnit server address") | ||
|
||
ui.addMessage(response, true, response) | ||
|
||
ApplicationManager.getApplication().executeOnPooledThread { | ||
val response = llmProviderFactory.connector(project).stream(response, "") | ||
LLMCoroutineScope.scope(project).launch { | ||
ui.updateMessage(response) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters