Class AIGenerationTask
- All Implemented Interfaces:
Cloneable
Since ChatGPT is not particularily fast not free and the generation results have to be manually checked, this is heavily cached. Into each output file we write the versions of all the input files from which it was generated into a comment. When the tasks are run, we compare the versions of all the input files with the versions recorded in the comment, and only regenerate the output file if the versions have changed. An input file can have a version comment that explicitly states the version, or we take the an abbreviated SHA256 hash of the input file as version. It is possible to explicitly state the versions in version comments in the input files to avoid regenerating all files if minor details e.g. in a prompt file are changed - only when the prompt file version comment is changed everything is regenerated.
A version comment can e.g. look like this:
// AIGenVersion(ourversion, inputfile1@version1, inputfile2@version2, ...)
where ourversion and version1 and version2 are hashes. ourversion is the hash of the original output of the AI. The comment syntax (in this case //) is ignored - we just look for the AIGenVersion via regex.
Normally the intermediate and final results should be checked in with Git. That ensures manual checks when they are regenerated, and minimizes regeneration.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringA marker that can be inserted by the AI when something is wrong / unclear.protected booleanprotected static final Loggerprotected Integerprotected Fileprotected static final PatternA pattern that matches the license header, which we want to remove to avoid clutter.protected StringThe actual prompt created from prompt files and parameters.protected Stringprotected File -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddInputFile(File file) addInputFiles(List<File> files) addOptionalInputFile(File file) The actual prompt to be executed.The actual prompt to be executed.protected Objectclone()Deprecated.copy()Creates a deep copy of the task.protected Stringprotected StringembedComment(String content, String comment) execute(Supplier<AIChatBuilder> chatBuilderFactory, File rootDirectory) Execute the task if necessary.explain(Supplier<AIChatBuilder> chatBuilderFactory, File rootDirectory, String question) Ask a question about the previous task execution.voidforce(boolean force) If true the generation will be run even if nothasToBeRun().protected StringgetFileContent(File file) protected AIVersionMarkerVersion of current output file.booleanprotected AIChatBuildermakeChatBuilder(Supplier<AIChatBuilder> chatBuilderFactory, File rootDirectory, String outputRelPath) protected StringrelativePath(File file, File rootDirectory) setOutputFile(File file) setSystemMessage(File systemMessageFile) protected StringtoJson(Supplier<AIChatBuilder> chatBuilderFactory, File rootDirectory) For debugging purposes: returns the JSON that would be sent to the AI.toString()protected static String
-
Field Details
-
LOG
-
FIXME
A marker that can be inserted by the AI when something is wrong / unclear. We will make sure the user sees that by aborting.- See Also:
-
PATTERN_LICENCE
A pattern that matches the license header, which we want to remove to avoid clutter. -
inputFiles
-
outputFile
-
prompt
The actual prompt created from prompt files and parameters. -
promptFiles
-
placeholdersAndValues
-
systemMessage
-
systemMessageFile
-
force
protected boolean force -
maxTokens
-
-
Constructor Details
-
AIGenerationTask
public AIGenerationTask()
-
-
Method Details
-
copy
Creates a deep copy of the task. -
clone
Deprecated.usecopy()We override this to allow cloning for use with thecopy()method, but deliberately leave it protected since the use ofcopy()is intended.- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
maxTokens
-
addOptionalInputFile
-
addInputFiles
-
addInputFile
-
setOutputFile
-
embedComment
-
hasToBeRun
public boolean hasToBeRun() -
calculateAllInputsMarkers
-
determineFileVersionMarker
-
shaHash
-
getRecordedOutputVersionMarker
Version of current output file. -
addPrompt
The actual prompt to be executed. The prompt file content can contain placeholders that are replaced by the values given: placeholdersAndValues contain alternatingly placeholder names and values for them.- Returns:
- this
-
addPrompt
public AIGenerationTask addPrompt(@Nonnull File promptFile, Map<String, String> placeholdersAndValues) The actual prompt to be executed. The prompt file content can contain placeholders that are replaced by the values given.- Returns:
- this
-
getFileContent
-
unclutter
-
setSystemMessage
-
relativePath
-
execute
public AIGenerationTask execute(@Nonnull Supplier<AIChatBuilder> chatBuilderFactory, @Nonnull File rootDirectory) Execute the task if necessary. If the output file is already there and up to date, nothing is done. -
toJson
public String toJson(@Nonnull Supplier<AIChatBuilder> chatBuilderFactory, @Nonnull File rootDirectory) For debugging purposes: returns the JSON that would be sent to the AI. -
makeChatBuilder
@Nonnull protected AIChatBuilder makeChatBuilder(@Nonnull Supplier<AIChatBuilder> chatBuilderFactory, @Nonnull File rootDirectory, String outputRelPath) -
explain
public String explain(@Nonnull Supplier<AIChatBuilder> chatBuilderFactory, @Nonnull File rootDirectory, @Nonnull String question) Ask a question about the previous task execution. We assume it was previously run (hasToBeRun()== false), add the result of the previous execution to the chat, and ask the AI the given question about it. This can be used e.g. to see why the AI did something, or in the process of improving the prompt, etc.- Returns:
- the answer of the AI - not written to a file!
-
toString
-
force
public void force(boolean force) If true the generation will be run even if nothasToBeRun().
-
copy()