Package io.codemodder.plugins.llm
Class SarifToLLMForBinaryVerificationAndFixingCodemod
java.lang.Object
io.codemodder.RawFileChanger
io.codemodder.SarifPluginRawFileChanger
io.codemodder.plugins.llm.SarifPluginLLMCodemod
io.codemodder.plugins.llm.SarifToLLMForBinaryVerificationAndFixingCodemod
- All Implemented Interfaces:
io.codemodder.CodeChanger
An extension of
SarifPluginRawFileChanger that uses large language models (LLMs) to more
deeply analyze and then fix the files found by the static analysis tool.
It has three phases:
- Use a SARIF file to find locations of interest for analysis
- Analyze the "threat" of the location found using a more inexpensive or faster model
- Using a more reliable (and more expensive model), confirm the finding and rewrite the code
-
Field Summary
Fields inherited from class io.codemodder.plugins.llm.SarifPluginLLMCodemod
openAIFields inherited from class io.codemodder.RawFileChanger
reporter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSarifToLLMForBinaryVerificationAndFixingCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI) For backwards compatibility with a previous version of this API, uses a GPT 3.5 Turbo model.protectedSarifToLLMForBinaryVerificationAndFixingCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI, Model model) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringInstructs the LLM on how to fix the threat.protected abstract StringgetThreatPrompt(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) Instructs 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.io.codemodder.CodemodFileScanningResultonFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) Methods inherited from class io.codemodder.plugins.llm.SarifPluginLLMCodemod
shouldRunMethods inherited from class io.codemodder.SarifPluginRawFileChanger
visitFileMethods inherited from class io.codemodder.RawFileChanger
getDescription, getIndividualChangeDescription, getReferences, getSummary
-
Constructor Details
-
SarifToLLMForBinaryVerificationAndFixingCodemod
protected SarifToLLMForBinaryVerificationAndFixingCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI, Model model) -
SarifToLLMForBinaryVerificationAndFixingCodemod
protected SarifToLLMForBinaryVerificationAndFixingCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI) For backwards compatibility with a previous version of this API, uses a GPT 3.5 Turbo model.
-
-
Method Details
-
onFileFound
public io.codemodder.CodemodFileScanningResult onFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) - Specified by:
onFileFoundin classio.codemodder.SarifPluginRawFileChanger
-
getThreatPrompt
protected abstract String getThreatPrompt(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results) 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.
-