Skip to content

Commit

Permalink
feat(custom): add basic custom prompts to intentions
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 8, 2023
1 parent 6791739 commit 9af81d0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 29 deletions.
Expand Up @@ -2,7 +2,7 @@ package cc.unitmesh.idea.promting

import com.intellij.temporary.similar.chunks.SimilarChunksWithPaths
import cc.unitmesh.devti.gui.chat.ChatActionType
import cc.unitmesh.devti.prompting.model.CustomPromptConfig
import cc.unitmesh.devti.custom.CustomPromptConfig
import cc.unitmesh.devti.provider.ContextPrompter
import cc.unitmesh.devti.provider.context.ChatCreationContext
import cc.unitmesh.devti.provider.context.ChatOrigin
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt
@@ -0,0 +1,16 @@
package cc.unitmesh.devti.custom

import cc.unitmesh.devti.intentions.AbstractChatIntention

class CustomIntention(val intentionConfig: CustomIntentionConfig) : AbstractChatIntention() {

override fun getText(): String = intentionConfig.title

override fun getFamilyName(): String = "Custom Intention"

companion object {
fun create(intentionConfig: CustomIntentionConfig): CustomIntention {
return CustomIntention(intentionConfig)
}
}
}
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.devti.custom
import kotlinx.serialization.Serializable

@Serializable
class CustomIntentionPrompt {
class CustomIntentionConfig {
var title: String = ""
var autoInvoke: Boolean = false
var matchRegex: String = ""
Expand Down
@@ -1,6 +1,5 @@
package cc.unitmesh.devti.prompting.model
package cc.unitmesh.devti.custom

import cc.unitmesh.devti.custom.CustomIntentionPrompt
import cc.unitmesh.devti.gui.chat.ChatActionType.*
import cc.unitmesh.devti.settings.AutoDevSettingsState
import com.intellij.openapi.diagnostic.logger
Expand Down Expand Up @@ -29,7 +28,7 @@ data class CustomPromptConfig(
@SerialName("spec")
val spec: Map<String, String> = mapOf(),
@SerialName("prompts")
val prompts: List<CustomIntentionPrompt> = listOf(),
val prompts: List<CustomIntentionConfig> = listOf(),
) {
companion object {
private val logger = logger<CustomPromptConfig>()
Expand Down
@@ -1,4 +1,4 @@
package cc.unitmesh.devti.prompting.model
package cc.unitmesh.devti.custom

import kotlinx.serialization.Serializable

Expand Down
19 changes: 11 additions & 8 deletions src/main/kotlin/cc/unitmesh/devti/intentions/AutoDevIntention.kt
Expand Up @@ -2,7 +2,9 @@ package cc.unitmesh.devti.intentions

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.AutoDevIcons
import cc.unitmesh.devti.custom.CustomIntention
import cc.unitmesh.devti.intentions.ui.CustomPopupStep
import cc.unitmesh.devti.custom.CustomPromptConfig
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInsight.intention.IntentionActionBean
import com.intellij.lang.injection.InjectedLanguageManager
Expand Down Expand Up @@ -43,18 +45,19 @@ class AutoDevIntention : IntentionAction, Iconable {
ExtensionPointName<IntentionActionBean>("cc.unitmesh.autoDevIntention")

fun getAiAssistantIntentions(project: Project, editor: Editor, file: PsiFile): List<IntentionAction> {
val intentions: MutableList<IntentionAction> = ArrayList()
val extensionList = EP_NAME.extensionList

for (bean in extensionList) {
val intentionActionBean = bean as IntentionActionBean
val intention = intentionActionBean.instance
if (intention.isAvailable(project, editor, file)) {
intentions.add(intention)
}
val builtinIntentions = extensionList
.asSequence()
.map { (it as IntentionActionBean).instance }
.filter { it.isAvailable(project, editor, file) }
.toList()

val customIntentions: List<IntentionAction> = CustomPromptConfig.load().prompts.map {
CustomIntention.create(it)
}

return intentions
return builtinIntentions + customIntentions
}
}
}
@@ -1,7 +1,7 @@
package cc.unitmesh.devti.llms.azure

import cc.unitmesh.devti.llms.CodeCopilotProvider
import cc.unitmesh.devti.prompting.model.CustomPromptConfig
import cc.unitmesh.devti.custom.CustomPromptConfig
import cc.unitmesh.devti.settings.AutoDevSettingsState
import com.fasterxml.jackson.databind.ObjectMapper
import com.intellij.openapi.components.Service
Expand All @@ -10,23 +10,18 @@ import com.intellij.openapi.project.Project
import com.theokanning.openai.completion.chat.ChatCompletionResult
import com.theokanning.openai.completion.chat.ChatMessage
import com.theokanning.openai.completion.chat.ChatMessageRole
import com.theokanning.openai.service.ResponseBodyCallback
import com.theokanning.openai.service.SSE
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.FlowableEmitter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import java.io.IOException


@Serializable
Expand Down
@@ -1,8 +1,7 @@
package cc.unitmesh.devti.llms.custom

import cc.unitmesh.devti.llms.CodeCopilotProvider
import cc.unitmesh.devti.llms.azure.SimpleOpenAIBody
import cc.unitmesh.devti.prompting.model.CustomPromptConfig
import cc.unitmesh.devti.custom.CustomPromptConfig
import cc.unitmesh.devti.settings.AutoDevSettingsState
import com.fasterxml.jackson.databind.ObjectMapper
import com.intellij.openapi.components.Service
Expand All @@ -15,7 +14,6 @@ import io.reactivex.Flowable
import io.reactivex.FlowableEmitter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.withContext
Expand All @@ -24,9 +22,6 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.sse.EventSource
import okhttp3.sse.EventSourceListener
import okhttp3.sse.EventSources
import java.time.Duration


Expand Down
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.devti.llms.openai
import cc.unitmesh.devti.context.model.DtClass
import cc.unitmesh.devti.flow.model.SimpleProjectInfo
import cc.unitmesh.devti.prompting.model.FinalCodePrompt
import cc.unitmesh.devti.prompting.model.CustomPromptConfig
import cc.unitmesh.devti.custom.CustomPromptConfig
import com.intellij.openapi.util.NlsSafe
import java.io.InputStream

Expand Down
@@ -1,12 +1,12 @@
package cc.unitmesh.devti.prompting

import cc.unitmesh.devti.parser.parseCodeFromString
import cc.unitmesh.devti.prompting.model.CustomPromptConfig
import cc.unitmesh.devti.custom.CustomPromptConfig
import junit.framework.TestCase.assertNotNull
import org.junit.Test
import java.io.File

class CustomIntentionPromptConfigTest {
class CustomIntentionConfigConfigTest {
@Test
fun should_serial_from_readme_string() {
val readmeFile = File("README.md").readText()
Expand Down

0 comments on commit 9af81d0

Please sign in to comment.