Package io.codemodder.plugins.llm
Class LLMAssistedCodemod
java.lang.Object
io.codemodder.RawFileChanger
io.codemodder.SarifPluginRawFileChanger
io.codemodder.plugins.llm.LLMAssistedCodemod
- All Implemented Interfaces:
io.codemodder.CodeChanger
public abstract class LLMAssistedCodemod
extends io.codemodder.SarifPluginRawFileChanger
An extension of
SarifPluginRawFileChanger that uses large language models (LLMs) to
analyze and fix the files found by the static analysis tool.-
Field Summary
Fields inherited from class io.codemodder.RawFileChanger
reporter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLLMAssistedCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetClassResourceAsString(String relativeName) Returns a class resource as aString.protected abstract StringInstructs the LLM on how to fix the threat.protected abstract StringInstructs the LLM on how to assess the risk of the threat.protected abstract booleanisPatchExpected(com.github.difflib.patch.Patch<String> patch) Returns whether the patch returned by the LLM is within the expectations of this codemod.List<io.codemodder.CodemodChange>onFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) Methods inherited from class io.codemodder.SarifPluginRawFileChanger
visitFileMethods inherited from class io.codemodder.RawFileChanger
getDescription, getIndividualChangeDescription, getReferences, getSourceControlUrl, getSummary
-
Constructor Details
-
LLMAssistedCodemod
-
-
Method Details
-
onFileFound
public List<io.codemodder.CodemodChange> onFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) - Specified by:
onFileFoundin classio.codemodder.SarifPluginRawFileChanger
-
getThreatPrompt
Instructs the LLM on how to assess the risk of the threat.- Returns:
- The prompt.
-
getFixPrompt
Instructs the LLM on how to fix the threat.- Returns:
- The prompt.
-
isPatchExpected
Returns whether the patch returned by the LLM is within the expectations of this codemod.- Returns:
trueif the patch is expected; otherwise,false.
-
getClassResourceAsString
Returns a class resource as aString.The absolute name of the class resource is of the following form:
Where the/modifiedPackageName/className/relativeNamemodifiedPackageNameis the package name of this object with'/'substituted for'.'.- Parameters:
relativeName- The relative name of the resource.- Returns:
- The resource as a
String. - Throws:
MissingResourceException- If the resource was not found.
-