More flexibility for LLMs not being great at this

This commit is contained in:
Matt Rubens
2024-12-19 02:12:20 -05:00
parent ef9c468f17
commit 5d930981a4
4 changed files with 105 additions and 162 deletions

View File

@@ -2,13 +2,13 @@
* Detects potential AI-generated code omissions in the given file content.
* @param originalFileContent The original content of the file.
* @param newFileContent The new content of the file to check.
* @param predictedLineCount Optional predicted number of lines in the new content.
* @param predictedLineCount The predicted number of lines in the new content.
* @returns True if a potential omission is detected, false otherwise.
*/
export function detectCodeOmission(
originalFileContent: string,
newFileContent: string,
predictedLineCount?: number
predictedLineCount: number
): boolean {
// Skip all checks if predictedLineCount is less than 100
if (!predictedLineCount || predictedLineCount < 100) {
@@ -17,11 +17,6 @@ export function detectCodeOmission(
const actualLineCount = newFileContent.split("\n").length
const lengthRatio = actualLineCount / predictedLineCount
// If content is more than 25% shorter than predicted, this is suspicious
if (lengthRatio <= 0.75) {
return true
}
const originalLines = originalFileContent.split("\n")
const newLines = newFileContent.split("\n")
@@ -43,8 +38,8 @@ export function detectCodeOmission(
const words = line.toLowerCase().split(/\s+/)
if (omissionKeywords.some((keyword) => words.includes(keyword))) {
if (!originalLines.includes(line)) {
// For files with 100+ lines, only flag if content is more than 15% shorter
if (lengthRatio <= 0.85) {
// For files with 100+ lines, only flag if content is more than 20% shorter
if (lengthRatio <= 0.80) {
return true
}
}