-
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.
* PDF support for gemini * Formatting * Updated PDF example
- Loading branch information
Showing
22 changed files
with
151 additions
and
47 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
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
81 changes: 81 additions & 0 deletions
81
...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,81 @@ | ||
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.getItems | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
val saveInvoiceComponents = | ||
object : Tool { | ||
val invoiceComponents = | ||
Parameter.Complex.Array( | ||
name = "components", | ||
description = "A list of the invoice components like number, date, customer_number, etc", | ||
isRequired = true, | ||
itemDefinition = | ||
Parameter.Complex.Object( | ||
name = "component", | ||
description = null, | ||
isRequired = true, | ||
parameters = | ||
listOf( | ||
Parameter.Primitive( | ||
name = "name", | ||
description = "The name of the invoice component e.g. number or date", | ||
isRequired = true, | ||
type = Primitive.String, | ||
), | ||
Parameter.Primitive( | ||
name = "value", | ||
description = "The value of the component", | ||
isRequired = true, | ||
type = Primitive.String, | ||
), | ||
), | ||
), | ||
) | ||
|
||
override val name = ToolName("saveInvoiceComponents") | ||
override val description = "Saves the individual invoice components" | ||
override val parameters = listOf(invoiceComponents) | ||
|
||
override val handler: suspend (JsonObject) -> String = { arguments -> | ||
val components = invoiceComponents.getItems<InvoiceComponent>(arguments) | ||
Json.encodeToString("Saved ${components.size} invoice components successfully") | ||
} | ||
} | ||
|
||
@Serializable | ||
data class InvoiceComponent( | ||
val name: String, | ||
val value: String, | ||
) | ||
|
||
suspend fun invoiceExtractorAgent( | ||
invoicePdfBase64: String, | ||
configureModel: AgentConfig.() -> Unit, | ||
): Run { | ||
val run = | ||
agent { | ||
configureModel() | ||
task("Extract the different invoice components") { | ||
addInstruction("Please provide list of the invoice components") | ||
} | ||
addTool(saveInvoiceComponents) | ||
context { | ||
addBase64(invoicePdfBase64, MimeType.PDF) | ||
} | ||
}.start() | ||
|
||
return run | ||
} |
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.
Binary file not shown.
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
10 changes: 8 additions & 2 deletions
10
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,13 @@ | ||
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
Oops, something went wrong.