diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/output/Instruction.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/output/Instruction.kt new file mode 100644 index 00000000..04a258f7 --- /dev/null +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/output/Instruction.kt @@ -0,0 +1,82 @@ +package cc.unitmesh.pick.output + +enum class InstructionType { + INLINE_CODE_COMPLETION, + IN_BLOCK_CODE_COMPLETION, + AFTER_BLOCK_CODE_COMPLETION, + RELATED_CODE_COMPLETION, +// CODE_DIFF, +// REFACTOR, +} + +sealed class Instruction( + val instructionType: InstructionType, + val instruction: String, + val output: String, +) { + abstract fun input(): String +} + +class InlineCodeCompletion( + instruction: String, + output: String, + val language: String, + val beforeCursorCode: String, +) : Instruction(InstructionType.INLINE_CODE_COMPLETION, instruction, output) { + override fun input(): String { + return """```$language + |$beforeCursorCode + |```""".trimMargin() + } +} + +class InBlockCodeCompletion( + instruction: String, + output: String, + val language: String, + val beforeCursorCode: String, + val afterCursorCode: String, +) : Instruction(InstructionType.IN_BLOCK_CODE_COMPLETION, instruction, output) { + override fun input(): String { + return """```$language + |$beforeCursorCode + |$afterCursorCode + |```""".trimMargin() + } +} + +class AfterBlockCodeCompletion( + instruction: String, + output: String, + val language: String, + val beforeCursorCode: String, + val afterCursorCode: String, +) : Instruction(InstructionType.AFTER_BLOCK_CODE_COMPLETION, instruction, output) { + override fun input(): String { + return """```$language + |$beforeCursorCode + |$afterCursorCode + |```""".trimMargin() + } +} + +class RelatedCodeCompletion( + instruction: String, + output: String, + val language: String, + val beforeCursorCode: String, + val relatedCode: String, +) : Instruction(InstructionType.RELATED_CODE_COMPLETION, instruction, output) { + override fun input(): String { + return """ + | Compare this snippet: + |```$language + |$relatedCode + |``` + |Code: + |```$language + |$beforeCursorCode + |```""".trimMargin() + } +} + diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/ToolingPromptType.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/ToolingPromptType.kt deleted file mode 100644 index 7f4587e0..00000000 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/ToolingPromptType.kt +++ /dev/null @@ -1,25 +0,0 @@ -package cc.unitmesh.pick.picker - -enum class ToolingPromptType { - /** - * like GitHub Copilot, use similar chunk of code to complete - */ - INLINE_CODE_COMPLETION, - - /** - * like GitHub Copilot, use similar chunk of code to complete - */ - IN_BLOCK_CODE_COMPLETION, - - /** - * like GitHub Copilot, use similar chunk of code to complete - */ - AFTER_BLOCK_CODE_COMPLETION, - - /** - * like AutoDev, use Static Program Analysis for code based on imports - */ - RELATED_CODE_COMPLETION, - CODE_DIFF, - REFACTOR, -} \ No newline at end of file diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt index ec3e3a71..4f9de515 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt @@ -1,18 +1,16 @@ package cc.unitmesh.pick.worker import cc.unitmesh.pick.picker.PickJob -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import org.archguard.rule.common.Language class WorkerManager { private val workers: Map = mapOf( + // todo: add more language support Language.JAVA to JavaLangWorker(), ) fun addJob(job: PickJob) { val language = job.language.toSupportLanguage() -// print job serial val worker = workers[language] worker?.addJob(job) }