-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...mples/simple-tools/src/commonMain/kotlin/community/flock/aigentic/example/PdfExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package community.flock.aigentic.example | ||
|
||
import community.flock.aigentic.core.agent.Run | ||
import community.flock.aigentic.core.agent.start | ||
import community.flock.aigentic.core.dsl.AgentConfig | ||
import community.flock.aigentic.core.dsl.agent | ||
import community.flock.aigentic.core.message.MimeType | ||
import community.flock.aigentic.core.tool.Parameter | ||
import community.flock.aigentic.core.tool.ParameterType.Primitive | ||
import community.flock.aigentic.core.tool.Tool | ||
import community.flock.aigentic.core.tool.ToolName | ||
import community.flock.aigentic.core.tool.getStringValue | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
val savePdfSummary = | ||
object : Tool { | ||
val title = | ||
Parameter.Primitive( | ||
name = "title", | ||
description = null, | ||
isRequired = true, | ||
type = Primitive.String, | ||
) | ||
|
||
val mainPointsParameter = | ||
Parameter.Complex.Array( | ||
name = "mainPoints", | ||
description = "List of main points mentioned in the article", | ||
isRequired = true, | ||
itemDefinition = | ||
Parameter.Primitive( | ||
name = "mainPoint", | ||
description = null, | ||
isRequired = true, | ||
type = Primitive.String, | ||
), | ||
) | ||
|
||
override val name = ToolName("savePdfSummary") | ||
override val description = "Saves the summary of the PDF" | ||
override val parameters = listOf(title, mainPointsParameter) | ||
|
||
override val handler: suspend (JsonObject) -> String = { arguments -> | ||
|
||
val message = title.getStringValue(arguments) | ||
"Successfully saved: '$message' " | ||
} | ||
} | ||
|
||
suspend fun pdfSummaryAgent( | ||
pdfBase64: String, | ||
configureModel: AgentConfig.() -> Unit, | ||
): Run { | ||
val run = | ||
agent { | ||
configureModel() | ||
task("Summarize the content of a PDF") { | ||
addInstruction("Give the summary a comprehensive title") | ||
addInstruction("Please provide list of main points") | ||
} | ||
addTool(savePdfSummary) | ||
context { | ||
addBase64(pdfBase64, MimeType.PDF) | ||
} | ||
}.start() | ||
|
||
return run | ||
} |
Binary file not shown.
1 change: 0 additions & 1 deletion
1
src/examples/simple-tools/src/commonMain/resources/base64image.txt
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
src/examples/simple-tools/src/jvmMain/kotlin/community/flock/aigentic/example/Util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package community.flock.aigentic.example | ||
|
||
import java.util.Base64 | ||
|
||
object FileReader { | ||
fun readFile(path: String): String { | ||
return this::class.java.getResource(path)!!.readText(Charsets.UTF_8).trim() | ||
|
||
fun readFileBase64(path: String): String { | ||
val inputStream = | ||
this::class.java.getResource(path)?.openStream() | ||
?: throw IllegalArgumentException("Resource not found: $path") | ||
val bytes = inputStream.use { it.readBytes() } | ||
return Base64.getEncoder().encodeToString(bytes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.