Skip to content

Commit

Permalink
feat: add simliar chunk context
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 14, 2023
1 parent a38182d commit 4b7918a
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,29 @@ package cc.unitmesh.core.intelli

import cc.unitmesh.core.base.LLMCodeContext

class SimilarChunkContext(val language: String, val paths: List<String>, val chunks: List<String>) : LLMCodeContext {
class SimilarChunkContext(val language: String, val paths: List<String>?, val chunks: List<String>?) : LLMCodeContext {
override fun format(): String {
TODO("Not yet implemented")
val commentPrefix = CommentService.getInstance().lineComment(language)

if (paths == null || chunks == null) return ""

val filteredPairs = paths.zip(chunks).filter { it.second.isNotEmpty() }

val queryBuilder = StringBuilder()
for ((path, chunk) in filteredPairs) {
val commentedCode = commentCode(chunk, commentPrefix)
queryBuilder.append("$commentPrefix Compare this snippet from $path:\n")
queryBuilder.append(commentedCode).append("\n")
}

return queryBuilder.toString().trim()
}

private fun commentCode(code: String, commentSymbol: String?): String {
if (commentSymbol == null) return code

return code.split("\n").joinToString("\n") {
"$commentSymbol $it"
}
}
}

0 comments on commit 4b7918a

Please sign in to comment.