Skip to content

Commit

Permalink
fix: remove correnct line in duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 9, 2023
1 parent bf0e1a4 commit 6758260
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Expand Up @@ -3,4 +3,5 @@ package cc.unitmesh.devti.llms.tokenizer
interface Tokenizer {
fun getMaxLength(): Int
fun count(string: String): Int
fun tokenize(chunk: String): List<Int>
}
Expand Up @@ -15,6 +15,9 @@ class TokenizerImpl(private val maxTokenLength: Int = 8192) : Tokenizer {
override fun getMaxLength(): Int = maxTokenLength

override fun count(string: String): Int = encoding.countTokens(string)
override fun tokenize(chunk: String): List<Int> {
return encoding.encode(chunk, maxTokenLength).tokens
}

companion object {
val INSTANCE = ApplicationManager.getApplication().getService(TokenizerImpl::class.java)
Expand Down
Expand Up @@ -102,13 +102,12 @@ class SimilarChunksWithPaths(private var chunkSize: Int = 60, private var maxRel
}

private fun getMostRecentFiles(element: PsiElement): List<VirtualFile> {
val fileType: FileType? = element.containingFile?.fileType
if (element.containingFile == null || fileType == null) {
return emptyList()
}
val fileType: FileType = element.containingFile?.fileType ?: return emptyList()

val recentFiles: List<VirtualFile> = EditorHistoryManager.getInstance(element.project).fileList.filter { file ->
file.isValid && file.fileType == fileType
file.isValid && file.fileType == fileType && file != element.containingFile.virtualFile
}

val start = (recentFiles.size - maxRelevantFiles + 1).coerceAtLeast(0)
val end = (recentFiles.size - 1).coerceAtLeast(0)
return recentFiles.subList(start, end)
Expand Down

0 comments on commit 6758260

Please sign in to comment.