This library analyzes the output of AI and calls corresponding operations in a simple and straightforward manner. Designed for ease of use, AIResponseMatcher simplifies the interpretation of AI responses, enabling efficient integration with specific operations.
Warning
This project is currently experimental and mostly just a proof-of-concept at this point. There are no tests and some things might be broken or very non-performant. The API may also change between releases without deprecation cycles.
Consult the documentation
implementation 'com.github.Ruan625Br:AIResponseMatcher:1.0.0-beta'
implementation "com.github.Ruan625Br:AIResponseMatcher:1.0.0-beta"
ai-reponse-matcher = "1.0.0-beta"
ai-reponse-matcher = { group = "com.github.Ruan625Br", name = "AIResponseMatcher", version.ref = "ai-reponse-matcher" }
<dependency>
<groupId>com.github.Ruan625Br</groupId>
<artifactId>AIResponseMatcher</artifactId>
<version>1.0.0-beta</version>
</dependency>
Define the arguments that your operations will use by creating an enum class. In this example, MyArgs
represents the possible arguments for operations, such as the file path and file name.
enum class MyArgs(val arg: String) : OperationArg {
PATH("path"),
FILE_NAME("fileName");
override val value: String
get() = arg
}
Create operations that will be performed based on the AI output. In this instance, the FileOperations
object contains a RenameFile
operation, which demonstrates how to handle renaming a file.
object FileOperations {
data class RenameFile : Operation {
override fun resolve(output: String, args: Map<String, String>?): String {
val path = args?.get(MyArgs.PATH)
val fileName = args?.get(MyArgs.FILE_NAME)
val newValue = "Starting process to rename the file to: $fileName\nPath: $path"
return output.replaceOperationWithNewValue(this, newValue)
}
override val name: String
get() = "renameFile"
}
}
Combine your AI output with the defined operations to create an Output
instance. Here, the operations
list includes the RenameFile
and CreateFile
operations.
val operations = listOf(FileOperations.RenameFile, FileOperations.CreateFile)
val output = Output(outputAI, operations)
Execute the operations on the AI output to process lines accordingly. In this step, the processLines()
method is invoked on the output
instance.
val result = output.processLines()